Skip to content

Commit

Permalink
mod_quizgame: improve handling of activity only restores.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourget committed Feb 18, 2018
1 parent 6712bdd commit 2be5c2b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion backup/moodle2/restore_quizgame_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit 2be5c2b

Please sign in to comment.