Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-29942

User web service functions do not trigger user events.

    Details

    • Type: Task
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.1.2, 2.2, 2.3
    • Fix Version/s: 2.1.4, 2.2.1
    • Component/s: Web Services
    • Labels:
      None
    • Testing Instructions:
      Hide

      Create a local plugin with /local/YOURLOCALPLUGIN/db/events.php :

      $handlers = array (
          'user_created' => array (
               'handlerfile'      => '/local/YOURLOCALPLUGIN/lib.php',
               'handlerfunction'  => 'YOURLOCALPLUGIN_user_created',
               'schedule'         => 'instant'
           ),
          
          'user_updated' => array (
               'handlerfile'      => '/local/YOURLOCALPLUGIN/lib.php',
               'handlerfunction'  => 'YOURLOCALPLUGIN_user_updated',
               'schedule'         => 'instant'
           ),
          
      );

      in /local/YOURLOCALPLUGIN/lib.php:

      function YOURLOCALPLUGIN_user_created ($user) {
          error_log(print_r('An user has been created - wstemplate Tester plugin event handler', true));   
          error_log(print_r($user, true));
      }
       
      function YOURLOCALPLUGIN_user_updated ($user) {
          error_log(print_r('An user has been updated - wstemplate Tester plugin event handler', true));   
          error_log(print_r($user, true));
      }

      Then call the web service 'create users' and 'update users' functions with a ws client (https://github.com/moodlehq/sample-ws-clients)

      You should see the error logs meaning that the events have been correctly triggered.

      Show
      Create a local plugin with /local/YOURLOCALPLUGIN/db/events.php : $handlers = array ( 'user_created' => array ( 'handlerfile' => '/local/YOURLOCALPLUGIN/lib.php', 'handlerfunction' => 'YOURLOCALPLUGIN_user_created', 'schedule' => 'instant' ), 'user_updated' => array ( 'handlerfile' => '/local/YOURLOCALPLUGIN/lib.php', 'handlerfunction' => 'YOURLOCALPLUGIN_user_updated', 'schedule' => 'instant' ), ); in /local/YOURLOCALPLUGIN/lib.php: function YOURLOCALPLUGIN_user_created ($user) { error_log(print_r('An user has been created - wstemplate Tester plugin event handler', true)); error_log(print_r($user, true)); }   function YOURLOCALPLUGIN_user_updated ($user) { error_log(print_r('An user has been updated - wstemplate Tester plugin event handler', true)); error_log(print_r($user, true)); } Then call the web service 'create users' and 'update users' functions with a ws client ( https://github.com/moodlehq/sample-ws-clients ) You should see the error logs meaning that the events have been correctly triggered.
    • Affected Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE, MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE
    • Pull Master Branch:

      Description

      browse the entire web service functions and check that they implement the trigger indicated in the documentation: http://docs.moodle.org/dev/Events_API#Events_which_exist

        Gliffy Diagrams

          Activity

          Hide
          jerome Jérôme Mouneyrac added a comment - - edited
          Missing trigger calls
          • create_users : events_trigger('user_created', $user); => /user/lib.php/user_create_user()
          • update_users : events_trigger('user_updated', $usernew); => /user/lib.php/user_update_user()
          Show
          jerome Jérôme Mouneyrac added a comment - - edited Missing trigger calls create_users : events_trigger('user_created', $user); => /user/lib.php/user_create_user() update_users : events_trigger('user_updated', $usernew); => /user/lib.php/user_update_user()
          Hide
          rwijaya Rossiani Wijaya added a comment -

          Hi Jerome,

          The patch looks good.

          However I noticed difference output between the create and update function. When user is successfully created, there is an output of user id and username on the page. On the other hand, when user info is successfully updated, there is no output on the page.

          It doesn't look like a major issue, but just wanted to get your opinion on this.

          Thanks

          Show
          rwijaya Rossiani Wijaya added a comment - Hi Jerome, The patch looks good. However I noticed difference output between the create and update function. When user is successfully created, there is an output of user id and username on the page. On the other hand, when user info is successfully updated, there is no output on the page. It doesn't look like a major issue, but just wanted to get your opinion on this. Thanks
          Hide
          jerome Jérôme Mouneyrac added a comment -

          It's just what the web service returns, don't worry all good

          Show
          jerome Jérôme Mouneyrac added a comment - It's just what the web service returns, don't worry all good
          Hide
          stronk7 Eloy Lafuente (stronk7) added a comment -

          The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week.

          TIA and ciao

          Show
          stronk7 Eloy Lafuente (stronk7) added a comment - The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week. TIA and ciao
          Hide
          samhemelryk Sam Hemelryk added a comment -

          Thanks Jerome - this has been integrated now

          Show
          samhemelryk Sam Hemelryk added a comment - Thanks Jerome - this has been integrated now
          Hide
          gerry Gerard Caulfield added a comment -

          Actually on a second look I'm probably not the best person to test this.

          Show
          gerry Gerard Caulfield added a comment - Actually on a second look I'm probably not the best person to test this.
          Hide
          gerry Gerard Caulfield added a comment -

          Removing my name from the tester field to avoid confusion.

          Show
          gerry Gerard Caulfield added a comment - Removing my name from the tester field to avoid confusion.
          Hide
          rajeshtaneja Rajesh Taneja added a comment -

          Works Great
          Thanks for fixing this Jerome.

          Show
          rajeshtaneja Rajesh Taneja added a comment - Works Great Thanks for fixing this Jerome.
          Hide
          stronk7 Eloy Lafuente (stronk7) added a comment -

          Whoever decided one week was worth 14 days had really one bad idea. Anyway, the nightmare is over, so thanks for your, once again, amazing contributions. Many, many thanks!

          Now... disconnect, relax and enjoy the next days, yay!

          Closing...ciao

          Show
          stronk7 Eloy Lafuente (stronk7) added a comment - Whoever decided one week was worth 14 days had really one bad idea. Anyway, the nightmare is over, so thanks for your, once again, amazing contributions. Many, many thanks! Now... disconnect, relax and enjoy the next days, yay! Closing...ciao

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Jan/12