MDL-66796 mod_quiz: only update the id number if changed

If the idnumber is present in the DB, it's set to null. In this case,
don't update the value.
This commit is contained in:
Jake Dallimore
2019-10-14 13:41:40 +08:00
parent 21ee8ef703
commit 0143e8bcf4
+6 -1
View File
@@ -437,6 +437,7 @@ class question_category_object {
$cat->sortorder = 999;
$cat->stamp = make_unique_id_code();
$cat->idnumber = $idnumber;
$categoryid = $DB->insert_record("question_categories", $cat);
// Log the creation of this category.
@@ -491,6 +492,7 @@ class question_category_object {
}
}
$updateidnumber = true;
if ((string) $idnumber === '') {
$idnumber = null;
} else if (!empty($tocontextid)) {
@@ -498,6 +500,7 @@ class question_category_object {
if ($DB->record_exists('question_categories',
['idnumber' => $idnumber, 'contextid' => $tocontextid])) {
$idnumber = null;
$updateidnumber = false;
}
}
@@ -509,7 +512,9 @@ class question_category_object {
$cat->infoformat = $newinfoformat;
$cat->parent = $parentid;
$cat->contextid = $tocontextid;
$cat->idnumber = $idnumber;
if ($updateidnumber) {
$cat->idnumber = $idnumber;
}
if ($newstamprequired) {
$cat->stamp = make_unique_id_code();
}