Permalink
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 62b0af5 commit 370bda4cb96acac3a8f1090ff54bfea97d88401c @timhunt timhunt committed Feb 21, 2012
@@ -1843,13 +1843,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);
}
}
@@ -280,6 +280,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);
@@ -294,6 +295,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);
@@ -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);
}
}
@@ -226,6 +226,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);
+ }
}
@@ -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);
}
}
@@ -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);
}
}
@@ -1131,6 +1131,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.
@@ -1185,6 +1206,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.
@@ -49,11 +49,13 @@ protected 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 370bda4

Please sign in to comment.