From 384ab12c554b6a5e8bac1f0b43d175e9aa63dc55 Mon Sep 17 00:00:00 2001 From: Tim Hunt <T.J.Hunt@open.ac.uk> Date: Tue, 25 Apr 2023 18:11:57 +0100 Subject: [PATCH] MDL-78025 quiz: fix the quiz_questions_in_use logic --- mod/quiz/lib.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index b8fc686a9fc..bdfc85229cf 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1432,25 +1432,15 @@ function quiz_get_post_actions() { } /** + * Standard callback used by questions_in_use. + * * @param array $questionids of question ids. * @return bool whether any of these questions are used by any instance of this module. */ function quiz_questions_in_use($questionids) { - global $DB; - list($test, $params) = $DB->get_in_or_equal($questionids); - $params['component'] = 'mod_quiz'; - $params['questionarea'] = 'slot'; - $sql = "SELECT qs.id - FROM {quiz_slots} qs - JOIN {question_references} qr ON qr.itemid = qs.id - JOIN {question_bank_entries} qbe ON qbe.id = qr.questionbankentryid - JOIN {question_versions} qv ON qv.questionbankentryid = qbe.id - WHERE qv.questionid $test - AND qr.component = ? - AND qr.questionarea = ?"; - return $DB->record_exists_sql($sql, $params) || question_engine::questions_in_use( - $questionids, new qubaid_join('{quiz_attempts} quiza', - 'quiza.uniqueid', 'quiza.preview = 0')); + return question_engine::questions_in_use($questionids, + new qubaid_join('{quiz_attempts} quiza', 'quiza.uniqueid', + 'quiza.preview = 0')); } /**