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]); }