-
Bug
-
Resolution: Fixed
-
Minor
-
4.0.5, 4.1, 4.2
-
1
-
Team Hedgehog 2023 Sprint 2.2
Reported here: https://moodle.org/mod/forum/discuss.php?d=442733
Problem
If the enrolment method for a 1.1 tool (the "Published as LTI tool" entry containing the various settings, including which activity/course to share) is updated "in-place" (the LTI version is just changed from 1.1/2.0 to 1.3), then it can cause an error during the LTI Advantage grade sync task:
Scheduled task failed: Publish as LTI tool grade sync (enrol_lti\local\ltiadvantage\task\sync_grades),Argument 3 passed to enrol_lti\local\ltiadvantage\entity\user::create() must be of the type int, null given, called in /var/app/current/moodle/enrol/lti/classes/local/ltiadvantage/repository/user_repository.php on line 58 |
This only happens if the legacy method has attached lti user (enrol_lti_users) and occurs because the repository code assumes the enrol_lti_users table will contain this field if it's attached to a 1.3 tool. That is, it doesn't account for this 'update in place' situation where legacy records (which don't contain the field) are present too.
Replication steps
- Set up two local Moodle sites - one provider, one consumer
- Perform all the relevant LTI setup on the provider site (enrol_lti and auth_lti need enabling, allow frame embedding)
- Publish an assignment activity on the provider site using legacy (1.1/2.0 method)
- In the consumer site, create a course.
- Create a new external tool instance in the course, using:
- Launch URL for the Tool URL
- Secret for the Shared secret
- Use 'testconsumer' as the consumer key (this can really be anything)
- As a student, launch into the external tool instance (this will create the relevant enrol_lti_users records)
- Now, log in to the provider site as the teacher/admin
- Go to the published resource (the activity you published over 1.1)
- Edit the settings and change the LTI version to 1.3
- Save
- Now, log out.
- Log in to the consumer site as the admin
- Perform the relevant LTI 1.3 setup (see https://docs.moodle.org/401/en/Publish_as_LTI_tool#Dynamic_Registration)
- Once you've got the preconfigured tool, go to the course
- Click to add a new instance of external tool
- Select the 1.3 tool now
- Click "Select content" when prompted (signing is and linking accounts to the admin/teacher as needed)
- Select the published activity
- Name the activity "1.3 tool instance" to make it clear.
- Save the activity
- Log out
- Log in as the student
- Launch the "1.3 tool instance" tool
- Now, log out
- Log in as the admin user
- Launch the "1.3 tool instance" tool
- Click "View all submissions"
- Enable quick grading (checkbox below the student rows)
- Enter a grade for both student entries (for the student who launched over 1.1 and the student who launched over 1.3). These may be the same student - that's fine.
- Save all quick grading changes
- Now, in the provider site root, run the grade sync:
php admin/cli/scheduled_task.php --execute="\enrol_lti\local\ltiadvantage\task\sync_grades"
Expected: Grade sync task runs without error and syncs the grade given to the LTI Advantage user.
Actual: grade sync error:Scheduled task failed: Publish as LTI tool grade sync (enrol_lti\local\ltiadvantage\task\sync_grades),Argument 3 passed to enrol_lti\local\ltiadvantage\entity\user::create() must be of the type int, null given, called in /var/app/current/moodle/enrol/lti/classes/local/ltiadvantage/repository/user_repository.php on line 58
Solution
LTI Advantage grade sync should only concern itself with LTI Advantage users, so we can just skip those records which are associated with the legacy enrolment method.
We also need to consider whether to prohibit this 'in place update' of the enrolment method. I'll admit this wasn't the original intention and was likely an oversight on my part. The intention was to bring up 1.3 tools alongside their 1.1 counterparts to allow users to confirm 1.3 launches work, before disabling access to the 1.1 instance.
Finally, if we do allow in-place updates, we need to make sure that legacy launches are prevented via the now-updated enrolment instance. Currently, if I update the instance from 1.1 to 1.3 - and provided the 1.1 links are still present in the platform - I can launch into the tool via either 1.1 or 1.3. This shouldn't be possible since we only have a 1.3 instance.