Skip to content

Commit

Permalink
Merge branch 'MDL-63752' of https://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Oct 25, 2018
2 parents fbf4eae + 2d696f8 commit 37ef65d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
8 changes: 6 additions & 2 deletions question/category_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ public function add_category($newparent, $newcategory, $newinfo, $return = false
}
}

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])) {
Expand Down Expand Up @@ -493,7 +495,9 @@ public function update_category($updateid, $newparent, $newname, $newinfo, $newi
}
}

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])) {
Expand Down
12 changes: 9 additions & 3 deletions question/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,16 @@ public function importprocess() {
$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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down
4 changes: 2 additions & 2 deletions question/format/xml/tests/qformat_xml_import_export_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function test_export_nested_categories_with_questions() {
'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',
Expand All @@ -378,7 +378,7 @@ public function test_export_nested_categories_with_questions() {
'feedbacktrue' => ['format' => '1', 'text' => ''],
'feedbackfalse' => ['format' => '1', 'text' => ''],
'penalty' => '1',
'idnumber' => 'K2']);
'idnumber' => '']);
$categorylambda = $generator->create_question_category([
'name' => 'Lambda',
'contextid' => '2',
Expand Down

0 comments on commit 37ef65d

Please sign in to comment.