Browse files

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...
1 parent d1c12af commit ea9f1a8faac08147d1032228a74b05a973d782e0 @timhunt timhunt committed Feb 21, 2012
View
2 question/type/calculated/questiontype.php
@@ -1839,13 +1839,15 @@ 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) {
$fs = get_file_storage();
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid);
+ $this->delete_files_in_hints($questionid, $contextid);
}
}
View
2 question/type/calculatedmulti/questiontype.php
@@ -276,6 +276,7 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
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 @@ protected function delete_files($questionid, $contextid) {
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);
View
2 question/type/match/questiontype.php
@@ -208,6 +208,7 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
}
$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 @@ protected function delete_files($questionid, $contextid) {
}
$this->delete_files_in_combined_feedback($questionid, $contextid);
+ $this->delete_files_in_hints($questionid, $contextid);
}
}
View
10 question/type/multianswer/questiontype.php
@@ -223,6 +223,16 @@ public function get_random_guess_score($questiondata) {
}
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);
+ }
}
View
2 question/type/multichoice/questiontype.php
@@ -240,11 +240,13 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
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);
}
}
View
2 question/type/numerical/questiontype.php
@@ -470,13 +470,15 @@ 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) {
$fs = get_file_storage();
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid);
+ $this->delete_files_in_hints($questionid, $contextid);
}
}
View
37 question/type/questiontypebase.php
@@ -1118,6 +1118,27 @@ protected function move_files_in_answers($questionid, $oldcontextid,
}
/**
+ * 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.
* @param int $questionid the question being moved.
@@ -1172,6 +1193,22 @@ protected function delete_files_in_answers($questionid, $contextid, $answerstoo
}
/**
+ * 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.
* @param int $contextid the context the question is in.
View
2 question/type/shortanswer/questiontype.php
@@ -49,11 +49,13 @@ public function questionid_column_name() {
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) {

0 comments on commit ea9f1a8

Please sign in to comment.