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.
This commit is contained in:
Tim Hunt 2012-02-21 17:54:58 +00:00
parent c4a12afaf9
commit d44480f60f
8 changed files with 59 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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) {