mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02: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
ae4efa96ee
commit
8e1583455e
2 changed files with 5 additions and 7 deletions
|
@ -28,6 +28,7 @@
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @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();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
@ -360,8 +361,10 @@ function question_delete_question($questionid): void {
|
||||||
$questionstocheck[] = $question->parent;
|
$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)) {
|
if (questions_in_use($questionstocheck)) {
|
||||||
|
$DB->set_field('question_versions', 'status',
|
||||||
|
question_version_status::QUESTION_STATUS_HIDDEN, ['questionid' => $questionid]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,14 +83,9 @@ if ($deleteselected && ($confirm = optional_param('confirm', '', PARAM_ALPHANUM)
|
||||||
foreach ($questionlist as $questionid) {
|
foreach ($questionlist as $questionid) {
|
||||||
$questionid = (int)$questionid;
|
$questionid = (int)$questionid;
|
||||||
question_require_capability_on($questionid, 'edit');
|
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);
|
redirect($returnurl);
|
||||||
} else {
|
} else {
|
||||||
throw new \moodle_exception('invalidconfirm', 'question');
|
throw new \moodle_exception('invalidconfirm', 'question');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue