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

External enrol get users courses only return the first course

XMLWordPrintable

    • MOODLE_29_STABLE
    • MOODLE_28_STABLE, MOODLE_29_STABLE
    • MDL-50271-master
    • Hide
      1. Enable the multimedia plugin filter at site level
      2. Create a couple of courses, ensure that the multimedia filter is enabled for both courses.
      3. Update the courses description/summary including normal links (<a href=..) to youtube videos.
      4. Enroll a user as student in both courses
      5. As admin, enable "Mobile services": Plugins ► Web Services ► Mobile
      6. Create a Token for the student user:
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      7. Next, you can do a CURL REST call simulating a WS client with the student user .
        • You need to replace the wstoken, userid (with the student user id) and the URL of your moodle instance

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'userid=106&wsfunction=core_enrol_get_users_courses&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&moodlewssettingfilter=true'

          Note, you can use jsonlint.com to validate and format the json returned string or append "| python -m json.tool" to automatically format the command output

      8. Confirm that:
        • You receive a list including both courses
      Show
      Enable the multimedia plugin filter at site level Create a couple of courses, ensure that the multimedia filter is enabled for both courses. Update the courses description/summary including normal links (<a href=..) to youtube videos. Enroll a user as student in both courses As admin, enable "Mobile services": Plugins ► Web Services ► Mobile Create a Token for the student user: Click on Site administration ► Plugins ► Web services ► Manage tokens Next, you can do a CURL REST call simulating a WS client with the student user . You need to replace the wstoken, userid (with the student user id) and the URL of your moodle instance curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'userid=106&wsfunction=core_enrol_get_users_courses&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&moodlewssettingfilter=true' Note, you can use jsonlint.com to validate and format the json returned string or append "| python -m json.tool" to automatically format the command output Confirm that: You receive a list including both courses

      There are times where only one course is returned from the core_enrol_external::get_users_courses(). I narrowed it down to an exception thrown during the validation of the context of each course. It seems that calling $PAGE->set_course() creates some issues.

      Here is a backtrace that can help:

      Default exception handler: Coding error detected, it must be fixed by a programmer: The theme has already been set up for this page ready for output. Therefore, you can no longer change the theme, or anything that might affect what the current theme is, for example, the course.
       
      Debug: Stack trace when the theme was set up: 
       
      - line 637 of /lib/pagelib.php: call to moodle_page->initialise_theme_and_output()
      - line 812 of /lib/pagelib.php: call to moodle_page->magic_get_theme()
      - line 64 of /filter/mediaplugin/filter.php: call to moodle_page->get_renderer()
      - line 167 of /lib/filterlib.php: call to filter_mediaplugin->filter()
      - line 205 of /lib/filterlib.php: call to filter_manager->apply_filter_chain()
      - line 337 of /lib/filterlib.php: call to filter_manager->filter_text()
      - line 1222 of /lib/weblib.php: call to performance_measuring_filter_manager->filter_text()
      - line 752 of /lib/externallib.php: call to format_text()
      - line 328 of /enrol/externallib.php: call to external_format_text()
      - line ? of unknownfile: call to core_enrol_external::get_users_courses()
      - line 1780 of /webservice/lib.php: call to call_user_func_array()
      - line 1644 of /webservice/lib.php: call to webservice_base_server->execute()
      - line 44 of /webservice/rest/server.php: call to webservice_base_server->run()
       
      Error code: codingerror
      * line 1832 of /lib/pagelib.php: coding_exception thrown
      * line 914 of /lib/pagelib.php: call to moodle_page->ensure_theme_not_set()
      * line 2627 of /lib/moodlelib.php: call to moodle_page->set_course()
      * line 379 of /lib/externallib.php: call to require_login()
      * line 310 of /enrol/externallib.php: call to external_api::validate_context()
      * line ? of unknownfile: call to core_enrol_external::get_users_courses()
      * line 1780 of /webservice/lib.php: call to call_user_func_array()
      * line 1644 of /webservice/lib.php: call to webservice_base_server->execute()
      * line 44 of /webservice/rest/server.php: call to webservice_base_server->run()
      , referer: http://localhost:8100/
      

      STEPS TO REPRODUCE:

      1. Enable the multimedia filter at site and course level
      2. Edit the description of two courses where the same user is enrolled, add normal links to youtube videos
      3. Open the site with the Mobile app, you will see only one course (the first course where the user is enrolled)

      I have reproduced this on master but it might affect other versions. I was logged in as admin but I think I have experienced this as another user.

            jleyva Juan Leyva
            fred Frédéric Massart
            Ankit Agarwal Ankit Agarwal
            Dan Poltawski Dan Poltawski
            John Okely John Okely
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

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