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

Missing LTI resource crashes sync_grades task

    XMLWordPrintable

Details

    • MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE
    • MOODLE_37_STABLE, MOODLE_38_STABLE
    • MDL-66671-master
    • Hide

      Setup

      1. You need two clean Moodle sites. One for the Provider and another for the consumer.
      2. As an admin you need to enable in both Moodle sites:
        1. In Site administration/Server/System paths, set the "Path to PHP CLI" to the proper one in your environment (usually, /usr/bin/php).
        2. In Site administration/Security/Site security settings check "Allow 'Run now' for scheduled tasks" is set to yes. 

      Setup: ProviderMoodle

      1. In the ProviderMoodle you need to enable the next settings and plugins:
        1. In Site Administration/Security/HTTP security Allow frame embedding set to enabled.
        2. In Site Administration/Plugins/Authentication/Manage authentication enable LTI.
        3. In Site Administration/Plugins/Enrolments/Manage enrol plugins enable Publish as LTI tool.
      2. Create a new course with two assignments (with Only text enable in Submission types) and named activity1 and activity2.
      3. Share these activities using Published as LTI tools. You could access using the Actions Menu in the course.
      4. You have to Publish these activities separately.
      5. For Activity1:
        1. Set Custom instance name as "LTI Activity1".
        2. Select the activity1 in the dropdown menu Tool to be published.
      6. For Activity2:
        1. Set Custom instance name as "LTI Activity2".
        2. Select the activity2 in the dropdown menu Tool to be published.
      7. Now you could see the details of the LTI activities in the main page for Published as LTI tools
        http://PROVIDERMODDLE/enrol/lti/index.php?courseid=COURSEID

       

      Setup: Consumer

      1. In the ConsumerMoodle you need to set up an External Tools for these two activities.
      2. To do that, go to Site administration/Plugins/Activity modules/External tool/Manage tools
        and use the "configure a tool manually" link to set up the activities.
      3. For Activity1:
        1. Set Tool name as "LTI Activity1"
        2. Set Tool URL with the value of the field "Launch URL" in the ProviderMoodle main page for Published as LTI tools for the LTI Activity 1.
        3. Set Consumer key as "activity1key"
        4. Set Shared secret as the value of the field "Secret" in the ProviderMoodle main page for Published as LTI tools for the LTI Activity 1.
        5. Open the Services section and:
          1. Set IMS LTI Assignment and Grade Services to "Use this service for grade sync and column management"
          2. Set IMS LTI Names and Role Provisioning to "Use this service to retrieve members' information as per privacy settings"
          3. Set Tool Settings to "Use this service"
        6. Save changes.
      4. For Activity2:
        1. Set Tool name as "LTI Activity2"
        2. Set Tool URL with the value of the field "Launch URL" in the ProviderMoodle main page for Published as LTI tools for the LTI Activity 2.
        3. Set Consumer key as "activity2key"
        4. Set Shared secret as the value of the field "Secret" in the ProviderMoodle main page for Published as LTI tools for the LTI Activity 2.
        5. Open the Services section and:
          1. Set IMS LTI Assignment and Grade Services to "Use this service for grade sync and column management"
          2. Set IMS LTI Names and Role Provisioning to "Use this service to retrieve members' information as per privacy settings"
          3. Set Tool Settings to "Use this service"
        6. Save changes.
      5. Now, you have to create a new course and add as two External Tool activities for these two new Tools, LTI Activity1 and LTI Activity2.
      6. For Activity1, Adding a new External tool and:
        1. Set Activity name as "LTI Activity1"
        2. Set Preconfigured tool to "LTI Activity1" in the dropdown menu.
        3. And click on Save and return to course.
      7. For Activity2, Adding a new External tool and:
        1. Set Activity name as "LTI Activity2"
        2. Set Preconfigured tool to "LTI Activity2" in the dropdown menu.
        3. And click on Save and return to course.
      8. Enrol two users as students named s1 and s2 in the course.

      Test

      1. Login as s1 in the ConsumerMoodle.
      2. Go to the course.
      3. Complete both activities, LTI Activity1 and LTI Activity2.
      4. Login as admin in the ProviderMoodle in another browser.
      5. Go to the course1.
      6. Go to the Activity1 and Activity2 and grade them.
      7. Go to Site Administration/Server/Tasks/Scheduled tasks and find "Publish as LTI tool grade sync" and run the task clicking on Run now in the column "Last run".
      8. Check the task log to see there are no errors.
      9. Verify that grades for s1 are updated from ProviderMoodle to ConsumerMoodle. To do that, access as s1 to the grades in the ConsumerMoodle and check the grades have been updated.
      10. Now, as admin in the ProviderMoodle, delete Activity1 but do not change any LTI provider enrolment settings.
      11. Login as s2 in the ConsumerMoodle.
      12. Complete the LTI Activity2.
      13. Login as admin in the ProviderMoodle.
      14. Go to the Activity2 and graded.
      15. Go to Site Administration/Server/Tasks/Scheduled tasks and find "Publish as LTI tool grade sync" and run the task clicking on Run now in the column "Last run".
      16. Check the task log to see that an error is reported for the first activity (something like "Failed - Invalid contextid 'XX' for the tool 'Z'."), but that whole task completes successfully.
      17. Check ConsumerMoodle to verify that the grades for the working activity where updated correctly in the course grade book for s2.

       
       
       
       

      Show
      Setup You need two clean Moodle sites. One for the Provider and another for the consumer. As an admin you need to enable in both Moodle sites: In Site administration/Server/System paths , set the " Path to PHP CLI" to the proper one in your environment (usually, /usr/bin/php). In Site administration/Security/Site security settings check "Allow 'Run now' for scheduled tasks" is set to yes.  Setup: ProviderMoodle In the ProviderMoodle you need to enable the next settings and plugins: In Site Administration/Security/HTTP security Allow frame embedding set to enabled. In Site Administration/Plugins/Authentication/Manage authentication enable LTI. In Site Administration/Plugins/Enrolments/Manage enrol plugins enable Publish as LTI tool. Create a new course with two assignments (with Only text enable in Submission types) and named activity1 and activity2. Share these activities using Published as LTI tools. You could access using the Actions Menu in the course. You have to Publish these activities separately. For Activity1: Set Custom instance name as "LTI Activity1". Select the activity1 in the dropdown menu Tool to be published. For Activity2: Set Custom instance name as "LTI Activity2". Select the activity2 in the dropdown menu Tool to be published. Now you could see the details of the LTI activities in the main page for Published as LTI tools http://PROVIDERMODDLE/enrol/lti/index.php?courseid=COURSEID   Setup: Consumer In the ConsumerMoodle you need to set up an External Tools for these two activities. To do that, go to Site administration/Plugins/Activity modules/External tool/Manage tools and use the "configure a tool manually" link to set up the activities. For Activity1: Set Tool name as "LTI Activity1" Set Tool URL with the value of the field "Launch URL" in the ProviderMoodle main page for Published as LTI tools for the LTI Activity 1. Set Consumer key as "activity1key" Set Shared secret as the value of the field "Secret" in the ProviderMoodle main page for Published as LTI tools for the LTI Activity 1. Open the Services section and: Set IMS LTI Assignment and Grade Services to "Use this service for grade sync and column management" Set IMS LTI Names and Role Provisioning to "Use this service to retrieve members' information as per privacy settings" Set Tool Settings to "Use this service" Save changes. For Activity2: Set Tool name as "LTI Activity2" Set Tool URL with the value of the field "Launch URL" in the ProviderMoodle main page for Published as LTI tools for the LTI Activity 2. Set Consumer key as "activity2key" Set Shared secret as the value of the field "Secret" in the ProviderMoodle main page for Published as LTI tools for the LTI Activity 2. Open the Services section and: Set IMS LTI Assignment and Grade Services to "Use this service for grade sync and column management" Set IMS LTI Names and Role Provisioning to "Use this service to retrieve members' information as per privacy settings" Set Tool Settings to "Use this service" Save changes. Now, you have to create a new course and add as two External Tool activities for these two new Tools, LTI Activity1 and LTI Activity2. For Activity1, Adding a new External tool and: Set Activity name as "LTI Activity1" Set Preconfigured tool to "LTI Activity1" in the dropdown menu. And click on Save and return to course. For Activity2, Adding a new External tool and: Set Activity name as "LTI Activity2" Set Preconfigured tool to "LTI Activity2" in the dropdown menu. And click on Save and return to course. Enrol two users as students named s1 and s2 in the course. Test Login as s1 in the ConsumerMoodle . Go to the course. Complete both activities, LTI Activity1 and LTI Activity2. Login as admin in the ProviderMoodle in another browser. Go to the course1. Go to the Activity1 and Activity2 and grade them. Go to Site Administration/Server/Tasks/Scheduled tasks and find "Publish as LTI tool grade sync" and run the task clicking on Run now in the column "Last run". Check the task log to see there are no errors. Verify that grades for s1 are updated from ProviderMoodle to ConsumerMoodle. To do that, access as s1 to the grades in the ConsumerMoodle and check the grades have been updated. Now, as admin in the ProviderMoodle, delete Activity1 but do not change any LTI provider enrolment settings. Login as s2 in the ConsumerMoodle. Complete the LTI Activity2. Login as admin in the ProviderMoodle. Go to the Activity2 and graded. Go to Site Administration/Server/Tasks/Scheduled tasks and find "Publish as LTI tool grade sync" and run the task clicking on Run now in the column "Last run". Check the task log to see that an error is reported for the first activity (something like " Failed - Invalid contextid 'XX' for the tool 'Z'. "), but that whole task completes successfully. Check ConsumerMoodle to verify that the grades for the working activity where updated correctly in the course grade book for s2.        

    Description

      As reported in https://moodle.org/mod/forum/discuss.php?d=390299

      If a resource used by LTI is removed "\enrol_lti\task\sync_grades" task crash due to a missing context.

       

      $ php www/admin/tool/task/cli/schedule_task.php --execute='\enrol_lti\task\sync_grades'
       Execute scheduled task: Publication comme outil LTI de synchro des notes (enrol_lti\task\sync_grades)
       Starting - Grade sync for shared tool '1' for the course '2'.
       Not sent - The grade for the user '10' in the tool '1' for the course '2' was not sent as the grades are the same.
       Not sent - The grade for the user '4' in the tool '1' for the course '2' was not sent as the grades are the same.
       Not sent - The grade for the user '12' in the tool '1' for the course '2' was not sent as the grades are the same.
       Completed - Synced grades for tool '1' in the course '2'. Processed 3 users; sent 0 grades.
      Starting - Grade sync for shared tool '3' for the course '2'.
       ... used 27 dbqueries
       ... used 0.095687866210938 seconds
       Scheduled task failed: Publication comme outil LTI de synchro des notes (enrol_lti\task\sync_grades),Impossible de trouver l'enregistrement de données dans la table context de la base de données.
       Debug info:
       SELECT * FROM
      {context}
      WHERE id = ?
       [array (
       0 => '28',
       )]
       Backtrace:
       
      line 1522 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select() line 5115 of /lib/accesslib.php: call to moodle_database->get_record() line 103 of /enrol/lti/classes/task/sync_grades.php: call to context::instance_by_id() line 156 of /admin/tool/task/cli/schedule_task.php: call to enrol_lti\task\sync_grades->execute() 

       

      Reproduced on latest Moodle 3.5.7+.

      Not tested against 3.5.8, 3.6, 3.7 and master yet but seeing enrol_lti git history they should be impacted too.

       

      Attachments

        Activity

          People

            dthies Daniel Thies
            ak4t0sh Arnaud Trouvé
            Carlos Escobedo Carlos Escobedo
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Janelle Barcega Janelle Barcega
            David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              11/May/20

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 5 minutes
                1d 5m