mirror of
https://github.com/moodle/moodle.git
synced 2025-03-23 00:50:15 +01:00
MDL-78025 question: move hiding logic into question_delete_question
This logic belongs in the API, so it is applied consistently. Also this avoids calling the expensive function questions_in_use twice per question.
This commit is contained in:
parent
b2d0712748
commit
a9fa52295a
@ -28,6 +28,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core_question\local\bank\question_version_status;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -360,8 +361,10 @@ function question_delete_question($questionid): void {
|
||||
$questionstocheck[] = $question->parent;
|
||||
}
|
||||
|
||||
// Do not delete a question if it is used by an activity module
|
||||
// Do not delete a question if it is used by an activity module. Just mark the version hidden.
|
||||
if (questions_in_use($questionstocheck)) {
|
||||
$DB->set_field('question_versions', 'status',
|
||||
question_version_status::QUESTION_STATUS_HIDDEN, ['questionid' => $questionid]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -83,12 +83,7 @@ if ($deleteselected && ($confirm = optional_param('confirm', '', PARAM_ALPHANUM)
|
||||
foreach ($questionlist as $questionid) {
|
||||
$questionid = (int)$questionid;
|
||||
question_require_capability_on($questionid, 'edit');
|
||||
if (questions_in_use(array($questionid))) {
|
||||
$DB->set_field('question_versions', 'status',
|
||||
\core_question\local\bank\question_version_status::QUESTION_STATUS_HIDDEN, ['questionid' => $questionid]);
|
||||
} else {
|
||||
question_delete_question($questionid);
|
||||
}
|
||||
question_delete_question($questionid);
|
||||
}
|
||||
}
|
||||
redirect($returnurl);
|
||||
|
Loading…
x
Reference in New Issue
Block a user