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

No response receieved from web service function core_group_get_groups, 500 internal server error received, call to undefined function in error log

    Details

    • Testing Instructions:
      Hide

      Copy the attached test.php file into your Moodle site.
      Run it without the fix, you see:

      Fatal error: Call to undefined function file_rewrite_pluginfile_urls() in /Users/jerome/Sites/master/lib/externallib.php on line 697

      Run it with the fix, you see no errors.

      Show
      Copy the attached test.php file into your Moodle site. Run it without the fix, you see: Fatal error: Call to undefined function file_rewrite_pluginfile_urls() in /Users/jerome/Sites/master/lib/externallib.php on line 697 Run it with the fix, you see no errors.
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull Master Branch:
      MDL-37552-master

      Description

      Having setup and configured a web service for groups, calling the web service function core_group_get_groups returned no response or exception but we got a response code and status of 500: Internal Server Error.

      Switched the debugging onto developer in Moodle and received the below line in the error log.
      Call to undefined function file_rewrite_pluginfile_urls() in <moodle_dir>/lib/externallib.php on line 690

      Looked in the externallib.php file and found this section of code where the error occurs:

      function external_format_text($text, $textformat, $contextid, $component, $filearea, $itemid) {
          global $CFG;
          
          // Get settings (singleton).
          $settings = external_settings::get_instance();
       
          if ($settings->get_fileurl()) {
              $text = file_rewrite_pluginfile_urls($text, $settings->get_file(), $contextid, $component, $filearea, $itemid);
          }
       
          if (!$settings->get_raw()) {
              $textformat = FORMAT_HTML; // Force format to HTML when not raw.
              $text = format_text($text, $textformat,
                      array('noclean' => true, 'para' => false, 'filter' => $settings->get_filter()));
          }
       
          return array($text, $textformat);
      }

      adding the line:

      require_once("$CFG->libdir/filelib.php");

      and modifying the function call to:

      $text = file_rewrite_pluginfile_urls($text, $settings->get_file(), $contextid, $component, $filearea, $itemid, null);

      shown modified below:

      function external_format_text($text, $textformat, $contextid, $component, $filearea, $itemid) {
          global $CFG;
          require_once("$CFG->libdir/filelib.php");
          // Get settings (singleton).
          $settings = external_settings::get_instance();
       
          if ($settings->get_fileurl()) {
              $text = file_rewrite_pluginfile_urls($text, $settings->get_file(), $contextid, $component, $filearea, $itemid, null);
          }
       
          if (!$settings->get_raw()) {
              $textformat = FORMAT_HTML; // Force format to HTML when not raw.
              $text = format_text($text, $textformat,
                      array('noclean' => true, 'para' => false, 'filter' => $settings->get_filter()));
          }
       
          return array($text, $textformat);
      }

      seems to fix this issue, and a test of calling the core_group_get_groups web service method resulted in a response with the correct data for the group being read and a 200 response code.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              jerome Jérôme Mouneyrac added a comment -

              Thanks for the report and fix suggestion Adam. If you some have time you can make a git commit from your changes and indicate where to get it (github is easy place) so you get credited in history Moodle history. Otherwise no worries, we'll look at that. Cheers, Jerome.

              Show
              jerome Jérôme Mouneyrac added a comment - Thanks for the report and fix suggestion Adam. If you some have time you can make a git commit from your changes and indicate where to get it (github is easy place) so you get credited in history Moodle history. Otherwise no worries, we'll look at that. Cheers, Jerome.
              Hide
              jerome Jérôme Mouneyrac added a comment -

              It makes total sens to me that external_format_text require_once the lib file that it uses. It usually works because filelib.php is usually require_once before external_format_text is called.

              Show
              jerome Jérôme Mouneyrac added a comment - It makes total sens to me that external_format_text require_once the lib file that it uses. It usually works because filelib.php is usually require_once before external_format_text is called.
              Hide
              ankit_frenz Ankit Agarwal added a comment -

              Hi Jerome,
              Patch is good , feel free to send for integration. Would be nice if you can give credits to Adam in commit msgs.

              feel free to send for integration.
              Thanks

              Show
              ankit_frenz Ankit Agarwal added a comment - Hi Jerome, Patch is good , feel free to send for integration. Would be nice if you can give credits to Adam in commit msgs. feel free to send for integration. Thanks
              Hide
              jerome Jérôme Mouneyrac added a comment -

              Thanks Ankit, submitting to integration.

              Show
              jerome Jérôme Mouneyrac added a comment - Thanks Ankit, submitting to integration.
              Hide
              jerome Jérôme Mouneyrac added a comment -

              retaking I forgot to backport it

              Show
              jerome Jérôme Mouneyrac added a comment - retaking I forgot to backport it
              Hide
              jerome Jérôme Mouneyrac added a comment -

              resubmitting

              Show
              jerome Jérôme Mouneyrac added a comment - resubmitting
              Hide
              poltawski Dan Poltawski added a comment -

              Hi Jerome,

              Since the phpunit tests do not detect this problem, I do not think that they are sufficient to test that this issue has been fixed.

              Please add some testing instructions which verify the reported problem is fixed.

              Show
              poltawski Dan Poltawski added a comment - Hi Jerome, Since the phpunit tests do not detect this problem, I do not think that they are sufficient to test that this issue has been fixed. Please add some testing instructions which verify the reported problem is fixed.
              Hide
              jerome Jérôme Mouneyrac added a comment -

              Thanks Dan for having a look, I created a php test file.

              Show
              jerome Jérôme Mouneyrac added a comment - Thanks Dan for having a look, I created a php test file.
              Hide
              damyon Damyon Wiese added a comment -

              This is blocking another webservice issue (which can be used to test it).

              Show
              damyon Damyon Wiese added a comment - This is blocking another webservice issue (which can be used to test it).
              Hide
              damyon Damyon Wiese added a comment -

              Tested this on master by pulling both this and the blocking issue and then testing with a web service client.

              Show
              damyon Damyon Wiese added a comment - Tested this on master by pulling both this and the blocking issue and then testing with a web service client.
              Hide
              damyon Damyon Wiese added a comment -

              Thanks Adam and Jerome,

              This has been integrated to 23, 24 and master. I tested it on all branches with the test script and on master with the linked issue.

              Show
              damyon Damyon Wiese added a comment - Thanks Adam and Jerome, This has been integrated to 23, 24 and master. I tested it on all branches with the test script and on master with the linked issue.
              Hide
              damyon Damyon Wiese added a comment -

              All tests passed. Thanks!

              Show
              damyon Damyon Wiese added a comment - All tests passed. Thanks!
              Hide
              stronk7 Eloy Lafuente (stronk7) added a comment -

              Did you think this day was not going to arrive ever?

              Your patience has been rewarded, yay, sent upstream, thanks!

              Closing...ciao

              Show
              stronk7 Eloy Lafuente (stronk7) added a comment - Did you think this day was not going to arrive ever? Your patience has been rewarded, yay, sent upstream, thanks! Closing...ciao

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    13/May/13