From 0f1c59c552b52a9e66783f76393f7669a77cb856 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 7 Jun 2011 16:27:43 +0100 Subject: [PATCH] MDL-27747 quiz locallib remove unnecessary try/catch. #475 delegated_transaction just does the right thing. Thanks to Justin Wyllie for spotting this. --- mod/quiz/locallib.php | 59 ++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 9dfbc6bebfa..4504dca3da1 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -481,43 +481,38 @@ function quiz_set_grade($newgrade, $quiz) { // Use a transaction, so that on those databases that support it, this is safer. $transaction = $DB->start_delegated_transaction(); - try { - // Update the quiz table. - $DB->set_field('quiz', 'grade', $newgrade, array('id' => $quiz->instance)); + // Update the quiz table. + $DB->set_field('quiz', 'grade', $newgrade, array('id' => $quiz->instance)); - // Rescaling the other data is only possible if the old grade was non-zero. - if ($quiz->grade > 1e-7) { - global $CFG; + // Rescaling the other data is only possible if the old grade was non-zero. + if ($quiz->grade > 1e-7) { + global $CFG; - $factor = $newgrade/$quiz->grade; - $quiz->grade = $newgrade; + $factor = $newgrade/$quiz->grade; + $quiz->grade = $newgrade; - // Update the quiz_grades table. - $timemodified = time(); - $DB->execute(" - UPDATE {quiz_grades} - SET grade = ? * grade, timemodified = ? - WHERE quiz = ? - ", array($factor, $timemodified, $quiz->id)); + // Update the quiz_grades table. + $timemodified = time(); + $DB->execute(" + UPDATE {quiz_grades} + SET grade = ? * grade, timemodified = ? + WHERE quiz = ? + ", array($factor, $timemodified, $quiz->id)); - // Update the quiz_feedback table. - $DB->execute(" - UPDATE {quiz_feedback} - SET mingrade = ? * mingrade, maxgrade = ? * maxgrade - WHERE quizid = ? - ", array($factor, $factor, $quiz->id)); - } - - // update grade item and send all grades to gradebook - quiz_grade_item_update($quiz); - quiz_update_grades($quiz); - - $transaction->allow_commit(); - return true; - - } catch (Exception $e) { - $transaction->rollback($e); + // Update the quiz_feedback table. + $DB->execute(" + UPDATE {quiz_feedback} + SET mingrade = ? * mingrade, maxgrade = ? * maxgrade + WHERE quizid = ? + ", array($factor, $factor, $quiz->id)); } + + // update grade item and send all grades to gradebook + quiz_grade_item_update($quiz); + quiz_update_grades($quiz); + + $transaction->allow_commit(); + return true; } /**