Skip to content

Commit 59cda8c

Browse files
committed
Possible fix for issue #249. Further testing called for.
1 parent df4938a commit 59cda8c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

backup/moodle2/restore_qtype_coderunner_plugin.class.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ public function process_coderunner_options($data) {
149149
public static function convert_backup_to_questiondata(array $backupdata): stdClass {
150150
$questiondata = parent::convert_backup_to_questiondata($backupdata);
151151
$qtype = $questiondata->qtype;
152-
if ($qtype !== 'coderunner' || !isset($backupdata["plugin_qtype_{$qtype}_question"]['coderunner_testcases'])) {
153-
return $questiondata;
154-
}
155152

156153
$questiondata->options->testcases = [];
157154
foreach ($backupdata["plugin_qtype_{$qtype}_question"]['coderunner_testcases']['coderunner_testcase'] as $record) {
@@ -180,6 +177,7 @@ protected function define_excluded_identity_hash_fields(): array {
180177
'/hints',
181178
'/prototype',
182179
'/options/customise',
180+
'/options/templateparamsevald',
183181
'/options/testcases/id',
184182
'/options/testcases/questionid',
185183
];
@@ -196,6 +194,9 @@ public static function remove_excluded_question_data(stdClass $questiondata, arr
196194
if (isset($questiondata->answers)) {
197195
unset($questiondata->answers);
198196
}
197+
if (isset($questiondata->options->answers)) {
198+
unset($questiondata->options->answers);
199+
}
199200
if (isset($questiondata->hints)) {
200201
unset($questiondata->hints);
201202
}

questiontype.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ public function can_analyse_responses() {
8282
* @return mixed array as above, or null to tell the base class to do nothing.
8383
*/
8484
public function extra_question_fields() {
85+
return self::extra_question_fields_static();
86+
}
87+
88+
// We need access to this list of extra question fields during quiz duplication
89+
// (when no actual question exists) so I make it static.
90+
public static function extra_question_fields_static() {
8591
return ['question_coderunner_options',
8692
'coderunnertype',
8793
'prototypetype',
@@ -420,8 +426,12 @@ public function get_question_options($question) {
420426
} else {
421427
$qtype = $options->coderunnertype;
422428
$context = $this->question_context($question);
423-
$question->prototype = $this->get_prototype($qtype, $context);
424-
$this->set_inherited_fields($options, $question->prototype);
429+
$prototype = $this->get_prototype($qtype, $context);
430+
if (!($question->export_process ?? false)) {
431+
// Don't inherit fields when exporting during quiz duplication or backup restore.
432+
$this->set_inherited_fields($options, $prototype);
433+
$question->prototype = $prototype;
434+
}
425435
}
426436

427437
// Add in any testcases.

0 commit comments

Comments
 (0)