MDL-52206 quiz: Integration bug fixes
authorPeter Dias <peter@moodle.com>
Thu, 7 Oct 2021 13:24:03 +0000 (21:24 +0800)
committerSara Arjona <sara@moodle.com>
Fri, 8 Oct 2021 05:33:05 +0000 (07:33 +0200)
mod/lti/tests/behat/lti_completion_pass_grade.feature
mod/quiz/db/upgrade.php

index e69f74f..26b471a 100644 (file)
@@ -41,9 +41,7 @@ Feature: Pass grade activity completion information in the LTI activity
     And I log out
 
   Scenario: View automatic completion items as a teacher
-    Given I log in as "teacher1"
-    And I am on "Course 1" course homepage
-    When I follow "Music history"
+    Given I am on the "Music history" "lti activity" page logged in as teacher1
     Then "Music history" should have the "View" completion condition
     And "Music history" should have the "Receive a grade" completion condition
     And "Music history" should have the "Receive a passing grade" completion condition
index 8ae2d57..6b343c1 100644 (file)
@@ -65,7 +65,7 @@ function xmldb_quiz_upgrade($oldversion) {
         $field = new xmldb_field('completionpass');
 
         if ($dbman->field_exists($table, $field)) {
-            $sql = "SELECT q.id " .
+            $sql = "SELECT q.id, m.id as quizid " .
                      "FROM {quiz} q " .
                "INNER JOIN {course_modules} cm ON cm.instance = q.id " .
                "INNER JOIN {modules} m ON m.id = cm.module " .
@@ -74,13 +74,16 @@ function xmldb_quiz_upgrade($oldversion) {
             /** @var moodle_recordset $records */
             $records = $DB->get_recordset_sql($sql, ['name' => 'quiz', 'completionpass' => 1], 0, 1000);
             while ($records->valid()) {
+                $quizmodule = null;
                 foreach ($records as $record) {
                     $ids[] = $record->id;
+                    $quizmodule = $record->quizid;
                 }
 
                 if ($ids) {
                     list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED);
-                    $DB->set_field_select('course_modules', 'completionpassgrade', 1, "instance $insql", $params);
+                    $DB->set_field_select('course_modules', 'completionpassgrade', 1,
+                        "module = :quiz AND instance $insql", $params + ['quiz' => $quizmodule]);
 
                     // Reset the value so it doesn't get picked on the next run. The field will be dropped later.
                     $DB->set_field_select('quiz', 'completionpass', 0, "id $insql", $params);