MDL-30742 restoring 1.9 backups with missing question data should be robust

This commit is contained in:
Tim Hunt
2011-12-14 17:17:07 +00:00
parent f89a83b87b
commit b5f65ba14c
2 changed files with 20 additions and 1 deletions
@@ -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']);
}
@@ -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);
}