Skip to content

Commit

Permalink
Fix/removing transactions (#899)
Browse files Browse the repository at this point in the history
* remove courseplanController transactions

* remove sagres transaction

* Retirando as transactions de grades

---------

Co-authored-by: AnotherOne07 <93009549+AnotherOne07@users.noreply.github.com>
Co-authored-by: gabriel-IPTI <ti.gabriel@ipti.org.br>
Co-authored-by: TI GUSTAVO <ti.gustavo@thp.org.br>
  • Loading branch information
4 people authored Dec 19, 2024
1 parent aeee2fd commit b0dfa26
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 42 deletions.
6 changes: 0 additions & 6 deletions app/controllers/GradesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ 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) {
Expand Down Expand Up @@ -590,12 +589,10 @@ 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);
}

Expand Down Expand Up @@ -629,7 +626,6 @@ public function actionGetGrades()

public function actionCalculateFinalMedia()
{
$transaction = Yii::app()->db->beginTransaction();
try {
$classroomId = Yii::app()->request->getPost("classroom");
$stage = Yii::app()->request->getPost("stage");
Expand Down Expand Up @@ -673,9 +669,7 @@ public function actionCalculateFinalMedia()
}

}
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
TLog::error("Erro ao atualizar status da matrícula", ["Exception" => $e]);
}

Expand Down
18 changes: 9 additions & 9 deletions app/modules/courseplan/controllers/CourseplanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ public function actionGetAbilitiesNextStructure()
*/
public function actionSave($id = null)
{
// $transaction = Yii::app()->db->beginTransaction();
$request = Yii::app()->request->getPost("CoursePlan");
$transaction = Yii::app()->db->beginTransaction();
try {
if ($id !== null) {
$coursePlan = CoursePlan::model()->findByPk($id);
Expand Down Expand Up @@ -343,32 +343,32 @@ public function actionSave($id = null)
CourseClass::model()->deleteAll("course_plan_fk = :course_plan_fk and id not in ( '" . implode("', '", $courseClassIds) . "' )", [":course_plan_fk" => $coursePlan->id]);
TLog::info("Todas as aulas não inclusas na atualização foram deletadas com sucesso.", ['coursePlanId' => $coursePlan->id, 'CourseClassesIds' => $courseClassIds]);
}
$transaction->commit();
// $transaction->commit();
header('HTTP/1.1 200 OK');
Log::model()->saveAction("courseplan", $id, $logSituation, $coursePlan->name);
Yii::app()->user->setFlash('success', Yii::t('default', 'Plano de Curso salvo com sucesso!'));
$this->redirect(array('index'));
} catch (Exception $e) {
TLog::error('Ocorreu um erro durante a transação de salvar um plano de aula', $e);
$transaction->rollback();
// $transaction->rollback();
throw new Exception($e->getMessage(), 500, $e);
}
}

