From 34e60be48e5a2fca21949a88828df2065f7e9e8d Mon Sep 17 00:00:00 2001 From: Michael Kotlyar Date: Fri, 16 Jan 2026 15:08:39 +0000 Subject: [PATCH] MDL-87492 mod_quiz: 'autosubmit' quiz attempt handling fix Some quiz attempts throw an exception when they are being processed and are stuck in a 'submitted' state. This change wraps the process in a transaction so that there are no partial changes made in such cases. --- public/mod/quiz/classes/quiz_attempt.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/mod/quiz/classes/quiz_attempt.php b/public/mod/quiz/classes/quiz_attempt.php index 8aee1b09bd4..896cc581a35 100644 --- a/public/mod/quiz/classes/quiz_attempt.php +++ b/public/mod/quiz/classes/quiz_attempt.php @@ -1618,6 +1618,7 @@ class quiz_attempt { * @param bool $studentisonline is the student currently interacting with Moodle? */ public function handle_if_time_expired($timestamp, $studentisonline) { + global $DB; $timeclose = $this->get_access_manager($timestamp)->get_end_time($this->attempt); @@ -1652,8 +1653,10 @@ class quiz_attempt { // Transition to the appropriate state. switch ($this->quizobj->get_quiz()->overduehandling) { case 'autosubmit': + $transaction = $DB->start_delegated_transaction(); $this->process_submit($timestamp, false, $studentisonline ? $timestamp : $timeclose, $studentisonline); $this->process_grade_submission($studentisonline ? $timestamp : $timeclose); + $transaction->allow_commit(); return; case 'graceperiod':