From 7bbe96dc16a435392595a95f2dad7fa07cddea29 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 5 May 2011 19:01:26 +0100 Subject: [PATCH] MDL-27394 Moodle 2.0 backup and restore may randomise the order of multichoice/numerical/shortanswer answers --- backup/moodle2/backup_qtype_plugin.class.php | 14 ++++++++++++-- backup/moodle2/restore_stepslib.php | 1 + .../moodle2/backup_qtype_match_plugin.class.php | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/backup/moodle2/backup_qtype_plugin.class.php b/backup/moodle2/backup_qtype_plugin.class.php index c0d48436f42..603ac9d8918 100644 --- a/backup/moodle2/backup_qtype_plugin.class.php +++ b/backup/moodle2/backup_qtype_plugin.class.php @@ -53,7 +53,12 @@ abstract class backup_qtype_plugin extends backup_plugin { $answers->add_child($answer); // Set the sources - $answer->set_source_table('question_answers', array('question' => backup::VAR_PARENTID)); + $answer->set_source_sql(' + SELECT * + FROM {question_answers} + WHERE question = :question + ORDER BY id', + array('question' => backup::VAR_PARENTID)); // Aliases $answer->set_source_alias('answer', 'answertext'); @@ -82,7 +87,12 @@ abstract class backup_qtype_plugin extends backup_plugin { $units->add_child($unit); // Set the sources - $unit->set_source_table('question_numerical_units', array('question' => backup::VAR_PARENTID)); + $unit->set_source_sql(' + SELECT * + FROM {question_numerical_units} + WHERE question = :question + ORDER BY id', + array('question' => backup::VAR_PARENTID)); // don't need to annotate ids nor files } diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 3f376ed1945..53fd78886ad 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2194,6 +2194,7 @@ abstract class restore_activity_structure_step extends restore_structure_step { /** * As far as activity restore steps are implementing restore_subplugin stuff, they need to * have the parent task available for wrapping purposes (get course/context....) + * @return restore_task */ public function get_task() { return $this->task; diff --git a/question/type/match/backup/moodle2/backup_qtype_match_plugin.class.php b/question/type/match/backup/moodle2/backup_qtype_match_plugin.class.php index 5ea9e66324e..f91a8d27e2a 100644 --- a/question/type/match/backup/moodle2/backup_qtype_match_plugin.class.php +++ b/question/type/match/backup/moodle2/backup_qtype_match_plugin.class.php @@ -58,7 +58,12 @@ class backup_qtype_match_plugin extends backup_qtype_plugin { // set source to populate the data $matchoptions->set_source_table('question_match', array('question' => backup::VAR_PARENTID)); - $match->set_source_table('question_match_sub', array('question' => backup::VAR_PARENTID)); + $match->set_source_sql(' + SELECT * + FROM {question_match_sub} + WHERE question = :question + ORDER BY id', + array('question' => backup::VAR_PARENTID)); // don't need to annotate ids nor files