MDL-56972 backup: fix question category stamp duplicates during restore

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.
This commit is contained in:
Jake Dallimore
2016-11-18 11:15:02 +08:00
parent b4d6669dd0
commit fe9864f488
+8
View File
@@ -4331,6 +4331,14 @@ class restore_create_categories_and_questions extends restore_structure_step {
}
$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);