Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit 370bda4cb96acac3a8f1090ff54bfea97d88401c 1 parent 62b0af5
Tim Hunt timhunt authored
2  question/type/calculated/questiontype.php
@@ -1843,6 +1843,7 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
1843 1843
1844 1844 parent::move_files($questionid, $oldcontextid, $newcontextid);
1845 1845 $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
  1846 + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
1846 1847 }
1847 1848
1848 1849 protected function delete_files($questionid, $contextid) {
@@ -1850,6 +1851,7 @@ protected function delete_files($questionid, $contextid) {
1850 1851
1851 1852 parent::delete_files($questionid, $contextid);
1852 1853 $this->delete_files_in_answers($questionid, $contextid);
  1854 + $this->delete_files_in_hints($questionid, $contextid);
1853 1855 }
1854 1856 }
1855 1857
2  question/type/calculatedmulti/questiontype.php
@@ -280,6 +280,7 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
280 280
281 281 parent::move_files($questionid, $oldcontextid, $newcontextid);
282 282 $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid, true);
  283 + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
283 284
284 285 $fs->move_area_files_to_new_context($oldcontextid,
285 286 $newcontextid, 'qtype_calculatedmulti', 'correctfeedback', $questionid);
@@ -294,6 +295,7 @@ protected function delete_files($questionid, $contextid) {
294 295
295 296 parent::delete_files($questionid, $contextid);
296 297 $this->delete_files_in_answers($questionid, $contextid, true);
  298 + $this->delete_files_in_hints($questionid, $contextid);
297 299
298 300 $fs->delete_area_files($contextid, 'qtype_calculatedmulti',
299 301 'correctfeedback', $questionid);
2  question/type/match/questiontype.php
@@ -208,6 +208,7 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
208 208 }
209 209
210 210 $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid);
  211 + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
211 212 }
212 213
213 214 protected function delete_files($questionid, $contextid) {
@@ -223,5 +224,6 @@ protected function delete_files($questionid, $contextid) {
223 224 }
224 225
225 226 $this->delete_files_in_combined_feedback($questionid, $contextid);
  227 + $this->delete_files_in_hints($questionid, $contextid);
226 228 }
227 229 }
10 question/type/multianswer/questiontype.php
@@ -226,6 +226,16 @@ public function get_random_guess_score($questiondata) {
226 226 }
227 227 return $fractionsum / $fractionmax;
228 228 }
  229 +
  230 + public function move_files($questionid, $oldcontextid, $newcontextid) {
  231 + parent::move_files($questionid, $oldcontextid, $newcontextid);
  232 + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
  233 + }
  234 +
  235 + protected function delete_files($questionid, $contextid) {
  236 + parent::delete_files($questionid, $contextid);
  237 + $this->delete_files_in_hints($questionid, $contextid);
  238 + }
229 239 }
230 240
231 241
2  question/type/multichoice/questiontype.php
@@ -240,11 +240,13 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
240 240 parent::move_files($questionid, $oldcontextid, $newcontextid);
241 241 $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid, true);
242 242 $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid);
  243 + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
243 244 }
244 245
245 246 protected function delete_files($questionid, $contextid) {
246 247 parent::delete_files($questionid, $contextid);
247 248 $this->delete_files_in_answers($questionid, $contextid, true);
248 249 $this->delete_files_in_combined_feedback($questionid, $contextid);
  250 + $this->delete_files_in_hints($questionid, $contextid);
249 251 }
250 252 }
2  question/type/numerical/questiontype.php
@@ -470,6 +470,7 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
470 470
471 471 parent::move_files($questionid, $oldcontextid, $newcontextid);
472 472 $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
  473 + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
473 474 }
474 475
475 476 protected function delete_files($questionid, $contextid) {
@@ -477,6 +478,7 @@ protected function delete_files($questionid, $contextid) {
477 478
478 479 parent::delete_files($questionid, $contextid);
479 480 $this->delete_files_in_answers($questionid, $contextid);
  481 + $this->delete_files_in_hints($questionid, $contextid);
480 482 }
481 483 }
482 484
37 question/type/questiontypebase.php
@@ -1131,6 +1131,27 @@ protected function move_files_in_answers($questionid, $oldcontextid,
1131 1131 }
1132 1132
1133 1133 /**
  1134 + * Move all the files belonging to this question's hints when the question
  1135 + * is moved from one context to another.
  1136 + * @param int $questionid the question being moved.
  1137 + * @param int $oldcontextid the context it is moving from.
  1138 + * @param int $newcontextid the context it is moving to.
  1139 + * @param bool $answerstoo whether there is an 'answer' question area,
  1140 + * as well as an 'answerfeedback' one. Default false.
  1141 + */
  1142 + protected function move_files_in_hints($questionid, $oldcontextid, $newcontextid) {
  1143 + global $DB;
  1144 + $fs = get_file_storage();
  1145 +
  1146 + $hintids = $DB->get_records_menu('question_hints',
  1147 + array('questionid' => $questionid), 'id', 'id,1');
  1148 + foreach ($hintids as $hintid => $notused) {
  1149 + $fs->move_area_files_to_new_context($oldcontextid,
  1150 + $newcontextid, 'question', 'hint', $hintid);
  1151 + }
  1152 + }
  1153 +
  1154 + /**
1134 1155 * Move all the files belonging to this question's answers when the question
1135 1156 * is moved from one context to another.
1136 1157 * @param int $questionid the question being moved.
@@ -1185,6 +1206,22 @@ protected function delete_files_in_answers($questionid, $contextid, $answerstoo
1185 1206 }
1186 1207
1187 1208 /**
  1209 + * Delete all the files belonging to this question's hints.
  1210 + * @param int $questionid the question being deleted.
  1211 + * @param int $contextid the context the question is in.
  1212 + */
  1213 + protected function delete_files_in_hints($questionid, $contextid) {
  1214 + global $DB;
  1215 + $fs = get_file_storage();
  1216 +
  1217 + $hintids = $DB->get_records_menu('question_hints',
  1218 + array('questionid' => $questionid), 'id', 'id,1');
  1219 + foreach ($hintids as $hintid => $notused) {
  1220 + $fs->delete_area_files($contextid, 'question', 'hint', $hintid);
  1221 + }
  1222 + }
  1223 +
  1224 + /**
1188 1225 * Delete all the files belonging to this question's answers.
1189 1226 * @param int $questionid the question being deleted.
1190 1227 * @param int $contextid the context the question is in.
2  question/type/shortanswer/questiontype.php
@@ -49,11 +49,13 @@ protected function questionid_column_name() {
49 49 public function move_files($questionid, $oldcontextid, $newcontextid) {
50 50 parent::move_files($questionid, $oldcontextid, $newcontextid);
51 51 $this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
  52 + $this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
52 53 }
53 54
54 55 protected function delete_files($questionid, $contextid) {
55 56 parent::delete_files($questionid, $contextid);
56 57 $this->delete_files_in_answers($questionid, $contextid);
  58 + $this->delete_files_in_hints($questionid, $contextid);
57 59 }
58 60
59 61 public function save_question_options($question) {

0 comments on commit 370bda4

Please sign in to comment.
Something went wrong with that request. Please try again.