Merge branch 'MDL-67842_37' of https://github.com/timhunt/moodle into MOODLE_37_STABLE

This commit is contained in:
Eloy Lafuente (stronk7)
2020-02-04 22:46:37 +01:00
+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;
}
}
}