public function actionAddResources()
{
$transaction = Yii::app()->db->beginTransaction();
// $transaction = Yii::app()->db->beginTransaction();
try {
$resources = Yii::app()->request->getPost('resources');
foreach ($resources as $resource) {
$newResource = new CourseClassResources();
$newResource->name = $resource;
$newResource->save();
}
$transaction->commit();
// $transaction->commit();
header('HTTP/1.1 200 OK');
} catch (Exception $e) {
$transaction->rollback();
// $transaction->rollback();
throw new CHttpException(500, $e->getMessage());
}
}
Expand Down Expand Up @@ -428,13 +428,13 @@ public function actionDeletePlan($id)
}
if (!$isUsed) {
TLog::info("Plano de aula não está sendo utilizado", ["id" => $id]);
$transaction = Yii::app()->db->beginTransaction();
// $transaction = Yii::app()->db->beginTransaction();
try {
$coursePlan->delete();
$transaction->commit();
// $transaction->commit();
} catch (Exception $e) {
TLog::error("Error ao excluir plano de aula", ["id" => $id, "error" => $e->getMessage()]);
$transaction->rollback();
// $transaction->rollback();
throw new Exception($e->getMessage(), 500, $e);
}

Expand Down
6 changes: 3 additions & 3 deletions app/modules/sagres/models/SagresConsultModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SagresConsultModel
public function cleanInconsistences()
{
$connection = Yii::app()->db;
$transaction = $connection->beginTransaction();
// $transaction = $connection->beginTransaction();

try {
$deleteQuery = "DELETE FROM inconsistency_sagres";
Expand All @@ -48,9 +48,9 @@ public function cleanInconsistences()
$resetQuery = "ALTER TABLE inconsistency_sagres AUTO_INCREMENT = 1";
$connection->createCommand($resetQuery)->execute();

$transaction->commit();
// $transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
// $transaction->rollback();
throw $e;
}
}
Expand Down
48 changes: 24 additions & 24 deletions app/modules/sagres/models/SagresValidations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SagresValidations
public function __construct()
{
$connection = Yii::app()->db;
$transaction = $connection->beginTransaction();
// $transaction = $connection->beginTransaction();

try {
$deleteQuery = "DELETE FROM inconsistency_sagres";
Expand All @@ -16,9 +16,9 @@ public function __construct()
$resetQuery = "ALTER TABLE inconsistency_sagres AUTO_INCREMENT = 1";
$connection->createCommand($resetQuery)->execute();

$transaction->commit();
// $transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
// $transaction->rollback();
throw $e;
}
}
Expand All @@ -39,7 +39,7 @@ public function validator($education, $finalClass)
}

$inconsistencyList = array_merge($inconsistencyList, $this->validatorProfessionals($professionals));

return $inconsistencyList;
}

Expand All @@ -56,7 +56,7 @@ public function validatorManagementUnit($managementUnit)
"action" => 'POR FAVOR, INFORME O CÓDIGO DE IDENTIFICAÇÃO DA UNIDADE GESTORA'
];
}

if (empty($managementUnit->getNomeUnidGestora())) {
$inconsistencies[] = [
"enrollment" => 'UNIDADE GESTORA: ' . $managementUnit->getNomeUnidGestora(),
Expand All @@ -65,7 +65,7 @@ public function validatorManagementUnit($managementUnit)
"action" => 'POR FAVOR, INFORME UM NOME PARA A UNIDADE GESTORA'
];
}

if (empty($managementUnit->getCpfResponsavel())) {
$inconsistencies[] = [
"enrollment" => 'UNIDADE GESTORA: ' . $managementUnit->getNomeUnidGestora(),
Expand All @@ -74,7 +74,7 @@ public function validatorManagementUnit($managementUnit)
"action" => 'POR FAVOR, INFORME UM CPF VÁLIDO PARA O RESPONSÁVEL'
];
}

if (empty($managementUnit->getCpfGestor())) {
$inconsistencies[] = [
"enrollment" => 'UNIDADE GESTORA: ' . $managementUnit->getNomeUnidGestora(),
Expand All @@ -83,7 +83,7 @@ public function validatorManagementUnit($managementUnit)
"action" => 'POR FAVOR, INFORME UM CPF VÁLIDO PARA O GESTOR'
];
}

return $inconsistencies;
}

Expand Down Expand Up @@ -123,10 +123,10 @@ public function validatorAttendance($professional)
$inconsistencies = [];
$attendances = $professional->getAtendimento();

foreach ($attendances as $attendance) {
foreach ($attendances as $attendance) {
$dateOfAttendance = intval($attendance->getData()->format("Y"));
$currentDate = date('Y');

if($dateOfAttendance <= ($currentDate - 3)){
$inconsistencies[] = [
"enrollment" => 'ATENDIMENTO',
Expand Down Expand Up @@ -245,7 +245,7 @@ public function validatorMenu($school)
"description" => 'DATA NO FORMATO INVÁLIDO',
"action" => 'ADICIONE UMA DATA NO FORMATO VÁLIDA'
];
}
}
}

