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

core_reportbuilder_retrieve_report WS fails when the Course Enrolment status column is used

XMLWordPrintable

    • MOODLE_401_STABLE
    • MOODLE_401_STABLE
    • MDL-77400-401
    • MDL-77400-master
    • Hide
      1. Login as admin.
      2. Go to "Site administration > Users > Add a new user" and create a new user.
      3. Go to "Site administration > Courses > Add a new course" and create a course.
      4. Enrol the user in the course as a student.
      5. Go to Site administration > Reports > Report builder > Custom reports.
      6. Click "New report".
      7. Set a Name and, in Report source, select "Course participants". Save changes.
      8. Copy the id you see in the URL of the page, you will need it later. E.g. the URL should be something like "YOURSITE/reportbuilder/edit.php?id=5".
      9. In the list at the left, click the option "Enrolment > Status". Check that the Status column has been added to the report.
      10. Go to the Audience tab and click "All users" at the left. Click Save changes.
      11. Create a Token for the student user:
            Click on Site administration ► Plugins ► Web services ► Manage tokens
      12. Do a CURL request simulating a WS client, replacing wstoken with the student token, the reportid with the one you copied in step 8, and the site url with yours.

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_reportbuilder_retrieve_report&reportid=5&page=0&perpage=20&wstoken=4fa679cba032a870004502b39c104583' --compressed | python -m "json.tool"

      13. Confirm you receive the report information, not an exception. E.g. you should be able to see the name of the report, the time it was created, etc.
      Show
      Login as admin. Go to "Site administration > Users > Add a new user" and create a new user. Go to "Site administration > Courses > Add a new course" and create a course. Enrol the user in the course as a student. Go to Site administration > Reports > Report builder > Custom reports. Click "New report". Set a Name and, in Report source, select "Course participants". Save changes. Copy the id you see in the URL of the page, you will need it later. E.g. the URL should be something like "YOURSITE/reportbuilder/edit.php?id=5". In the list at the left, click the option "Enrolment > Status". Check that the Status column has been added to the report. Go to the Audience tab and click "All users" at the left. Click Save changes. Create a Token for the student user:     Click on Site administration ► Plugins ► Web services ► Manage tokens Do a CURL request simulating a WS client, replacing wstoken with the student token, the reportid with the one you copied in step 8, and the site url with yours. curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_reportbuilder_retrieve_report&reportid=5&page=0&perpage=20&wstoken=4fa679cba032a870004502b39c104583' --compressed | python -m "json.tool" Confirm you receive the report information, not an exception. E.g. you should be able to see the name of the report, the time it was created, etc.

      We've debugged the issue and the problem is that the enrolment_status() method in /course/classes/reportbuilder/local/formatters/enrolment.php is returning a lang_string object instead of an scalar string

      This is not compatible with the current exporter implementation in LMS (that does not treat the case) so the external function tries to return an object instead of the expected PARAM_RAW so it fails

      I think there are two possible solutions here (there will be more possibly):

      • Change how exporters work to detect this case and treat lang_strings()
      • Just apply a quick fix in enrolment_status changing the expected returned type to string (something like)

      return $statusvalues[(int) $value] ? ($statusvalues[(int) $value])->out() :  null;

       

      STEPS TO REPRODUCE

      • Create a new report, using the "Courses" report source
      • Add the Enrolment Status column
      • Using the mobile app (dev webapp version here https://integration.apps.moodledemo.net/) try to access to the report (you can also just try doing a curl request)

      curl 'https://mysite/webservice/rest/server.php?moodlewsrestformat=json&wsfunction=core_reportbuilder_retrieve_report' --data-raw 'reportid=45&page=0&perpage=20&moodlewssettingfilter=true&moodlewssettingfileurl=true&moodlewssettinglang=en&wsfunction=core_reportbuilder_retrieve_report&wstoken=mytoken'

       

            dpalou Dani Palou
            jleyva Juan Leyva
            Paul Holden Paul Holden
            Jake Dallimore Jake Dallimore
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours, 29 minutes
                3h 29m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.