mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-27747 quiz locallib remove unnecessary try/catch. #475
delegated_transaction just does the right thing. Thanks to Justin Wyllie for spotting this.
This commit is contained in:
parent
3b049b7626
commit
0f1c59c552
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user