return $inconsistencies;
Expand All @@ -260,7 +260,7 @@ public function validatorClass($school, $finalClass)
$schoolId = $school->getIdEscola();

foreach ($classes as $class) {
/*
/*
* [0 : Anual], [1 : 1°], [2 : 2º] Semestre
*/
if (!in_array($class->getPeriodo(), [0, 1, 2])) {
Expand Down Expand Up @@ -350,11 +350,11 @@ public function validationSeries($class, $schoolId)
"action" => 'FORNEÇA UMA DESCRIÇÃO MENOS DETALHADA, CONTENDO ATÉ 50 CARACTERES'
];
}

/* [1, 2, 3, 4]
* 1 - Educação Infantil -->
* 2 - Ensino Fundamental -->
* 3 - Ensino Médio -->
* 3 - Ensino Médio -->
* 4 - Educação de Jovens e Adultos -->
*/
if (!in_array($serie->getModalidade(), [1, 2, 3, 4])) {
Expand All @@ -381,7 +381,7 @@ public function validatorEnrollments($class, $schoolId, $finalClass)
"enrollment" => 'MATRÍCULA',
"school" => $schoolId,
"description" => 'NÃO HÁ MATRÍCULA PARA A TURMA',
"action" => 'ADICIONE UMA MATRÍCULA PARA A TURMA: ' . $class->getDescricao() . ' DA ESCOLA: ' . $schoolId
"action" => 'ADICIONE UMA MATRÍCULA PARA A TURMA: ' . $class->getDescricao() . ' DA ESCOLA: ' . $schoolId
];
}else{
foreach ($enrollments as $enrollment) {
Expand All @@ -393,7 +393,7 @@ public function validatorEnrollments($class, $schoolId, $finalClass)
"action" => 'ADICIONE UMA DATA NO FORMATO VÁLIDO'
];
}

if(!is_int($enrollment->getNumeroFaltas())){
$inconsistencies[] = [
"enrollment" => 'MATRÍCULA',
Expand Down Expand Up @@ -436,7 +436,7 @@ public function validationStudent($student, $schoolId, $class)
];
}
}

if(!$this->validateDate($student->getDataNascimento()->format("Y-m-d"))){
$inconsistencies[] = [
"enrollment" => 'ESTUDANTE',
Expand Down Expand Up @@ -521,7 +521,7 @@ public function validatorSchedules($class, $schoolId)
"action" => 'ADICIONE UM DIA DA SEMANA VÁLIDO PARA A DISCIPLINA'
];
}

if (!is_int($schedule->getDuracao())) {
$inconsistencies[] = [
"enrollment" => 'HORÁRIO',
Expand All @@ -530,7 +530,7 @@ public function validatorSchedules($class, $schoolId)
"action" => 'ADICIONE UMA DURAÇÃO VÁLIDA PARA DISCIPLINA'
];
}

$cpfInstructor = $schedule->getCpfProfessor();
if (!$this->validaCPF($cpfInstructor[0])) {
$inconsistencies[] = [
Expand All @@ -540,7 +540,7 @@ public function validatorSchedules($class, $schoolId)
"action" => 'INFORMAR UM CPF VÁLIDO PARA O PROFESSOR'
];
}

if (strlen($schedule->getDisciplina()) < $strlen) {
$inconsistencies[] = [
"enrollment" => 'HORÁRIO',
Expand All @@ -560,12 +560,12 @@ public function validatorSchedules($class, $schoolId)
}
}
}

return $inconsistencies;
}

function validaCPF($cpf)
{
{
$cpf = preg_replace('/[^0-9]/is', '', $cpf);

if (strlen($cpf) != 11) {
Expand Down Expand Up @@ -593,7 +593,7 @@ function validateDate($date, $format = 'Y-m-d')
$d = DateTime::createFromFormat($format, $date);
if(intval($d->format('Y')) <= 1900)
return false;

return $d && $d->format($format) == $date;
}
}
}

0 comments on commit b0dfa26

Please sign in to comment.