MDL-67842 questions: Cannot remove the idnumber from a question

This commit is contained in:
Tim Hunt
2020-02-03 09:49:50 +00:00
parent ee0a8161dd
commit a8e2b5cea1
+15 -9
View File
@@ -350,16 +350,22 @@ class question_type {
$question->defaultmark = $form->defaultmark;
}
if (isset($form->idnumber) && ((string) $form->idnumber !== '')) {
// While this check already exists in the form validation, this is a backstop preventing unnecessary errors.
if (strpos($form->category, ',') !== false) {
list($category, $categorycontextid) = explode(',', $form->category);
if (isset($form->idnumber)) {
if ((string) $form->idnumber === '') {
$question->idnumber = null;
} else {
$category = $form->category;
}
if (!$DB->record_exists('question',
['idnumber' => $form->idnumber, 'category' => $category])) {
$question->idnumber = $form->idnumber;
// While this check already exists in the form validation,
// this is a backstop preventing unnecessary errors.
// Only set the idnumber if it has changed and will not cause a unique index violation.
if (strpos($form->category, ',') !== false) {
list($category, $categorycontextid) = explode(',', $form->category);
} else {
$category = $form->category;
}
if (!$DB->record_exists('question',
['idnumber' => $form->idnumber, 'category' => $category])) {
$question->idnumber = $form->idnumber;
}
}
}