Skip to content

Commit ba16b58

Browse files
committed
Fix logic in PRT tidy script.
1 parent 72026e7 commit ba16b58

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

stack/questiontest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ public function update_expected_testcase(array $prtrenames, array $notedata) {
8181
$oldanswernotes = $prtstate->__get('answernotes');
8282
// Expected answer notes are always a string, first element in the array.
8383
$note = $oldanswernotes[0];
84-
foreach (stack_utils::decompose_rename_operation($notedata[$oldprtname]) as $onote => $nnote) {
85-
$note = str_replace($onote, $nnote, $note);
84+
if (array_key_exists($oldprtname, $notedata) && is_array($notedata[$oldprtname])) {
85+
foreach (stack_utils::decompose_rename_operation($notedata[$oldprtname]) as $onote => $nnote) {
86+
$note = str_replace($onote, $nnote, $note);
87+
}
8688
}
8789
$newanswernotes = [$note];
8890
$prtstate->answernotes = $newanswernotes;

tidyquestion.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
redirect($returnurl);
9292
} else if ($data = $form->get_data()) {
9393
$qtype = question_bank::get_qtype('stack');
94-
$testscases = $qtype->load_question_tests($question->id);
9594

9695
$transaction = $DB->start_delegated_transaction();
9796

@@ -104,6 +103,10 @@
104103
$qtype->rename_input($question->id, $from, $to);
105104
}
106105

106+
// Rename inputs before getting the test cases. These test cases need the _new_ input names.
107+
// Get the test cases before renaming the question parts.
108+
$testscases = $qtype->load_question_tests($question->id);
109+
107110
// Rename the PRT nodes.
108111
$noderenames = [];
109112
foreach ($question->prts as $oldprtname => $prt) {

0 commit comments

Comments
 (0)