From d44480f60ffe07f40d792504cbd9a5ab36ba27b9 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 21 Feb 2012 17:54:58 +0000 Subject: [PATCH] MDL-31729 questions: files for hints are not moved or deleted. The files that belong to the question hints are neither moved when the question is moved to another context, nor deleted when the question is deleted. Oops! How come no one noticed that until today. --- question/type/calculated/questiontype.php | 2 + .../type/calculatedmulti/questiontype.php | 2 + question/type/match/questiontype.php | 2 + question/type/multianswer/questiontype.php | 10 +++++ question/type/multichoice/questiontype.php | 2 + question/type/numerical/questiontype.php | 2 + question/type/questiontypebase.php | 37 +++++++++++++++++++ question/type/shortanswer/questiontype.php | 2 + 8 files changed, 59 insertions(+) diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index a86bb20d4ca..af7cd38433a 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -1839,6 +1839,7 @@ class qtype_calculated extends question_type { parent::move_files($questionid, $oldcontextid, $newcontextid); $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid); + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid); } protected function delete_files($questionid, $contextid) { @@ -1846,6 +1847,7 @@ class qtype_calculated extends question_type { parent::delete_files($questionid, $contextid); $this->delete_files_in_answers($questionid, $contextid); + $this->delete_files_in_hints($questionid, $contextid); } } diff --git a/question/type/calculatedmulti/questiontype.php b/question/type/calculatedmulti/questiontype.php index 963a95e6cba..220d1bcaf8f 100644 --- a/question/type/calculatedmulti/questiontype.php +++ b/question/type/calculatedmulti/questiontype.php @@ -276,6 +276,7 @@ class qtype_calculatedmulti extends qtype_calculated { parent::move_files($questionid, $oldcontextid, $newcontextid); $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid, true); + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid); $fs->move_area_files_to_new_context($oldcontextid, $newcontextid, 'qtype_calculatedmulti', 'correctfeedback', $questionid); @@ -290,6 +291,7 @@ class qtype_calculatedmulti extends qtype_calculated { parent::delete_files($questionid, $contextid); $this->delete_files_in_answers($questionid, $contextid, true); + $this->delete_files_in_hints($questionid, $contextid); $fs->delete_area_files($contextid, 'qtype_calculatedmulti', 'correctfeedback', $questionid); diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php index 36f08b5f6f2..4a381970a05 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -208,6 +208,7 @@ class qtype_match extends question_type { } $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid); + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid); } protected function delete_files($questionid, $contextid) { @@ -223,5 +224,6 @@ class qtype_match extends question_type { } $this->delete_files_in_combined_feedback($questionid, $contextid); + $this->delete_files_in_hints($questionid, $contextid); } } diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php index c9cb5df8363..3dc969aa496 100644 --- a/question/type/multianswer/questiontype.php +++ b/question/type/multianswer/questiontype.php @@ -223,6 +223,16 @@ class qtype_multianswer extends question_type { } return $fractionsum / $fractionmax; } + + public function move_files($questionid, $oldcontextid, $newcontextid) { + parent::move_files($questionid, $oldcontextid, $newcontextid); + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid); + } + + protected function delete_files($questionid, $contextid) { + parent::delete_files($questionid, $contextid); + $this->delete_files_in_hints($questionid, $contextid); + } } diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index e155366f157..02fe6f4e56a 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -240,11 +240,13 @@ class qtype_multichoice extends question_type { parent::move_files($questionid, $oldcontextid, $newcontextid); $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid, true); $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid); + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid); } protected function delete_files($questionid, $contextid) { parent::delete_files($questionid, $contextid); $this->delete_files_in_answers($questionid, $contextid, true); $this->delete_files_in_combined_feedback($questionid, $contextid); + $this->delete_files_in_hints($questionid, $contextid); } } diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php index b275ffa195d..53f29b2c407 100644 --- a/question/type/numerical/questiontype.php +++ b/question/type/numerical/questiontype.php @@ -470,6 +470,7 @@ class qtype_numerical extends question_type { parent::move_files($questionid, $oldcontextid, $newcontextid); $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid); + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid); } protected function delete_files($questionid, $contextid) { @@ -477,6 +478,7 @@ class qtype_numerical extends question_type { parent::delete_files($questionid, $contextid); $this->delete_files_in_answers($questionid, $contextid); + $this->delete_files_in_hints($questionid, $contextid); } } diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php index 88750453d06..0e18786a3af 100644 --- a/question/type/questiontypebase.php +++ b/question/type/questiontypebase.php @@ -1103,6 +1103,27 @@ class question_type { } } + /** + * Move all the files belonging to this question's hints 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_hints($questionid, $oldcontextid, $newcontextid) { + global $DB; + $fs = get_file_storage(); + + $hintids = $DB->get_records_menu('question_hints', + array('questionid' => $questionid), 'id', 'id,1'); + foreach ($hintids as $hintid => $notused) { + $fs->move_area_files_to_new_context($oldcontextid, + $newcontextid, 'question', 'hint', $hintid); + } + } + /** * Move all the files belonging to this question's answers when the question * is moved from one context to another. @@ -1157,6 +1178,22 @@ class question_type { } } + /** + * Delete all the files belonging to this question's hints. + * @param int $questionid the question being deleted. + * @param int $contextid the context the question is in. + */ + protected function delete_files_in_hints($questionid, $contextid) { + global $DB; + $fs = get_file_storage(); + + $hintids = $DB->get_records_menu('question_hints', + array('questionid' => $questionid), 'id', 'id,1'); + foreach ($hintids as $hintid => $notused) { + $fs->delete_area_files($contextid, 'question', 'hint', $hintid); + } + } + /** * Delete all the files belonging to this question's answers. * @param int $questionid the question being deleted. diff --git a/question/type/shortanswer/questiontype.php b/question/type/shortanswer/questiontype.php index 7c78d389098..31212ce6e78 100644 --- a/question/type/shortanswer/questiontype.php +++ b/question/type/shortanswer/questiontype.php @@ -49,11 +49,13 @@ class qtype_shortanswer extends question_type { public function move_files($questionid, $oldcontextid, $newcontextid) { parent::move_files($questionid, $oldcontextid, $newcontextid); $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid); + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid); } protected function delete_files($questionid, $contextid) { parent::delete_files($questionid, $contextid); $this->delete_files_in_answers($questionid, $contextid); + $this->delete_files_in_hints($questionid, $contextid); } public function save_question_options($question) {