From a23bda41e44c43f1af1f76e024407463e011e217 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 5 Aug 2011 16:45:17 +0100 Subject: [PATCH] MDL-28618 question combined feedback: inconsistency in file areas. The (partially|in)?correct feedback fields acutally store their files in a file area with component 'question'. Some code, however, was written as if they were stored in the qtype_whatever area. --- backup/moodle2/restore_stepslib.php | 6 +++ question/type/match/questiontype.php | 9 ++-- .../backup_qtype_multichoice_plugin.class.php | 13 ------ question/type/multichoice/questiontype.php | 20 +-------- question/type/questiontypebase.php | 41 +++++++++++++++++++ 5 files changed, 52 insertions(+), 37 deletions(-) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 643c478ead2c0..0b02c0105d9db 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2637,6 +2637,12 @@ protected function define_execution() { $oldctxid, $this->task->get_userid(), 'question_answer', null, $newctxid, true); restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'hint', $oldctxid, $this->task->get_userid(), 'question_hint', null, $newctxid, true); + restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'correctfeedback', + $oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true); + restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'partiallycorrectfeedback', + $oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true); + restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'incorrectfeedback', + $oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true); // Add qtype dependent files $components = backup_qtype_plugin::get_components_and_fileareas($question->qtype); foreach ($components as $component => $fileareas) { diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php index 8828030474f79..36f08b5f6f266 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -206,6 +206,8 @@ public function move_files($questionid, $oldcontextid, $newcontextid) { $fs->move_area_files_to_new_context($oldcontextid, $newcontextid, 'qtype_match', 'subquestion', $subquestionid); } + + $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid); } protected function delete_files($questionid, $contextid) { @@ -220,11 +222,6 @@ protected function delete_files($questionid, $contextid) { $fs->delete_area_files($contextid, 'qtype_match', 'subquestion', $subquestionid); } - $fs->delete_area_files($contextid, 'qtype_multichoice', - 'correctfeedback', $questionid); - $fs->delete_area_files($contextid, 'qtype_multichoice', - 'partiallycorrectfeedback', $questionid); - $fs->delete_area_files($contextid, 'qtype_multichoice', - 'incorrectfeedback', $questionid); + $this->delete_files_in_combined_feedback($questionid, $contextid); } } diff --git a/question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php b/question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php index b4d20db3fcc4f..70724e00e52bc 100644 --- a/question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php +++ b/question/type/multichoice/backup/moodle2/backup_qtype_multichoice_plugin.class.php @@ -69,17 +69,4 @@ protected function define_question_plugin_structure() { return $plugin; } - - /** - * Returns one array with filearea => mappingname elements for the qtype - * - * Used by {@link get_components_and_fileareas} to know about all the qtype - * files to be processed both in backup and restore. - */ - public static function get_qtype_fileareas() { - return array( - 'correctfeedback' => 'question_created', - 'partiallycorrectfeedback' => 'question_created', - 'incorrectfeedback' => 'question_created'); - } } diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index f7b46ada8549b..240bc4c038467 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -231,30 +231,14 @@ public static function get_numbering_styles() { } public function move_files($questionid, $oldcontextid, $newcontextid) { - $fs = get_file_storage(); - parent::move_files($questionid, $oldcontextid, $newcontextid); $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid, true); - - $fs->move_area_files_to_new_context($oldcontextid, - $newcontextid, 'qtype_multichoice', 'correctfeedback', $questionid); - $fs->move_area_files_to_new_context($oldcontextid, - $newcontextid, 'qtype_multichoice', 'partiallycorrectfeedback', $questionid); - $fs->move_area_files_to_new_context($oldcontextid, - $newcontextid, 'qtype_multichoice', 'incorrectfeedback', $questionid); + $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid); } protected function delete_files($questionid, $contextid) { - $fs = get_file_storage(); - parent::delete_files($questionid, $contextid); $this->delete_files_in_answers($questionid, $contextid, true); - - $fs->delete_area_files($contextid, - 'qtype_multichoice', 'correctfeedback', $questionid); - $fs->delete_area_files($contextid, - 'qtype_multichoice', 'partiallycorrectfeedback', $questionid); - $fs->delete_area_files($contextid, - 'qtype_multichoice', 'incorrectfeedback', $questionid); + $this->delete_files_in_combined_feedback($questionid, $contextid); } } diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php index 75766690ca62d..d127c6ebe28ad 100644 --- a/question/type/questiontypebase.php +++ b/question/type/questiontypebase.php @@ -1107,6 +1107,28 @@ protected function move_files_in_answers($questionid, $oldcontextid, } } + /** + * Move all the files belonging to this question's answers when the question + * is moved from one context to another. + * @param int $questionid the question being moved. + * @param int $oldcontextid the context it is moving from. + * @param int $newcontextid the context it is moving to. + * @param bool $answerstoo whether there is an 'answer' question area, + * as well as an 'answerfeedback' one. Default false. + */ + protected function move_files_in_combined_feedback($questionid, $oldcontextid, + $newcontextid) { + global $DB; + $fs = get_file_storage(); + + $fs->move_area_files_to_new_context($oldcontextid, + $newcontextid, 'question', 'correctfeedback', $questionid); + $fs->move_area_files_to_new_context($oldcontextid, + $newcontextid, 'question', 'partiallycorrectfeedback', $questionid); + $fs->move_area_files_to_new_context($oldcontextid, + $newcontextid, 'question', 'incorrectfeedback', $questionid); + } + /** * Delete all the files belonging to this question. * @param int $questionid the question being deleted. @@ -1139,6 +1161,25 @@ protected function delete_files_in_answers($questionid, $contextid, $answerstoo } } + /** + * Delete all the files belonging to this question's answers. + * @param int $questionid the question being deleted. + * @param int $contextid the context the question is in. + * @param bool $answerstoo whether there is an 'answer' question area, + * as well as an 'answerfeedback' one. Default false. + */ + protected function delete_files_in_combined_feedback($questionid, $contextid) { + global $DB; + $fs = get_file_storage(); + + $fs->delete_area_files($contextid, + 'question', 'correctfeedback', $questionid); + $fs->delete_area_files($contextid, + 'question', 'partiallycorrectfeedback', $questionid); + $fs->delete_area_files($contextid, + 'question', 'incorrectfeedback', $questionid); + } + public function import_file($context, $component, $filearea, $itemid, $file) { $fs = get_file_storage(); $record = new stdClass();