Problem/Motivation
If a user is enrolled in a course, but does not have a tracked role in that course, an error is thrown by the getCourseCompletionPercentage function:
Drupal\moodle_rest\Services\MoodleRestException: User is not enrolled in this course in Drupal\moodle_rest\Services\MoodleRest->requestFunction() (line 159 of /app/web/modules/contrib/moodle_rest/src/Services/MoodleRest.ph
This can occur if the user has either no role at all or, for example, has the Course Creator role only.
Steps to reproduce
- Enrol a user in a course using whatever method.
- Via the Moodle Site Administration, remove all course roles from that user, eg remove Student.
- Execute the
getCourseCompletionPercentageREST function.
No roles may be an edge case, but from some old discussion it does appear to be a supported state, even in current versions (tested with v4.5.2).
Not having the Student role seems a more likely scenario. The Moodle function core_completion_get_course_completion_status checks if a user is 'tracked' (see Moodle source) and throws an exception if not.
Proposed resolution
Add usernotenroled as a possible error code that will trigger a NULL return.
Issue fork moodle_rest-3523307
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
gaddman commentedComment #4
gaddman commentedMR7 working OK for me, no more failures when pulling course info from Moodle.
Comment #7
ekes commented