diff --git a/question/category_class.php b/question/category_class.php index 6711a833b8d..eaa8a47419d 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -470,6 +470,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. @@ -532,6 +533,7 @@ class question_category_object { } } + $updateidnumber = true; if ((string) $idnumber === '') { $idnumber = null; } else if (!empty($tocontextid)) { @@ -539,6 +541,7 @@ class question_category_object { if ($DB->record_exists('question_categories', ['idnumber' => $idnumber, 'contextid' => $tocontextid])) { $idnumber = null; + $updateidnumber = false; } } @@ -550,7 +553,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(); }