From b5f65ba14cfa8d940563face1ef61b271dd8a0e6 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 14 Dec 2011 17:17:07 +0000 Subject: [PATCH] MDL-30742 restoring 1.9 backups with missing question data should be robust --- question/type/multichoice/backup/moodle1/lib.php | 15 +++++++++++++++ .../restore_qtype_multichoice_plugin.class.php | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/question/type/multichoice/backup/moodle1/lib.php b/question/type/multichoice/backup/moodle1/lib.php index b80f29914d0..bb1a459b6ef 100644 --- a/question/type/multichoice/backup/moodle1/lib.php +++ b/question/type/multichoice/backup/moodle1/lib.php @@ -50,6 +50,21 @@ class moodle1_qtype_multichoice_handler extends moodle1_qtype_handler { } // convert and write the multichoice + if (!isset($data['multichoice'])) { + // This should never happen, but it can do if the 1.9 site contained + // corrupt data/ + $data['multichoice'] = array(array( + 'single' => 1, + 'shuffleanswers' => 1, + 'correctfeedback' => '', + 'correctfeedbackformat' => FORMAT_HTML, + 'partiallycorrectfeedback' => '', + 'partiallycorrectfeedbackformat' => FORMAT_HTML, + 'incorrectfeedback' => '', + 'incorrectfeedbackformat' => FORMAT_HTML, + 'answernumbering' => 'abc', + )); + } $this->write_multichoice($data['multichoice'], $data['oldquestiontextformat']); } diff --git a/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php b/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php index 907e78010aa..230ef75d73a 100644 --- a/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php +++ b/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php @@ -73,7 +73,11 @@ class restore_qtype_multichoice_plugin extends restore_qtype_plugin { // Adjust some columns $data->question = $newquestionid; // Map sequence of question_answer ids - $answersarr = explode(',', $data->answers); + if ($data->answers) { + $answersarr = explode(',', $data->answers); + } else { + $answersarr = array(); + } foreach ($answersarr as $key => $answer) { $answersarr[$key] = $this->get_mappingid('question_answer', $answer); }