From 4f4fa095e9a4947e1207c2ad7d4abc6e19f6a997 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 11 Dec 2008 05:31:41 +0000 Subject: [PATCH] question bank: MDL-14376 Errors deleting a course containing Cloze questions. (For some reason, this only seemed to cause problems on MySQL.) --- lib/questionlib.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/questionlib.php b/lib/questionlib.php index 8dcf0a03bde..a7dceb73095 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -451,13 +451,19 @@ function delete_attempt($attemptid) { function delete_question($questionid) { global $QTYPES; + if (!$question = get_record('question', 'id', $questionid)) { + // In some situations, for example if this was a child of a + // Cloze question that was previously deleted, the question may already + // have gone. In this case, just do nothing. + return; + } + // Do not delete a question if it is used by an activity module if (count(question_list_instances($questionid))) { return; } // delete questiontype-specific data - $question = get_record('question', 'id', $questionid); question_require_capability_on($question, 'edit'); if ($question) { if (isset($QTYPES[$question->qtype])) {