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

    • Rank:
      47202

      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.

      1. test.php
        0.2 kB
        Jérôme Mouneyrac

        Issue Links

          Activity

          Hide
          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
          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
          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
          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 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 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
          Jérôme Mouneyrac added a comment -

          Thanks Ankit, submitting to integration.

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

          retaking I forgot to backport it

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

          resubmitting

          Show
          Jérôme Mouneyrac added a comment - resubmitting
          Hide
          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
          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
          Jérôme Mouneyrac added a comment -

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

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

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

          Show
          Damyon Wiese added a comment - This is blocking another webservice issue (which can be used to test it).
          Hide
          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 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 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 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 Wiese added a comment -

          All tests passed. Thanks!

          Show
          Damyon Wiese added a comment - All tests passed. Thanks!
          Hide
          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
          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: