From 5650c805998bda1418371b8edb495da810b30a7d Mon Sep 17 00:00:00 2001 From: odziminski Date: Fri, 23 Feb 2024 08:26:51 +0100 Subject: [PATCH] allow for checks only within question-delete command --- Moosh/Command/Moodle41/Question/QuestionDelete.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Moosh/Command/Moodle41/Question/QuestionDelete.php b/Moosh/Command/Moodle41/Question/QuestionDelete.php index b0456378..85d4815e 100644 --- a/Moosh/Command/Moodle41/Question/QuestionDelete.php +++ b/Moosh/Command/Moodle41/Question/QuestionDelete.php @@ -16,12 +16,14 @@ public function __construct() { parent::__construct('delete', 'question'); $this->addArgument('questionid'); + $this->addOption('check-only', null, 'Only check if the question is in use, do not delete'); } public function execute() { global $DB, $CFG; $questionid = $this->arguments[0]; + $checkOnly = $this->expandedOptions['check-only']; require_once($CFG->dirroot . '/question/engine/lib.php'); require_once($CFG->dirroot . '/question/type/questiontypebase.php'); @@ -40,10 +42,12 @@ public function execute() } if (questions_in_use($questionsToCheck)) { mtrace("[ID:$questionid] Question in use in activities - can not delete"); - return; + if ($checkOnly) { + return; + } + } + if (!$checkOnly) { + question_delete_question($question->id); } - question_delete_question($question->id); - } } -