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:38:20 +08:00
parent e7ac8db8a1
commit f79a974435
+6 -1
View File
@@ -475,6 +475,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.
@@ -537,6 +538,7 @@ class question_category_object {
}
}
$updateidnumber = true;
if ((string) $idnumber === '') {
$idnumber = null;
} else if (!empty($tocontextid)) {
@@ -544,6 +546,7 @@ class question_category_object {
if ($DB->record_exists('question_categories',
['idnumber' => $idnumber, 'contextid' => $tocontextid])) {
$idnumber = null;
$updateidnumber = false;
}
}
@@ -555,7 +558,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();
}