From 0143e8bcf4f42c26dee5c88429e083b44bcbf769 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Mon, 14 Oct 2019 11:47:57 +0800 Subject: [PATCH] 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. --- question/category_class.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/question/category_class.php b/question/category_class.php index 7a9bdb8086f..902276776bc 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -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(); }