Commit 37ef65d4 authored by Andrew Nicols's avatar Andrew Nicols
Browse files

Merge branch 'MDL-63752' of https://github.com/timhunt/moodle

parents fbf4eaee 2d696f8f
......@@ -420,7 +420,9 @@ class question_category_object {
}
}
if (((string) $idnumber !== '') && !empty($contextid)) {
if ((string) $idnumber === '') {
$idnumber = null;
} else if (!empty($contextid)) {
// While this check already exists in the form validation, this is a backstop preventing unnecessary errors.
if ($DB->record_exists('question_categories',
['idnumber' => $idnumber, 'contextid' => $contextid])) {
......@@ -493,7 +495,9 @@ class question_category_object {
}
}
if (((string) $idnumber !== '') && !empty($tocontextid)) {
if ((string) $idnumber === '') {
$idnumber = null;
} else if (!empty($tocontextid)) {
// While this check already exists in the form validation, this is a backstop preventing unnecessary errors.
if ($DB->record_exists('question_categories',
['idnumber' => $idnumber, 'contextid' => $tocontextid])) {
......
......@@ -406,10 +406,16 @@ class qformat_default {
$question->timecreated = time();
$question->modifiedby = $USER->id;
$question->timemodified = time();
if (isset($question->idnumber) && (string) $question->idnumber !== '') {
if ($DB->record_exists('question', ['idnumber' => $question->idnumber, 'category' => $question->category])) {
// We cannot have duplicate idnumbers in a category.
if (isset($question->idnumber)) {
if ((string) $question->idnumber === '') {
// Id number not really set. Get rid of it.
unset($question->idnumber);
} else {
if ($DB->record_exists('question',
['idnumber' => $question->idnumber, 'category' => $question->category])) {
// We cannot have duplicate idnumbers in a category. Just remove it.
unset($question->idnumber);
}
}
}
......
......@@ -63,7 +63,7 @@
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.0000000</penalty>
<hidden>0</hidden>
<idnumber>K1</idnumber>
<idnumber></idnumber>
<responseformat>editor</responseformat>
<responserequired>1</responserequired>
<responsefieldlines>10</responsefieldlines>
......@@ -91,7 +91,7 @@
<defaultgrade>1.0000000</defaultgrade>
<penalty>1.0000000</penalty>
<hidden>0</hidden>
<idnumber>K2</idnumber>
<idnumber></idnumber>
<answer fraction="100" format="moodle_auto_format">
<text>true</text>
<feedback format="html">
......
......@@ -366,7 +366,7 @@ class qformat_xml_import_export_test extends advanced_testcase {
'attachmentsrequired' => 0,
'graderinfo' => ['format' => '1', 'text' => ''],
'responsetemplate' => ['format' => '1', 'text' => ''],
'idnumber' => 'K1']);
'idnumber' => '']);
$kappaquestion1 = $generator->create_question('truefalse', null, [
'category' => $categorykappa->id,
'name' => 'Kappa Question',
......@@ -378,7 +378,7 @@ class qformat_xml_import_export_test extends advanced_testcase {
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1',
'idnumber' => 'K2']);
'idnumber' => '']);
$categorylambda = $generator->create_question_category([
'name' => 'Lambda',
'contextid' => '2',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment