diff --git a/mod/quiz/db/upgrade.php b/mod/quiz/db/upgrade.php index 9f87e8b74e7..4aa0fabd742 100644 --- a/mod/quiz/db/upgrade.php +++ b/mod/quiz/db/upgrade.php @@ -128,5 +128,40 @@ function xmldb_quiz_upgrade($oldversion) { upgrade_mod_savepoint(true, 2018020700, 'quiz'); } + if ($oldversion < 2018020701) { + // This SQL fetches all "random" questions from the question bank. + $fromclause = "FROM {quiz_slots} qs + JOIN {question} q ON q.id = qs.questionid + WHERE q.qtype = ?"; + + // Get the total record count - used for the progress bar. + $total = $DB->count_records_sql("SELECT count(qs.id) $fromclause", array('random')); + + // Get the records themselves. + $rs = $DB->get_recordset_sql("SELECT qs.id, q.category, q.questiontext $fromclause", array('random')); + + $a = new stdClass(); + $a->total = $total; + $a->done = 0; + + // For each question, move the configuration data to the quiz_slots table. + $pbar = new progress_bar('updatequizslotswithrandom', 500, true); + foreach ($rs as $record) { + $data = new stdClass(); + $data->id = $record->id; + $data->questioncategoryid = $record->category; + $data->includingsubcategories = empty($record->questiontext) ? 0 : 1; + $DB->update_record('quiz_slots', $data); + + // Update progress. + $a->done++; + $pbar->update($a->done, $a->total, get_string('updatequizslotswithrandomxofy', 'quiz', $a)); + } + $rs->close(); + + // Quiz savepoint reached. + upgrade_mod_savepoint(true, 2018020701, 'quiz'); + } + return true; } diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index 5f0eb1edd57..452ee008479 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -917,6 +917,7 @@ $string['ungraded'] = 'Ungraded'; $string['unit'] = 'Unit'; $string['unknowntype'] = 'Question type not supported at line {$a}. The question will be ignored'; $string['updatesettings'] = 'Update quiz settings'; +$string['updatequizslotswithrandomxofy'] = 'Updating quiz slots with "random" question data ({$a->done}/{$a->total})'; $string['updatingatttemptgrades'] = 'Updating attempt grades.'; $string['updatingfinalgrades'] = 'Updating final grades.'; $string['updatingthegradebook'] = 'Updating the gradebook.'; diff --git a/mod/quiz/version.php b/mod/quiz/version.php index e568ee781e9..f13117669ed 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2018020700; +$plugin->version = 2018020701; $plugin->requires = 2017110800; $plugin->component = 'mod_quiz'; $plugin->cron = 60;