Skip to content

Commit

Permalink
MDL-56972 backup: fix question category stamp duplicates during restore
Browse files Browse the repository at this point in the history
To kerb future stamp duplication, MDL-54864 added a unique index to the
question_categories table (stamp, contextid) and added an upgrade step
to fix existing duplicate stamps. It missed the case where a course with
duplicate stamps in the same context is directly restored into moodle
3.1, causing index clashes. This issue provides a fix for that.
  • Loading branch information
snake committed Nov 18, 2016
1 parent b4d6669 commit fe9864f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4331,6 +4331,14 @@ protected function process_question_category($data) {
}
$data->contextid = $mapping->parentitemid;

// Before 3.1, the 'stamp' field could be erroneously duplicated.
// From 3.1 onwards, there's a unique index of (contextid, stamp).
// If we encounter a duplicate in an old restore file, just generate a new stamp.
// This is the same as what happens during an upgrade to 3.1+ anyway.
if ($DB->record_exists('question_categories', ['stamp' => $data->stamp, 'contextid' => $data->contextid])) {
$data->stamp = make_unique_id_code();
}

// Let's create the question_category and save mapping
$newitemid = $DB->insert_record('question_categories', $data);
$this->set_mapping('question_category', $oldid, $newitemid);
Expand Down

0 comments on commit fe9864f

Please sign in to comment.