Permalink
Browse files

MDL-56303 quiz: lack of quiz filtering

Also, correctly feed completiongradeitemnumber with grade item numbers
and not with grade item ids.
  • Loading branch information...
danpoltawski authored and stronk7 committed Oct 6, 2016
1 parent f73f938 commit 41a9a9219ac55d42649f5b78ac85912f5de10b6b
Showing with 13 additions and 10 deletions.
  1. +13 −10 mod/quiz/db/upgrade.php
View
@@ -222,21 +222,24 @@ function xmldb_quiz_upgrade($oldversion) {
if ($oldversion < 2016100300) {
// Find quizzes with the combination of require passing grade and grade to pass 0.
$quizzes = $DB->get_records_sql("
SELECT gi.id, gi.iteminstance
$gradeitems = $DB->get_records_sql("
SELECT gi.id, gi.itemnumber, cm.id AS cmid
FROM {quiz} q
INNER JOIN {course_modules} cm ON q.id = cm.instance
INNER JOIN {grade_items} gi ON q.id = gi.iteminstance
INNER JOIN {modules} m ON m.id = cm.module
WHERE q.completionpass = 1
AND gi.gradepass = 0
AND cm.completiongradeitemnumber IS NULL");
if ($quizzes) {
foreach ($quizzes as $quiz) {
$DB->execute("UPDATE {course_modules}
SET completiongradeitemnumber = :gradeitemid
WHERE instance = :quizid",
array('gradeitemid' => $quiz->id, 'quizid' => $quiz->iteminstance));
}
AND cm.completiongradeitemnumber IS NULL
AND gi.itemmodule = m.name
AND gi.itemtype = ?
AND m.name = ?", array('mod', 'quiz'));
foreach ($gradeitems as $gradeitem) {
$DB->execute("UPDATE {course_modules}
SET completiongradeitemnumber = :itemnumber
WHERE id = :cmid",
array('itemnumber' => $gradeitem->itemnumber, 'cmid' => $gradeitem->cmid));
}
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2016100300, 'quiz');

0 comments on commit 41a9a92

Please sign in to comment.