From 9523cbfcef4ea7bae0b2185691e2fdb8c5f8a7a6 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 30 Mar 2007 10:17:16 +0000 Subject: [PATCH] Small code cleanup to fix an obscure warning. If you got an error in the middle of creating a quiz attempt, you could get an attempt with no states. Then that caused an error when the attempt was deleted. Merged from MOODLE_17_STABLE. --- lib/questionlib.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/questionlib.php b/lib/questionlib.php index fd53272d0e..0585b1a30c 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -373,11 +373,13 @@ function delete_attempt($attemptid) { global $QTYPES; $states = get_records('question_states', 'attempt', $attemptid); - $stateslist = implode(',', array_keys($states)); - - // delete questiontype-specific data - foreach ($QTYPES as $qtype) { - $qtype->delete_states($stateslist); + if ($states) { + $stateslist = implode(',', array_keys($states)); + + // delete question-type specific data + foreach ($QTYPES as $qtype) { + $qtype->delete_states($stateslist); + } } // delete entries from all other question tables @@ -385,8 +387,6 @@ function delete_attempt($attemptid) { delete_records("question_states", "attempt", $attemptid); delete_records("question_sessions", "attemptid", $attemptid); delete_records("question_attempts", "id", $attemptid); - - return; } /** -- 2.39.5