From 7ab2d7d7bdb632597621265997d38a9a7bc070df Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Thu, 7 Oct 2021 21:24:03 +0800 Subject: [PATCH] MDL-52206 quiz: Integration bug fixes --- mod/lti/tests/behat/lti_completion_pass_grade.feature | 4 +--- mod/quiz/db/upgrade.php | 7 +++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mod/lti/tests/behat/lti_completion_pass_grade.feature b/mod/lti/tests/behat/lti_completion_pass_grade.feature index e69f74ff996..26b471a2247 100644 --- a/mod/lti/tests/behat/lti_completion_pass_grade.feature +++ b/mod/lti/tests/behat/lti_completion_pass_grade.feature @@ -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 diff --git a/mod/quiz/db/upgrade.php b/mod/quiz/db/upgrade.php index 8ae2d577b51..6b343c1bbd7 100644 --- a/mod/quiz/db/upgrade.php +++ b/mod/quiz/db/upgrade.php @@ -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);