Skip to content

Commit

Permalink
allow for checks only within question-delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
odziminski committed Feb 23, 2024
1 parent 2c9e33d commit 5650c80
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Moosh/Command/Moodle41/Question/QuestionDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

}
}

0 comments on commit 5650c80

Please sign in to comment.