From 2be5c2beff3cddb50e475e6a7c958ab8d7b96e3f Mon Sep 17 00:00:00 2001 From: Stephen Bourget Date: Sat, 17 Feb 2018 20:59:59 -0500 Subject: [PATCH] mod_quizgame: improve handling of activity only restores. --- backup/moodle2/restore_quizgame_stepslib.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/backup/moodle2/restore_quizgame_stepslib.php b/backup/moodle2/restore_quizgame_stepslib.php index b96d445..c3930e2 100644 --- a/backup/moodle2/restore_quizgame_stepslib.php +++ b/backup/moodle2/restore_quizgame_stepslib.php @@ -47,6 +47,7 @@ protected function process_quizgame($data) { $data = (object)$data; $oldid = $data->id; + $oldcourse = $data->course; $data->course = $this->get_courseid(); // Map the category in the QB. @@ -59,7 +60,22 @@ protected function process_quizgame($data) { // Now get the context for this category. $newcontext = $DB->get_field('question_categories', 'contextid', array('id' => $newcat)); // Assemble the field data. - $data->questioncategory = implode(',', array($newcat, $newcontext)); + if (!empty($newcat)) { + $data->questioncategory = implode(',', array($newcat, $newcontext)); + } else { + if (!$this->task->is_samesite() || $data->course != $oldcourse) { + // We cannot map to the question category. + // They were not included in the backup since they were at a higher context. + // This can happen when we are backing up the activity alone and trying to restore it elsewhere. + $this->log('question category ' . $category[0] . ' was associated with the quizgame ' . + $data->id . ' but cannot actually be used as it is not available in this backup. ' . + 'The category needs to be re-selected.', backup::LOG_INFO); + + // Remove the old data. + $data->questioncategory = ""; + } + } + } else { // The qustion category was just stored as an ID, so find the new mapping. $data->questioncategory = $this->get_mappingid('question_category', $category);