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:
@@ -1130,6 +1130,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.
|
||||
@@ -1184,6 +1205,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.
|
||||
|
||||
Reference in New Issue
Block a user