From cee74600fa6e68508ef9d42b0e4f8df2373051cb Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 13 Jun 2011 18:28:59 +0100 Subject: [PATCH] MDL-27839 supply default qtype_essay_options if they are not present in the XML. --- .../restore_qtype_essay_plugin.class.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php b/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php index 00b2429fe90..06f3a460f76 100644 --- a/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php +++ b/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php @@ -73,4 +73,34 @@ class restore_qtype_essay_plugin extends restore_qtype_plugin { new restore_decode_content('qtype_essay_options', 'graderinfo', 'qtype_essay'), ); } + + /** + * When restoring old data, that does not have the essay options information + * in the XML, supply defaults. + */ + protected function after_execute_question() { + global $DB; + + $essayswithoutoptions = $DB->get_records_sql(" + SELECT * + FROM {question} q + WHERE q.qtype = ? + AND NOT EXISTS ( + SELECT 1 + FROM {qtype_essay_options} + WHERE questionid = q.id + ) + ", array('essay')); + + foreach ($essayswithoutoptions as $q) { + $defaultoptions = new stdClass(); + $defaultoptions->questionid = $q->id; + $defaultoptions->responseformat = 'editor'; + $defaultoptions->responsefieldlines = 15; + $defaultoptions->attachments = 0; + $defaultoptions->graderinfo = ''; + $defaultoptions->graderinfoformat = FORMAT_HTML; + $DB->insert_record('qtype_essay_options', $defaultoptions); + } + } }