]> git.mjollnir.org Git - moodle.git/commitdiff
question bank: MDL-14376 Errors deleting a course containing Cloze questions.
authortjhunt <tjhunt>
Thu, 11 Dec 2008 05:31:33 +0000 (05:31 +0000)
committertjhunt <tjhunt>
Thu, 11 Dec 2008 05:31:33 +0000 (05:31 +0000)
(For some reason, this only seemed to cause problems on MySQL.)

lib/questionlib.php

index 1a16128807021a57232f544e6b420765b492c0af..9dfb6200caa6291a8019c0112f2b98c22d2b7850 100644 (file)
@@ -450,13 +450,19 @@ function delete_attempt($attemptid) {
 function delete_question($questionid) {
     global $QTYPES, $DB;
 
+    if (!$question = $DB->get_record('question', array('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 = $DB->get_record('question', array('id'=>$questionid));
     question_require_capability_on($question, 'edit');
     if ($question) {
         if (isset($QTYPES[$question->qtype])) {