From d9cbd9b41e1309e83687d9156528e6c7ab7b6aed Mon Sep 17 00:00:00 2001 From: GabrielChagas14 <84946326+GabrielChagas14@users.noreply.github.com> Date: Fri, 27 Dec 2024 08:29:05 -0300 Subject: [PATCH] fix/add-transaction-grades (#907) --- app/controllers/GradesController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/GradesController.php b/app/controllers/GradesController.php index 851838095..462380c09 100644 --- a/app/controllers/GradesController.php +++ b/app/controllers/GradesController.php @@ -546,6 +546,7 @@ public function actionSaveGrades() $stage = Yii::app()->request->getPost("stage"); $isConcept = Yii::app()->request->getPost("isConcept"); + $transaction = Yii::app()->db->beginTransaction(); try { foreach ($students as $student) { foreach ($student["grades"] as $grade) { @@ -589,10 +590,12 @@ public function actionSaveGrades() } } self::saveGradeResults($classroomId, $disciplineId, $stage); + $transaction->commit(); header('HTTP/1.1 200 OK'); echo json_encode(["valid" => true]); } catch (Exception $e) { TLog::error("Ocorreu algum erro durante a transação de SaveGrades", ["ExceptionMessage" => $e->getMessage()]); + $transaction->rollback(); throw new Exception($e->getMessage(), 500, $e); } @@ -626,6 +629,7 @@ public function actionGetGrades() public function actionCalculateFinalMedia() { + $transaction = Yii::app()->db->beginTransaction(); try { $classroomId = Yii::app()->request->getPost("classroom"); $stage = Yii::app()->request->getPost("stage"); @@ -669,7 +673,9 @@ public function actionCalculateFinalMedia() } } + $transaction->commit(); } catch (Exception $e) { + $transaction->rollback(); TLog::error("Erro ao atualizar status da matrícula", ["Exception" => $e]); }