Fix transaction handling

parent a6c5526a
...@@ -120,7 +120,6 @@ class Distribution extends ControllerBase ...@@ -120,7 +120,6 @@ class Distribution extends ControllerBase
} }
} }
$transaction = $this->connection->startTransaction(); $transaction = $this->connection->startTransaction();
try { try {
...@@ -142,7 +141,7 @@ class Distribution extends ControllerBase ...@@ -142,7 +141,7 @@ class Distribution extends ControllerBase
while ($this->choice_id <= $numDistributions) { while ($this->choice_id <= $numDistributions) {
if ($this->choice_id === 1) { if ($this->choice_id === 1) {
// υπολογισμός πλήθους non-finalized δηλώσεων για να καθοριστεί ο αριθμός των fetches που θα κάνουμε με συγκεκριμένο sizeOfBlock // υπολογισμός πλήθους για να καθοριστεί ο αριθμός των fetches που θα κάνουμε με συγκεκριμένο sizeOfBlock
$sCon = $this->connection->select('epal_student', 'eStudent') $sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id')); ->fields('eStudent', array('id'));
$numData = $sCon->countQuery()->execute()->fetchField(); $numData = $sCon->countQuery()->execute()->fetchField();
...@@ -276,8 +275,6 @@ class Distribution extends ControllerBase ...@@ -276,8 +275,6 @@ class Distribution extends ControllerBase
$epal_dist_id = -1; $epal_dist_id = -1;
$specialization_id = -1; $specialization_id = -1;
$transaction = $this->connection->startTransaction(); // TODO CHECK
try { try {
foreach ($epalStudents as $epalStudent) { foreach ($epalStudents as $epalStudent) {
//print_r("<br>ΚΑΤΑΝΟΜΗ ΜΑΘΗΤΩΝ ΝΟ: " . $choice_id); //print_r("<br>ΚΑΤΑΝΟΜΗ ΜΑΘΗΤΩΝ ΝΟ: " . $choice_id);
...@@ -318,12 +315,11 @@ class Distribution extends ControllerBase ...@@ -318,12 +315,11 @@ class Distribution extends ControllerBase
$specialization_id = -1; $specialization_id = -1;
} }
$timestamp = strtotime(date("Y-m-d")); $timestamp = strtotime(date("Y-m-d"));
$this->connection->insert('epal_student_class')->fields( $this->connection->insert('epal_student_class')->fields(
array('id' => $this->globalCounterId++, array(
'id' => $this->globalCounterId++,
'uuid' => \Drupal::service('uuid')->generate(), 'uuid' => \Drupal::service('uuid')->generate(),
'langcode' => $this->language, 'langcode' => $this->language,
'user_id' => $this->currentuser, 'user_id' => $this->currentuser,
...@@ -338,13 +334,13 @@ class Distribution extends ControllerBase ...@@ -338,13 +334,13 @@ class Distribution extends ControllerBase
'second_period' => $epalStudent->second_period, 'second_period' => $epalStudent->second_period,
'status' => 1, 'status' => 1,
'created' => $timestamp, 'created' => $timestamp,
'changed' => $timestamp,) 'changed' => $timestamp
)
)->execute(); )->execute();
} //end if } //end if
} //foreach } //foreach
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
$transaction->rollback();
return self::ERROR_DB; return self::ERROR_DB;
} }
...@@ -354,9 +350,6 @@ class Distribution extends ControllerBase ...@@ -354,9 +350,6 @@ class Distribution extends ControllerBase
public function retrieveCapacityLimitUp($className) public function retrieveCapacityLimitUp($className)
{ {
$transaction = $this->connection->startTransaction();
try { try {
$clCon = $this->connection->select('epal_class_limits', 'classLimits') $clCon = $this->connection->select('epal_class_limits', 'classLimits')
->fields('classLimits', array('limit_up')) ->fields('classLimits', array('limit_up'))
...@@ -365,7 +358,6 @@ class Distribution extends ControllerBase ...@@ -365,7 +358,6 @@ class Distribution extends ControllerBase
$row = reset($results); $row = reset($results);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
$transaction->rollback();
return self::ERROR_DB; return self::ERROR_DB;
} }
...@@ -382,8 +374,6 @@ class Distribution extends ControllerBase ...@@ -382,8 +374,6 @@ class Distribution extends ControllerBase
$capacity = 0; $capacity = 0;
} }
$transaction = $this->connection->startTransaction();
try { try {
$clCon = $this->connection->select('epal_student_class', 'studentClass') $clCon = $this->connection->select('epal_student_class', 'studentClass')
->fields('studentClass', array('epal_id', 'student_id', 'points', 'currentepal', 'currentclass', 'specialization_id')) ->fields('studentClass', array('epal_id', 'student_id', 'points', 'currentepal', 'currentclass', 'specialization_id'))
...@@ -412,7 +402,6 @@ class Distribution extends ControllerBase ...@@ -412,7 +402,6 @@ class Distribution extends ControllerBase
} // end try } // end try
catch (\Exception $e) { catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
$transaction->rollback();
return self::ERROR_DB; return self::ERROR_DB;
} }
...@@ -479,14 +468,14 @@ class Distribution extends ControllerBase ...@@ -479,14 +468,14 @@ class Distribution extends ControllerBase
array_push($this->pendingStudents, $student->student_id); array_push($this->pendingStudents, $student->student_id);
try { try {
$this->connection->delete('epal_student_class') $this->connection->delete('epal_student_class')
->condition('student_id', $student->student_id) ->condition('student_id', $student->student_id)
->execute(); ->execute();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
$transaction->rollback(); $transaction->rollback();
return $this->respondWithStatus([ return $this->respondWithStatus([
"message" => t("An unexpected problem occured during DELETE proccess in makeSelectionOfStudents Method of Distribution") "message" => t("An unexpected problem occured during DELETE proccess in makeSelectionOfStudents Method of Distribution")
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
} }
} else { } else {
if ($this->choice_id !== 1) { if ($this->choice_id !== 1) {
...@@ -498,8 +487,8 @@ class Distribution extends ControllerBase ...@@ -498,8 +487,8 @@ class Distribution extends ControllerBase
} }
return $this->respondWithStatus([ return $this->respondWithStatus([
"message" => t("makeSelectionOfStudents Method of Distribution has made successfully") "message" => t("makeSelectionOfStudents Method of Distribution has made successfully")
], Response::HTTP_OK); ], Response::HTTP_OK);
} }
...@@ -520,7 +509,6 @@ class Distribution extends ControllerBase ...@@ -520,7 +509,6 @@ class Distribution extends ControllerBase
->execute(); ->execute();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
$transaction->rollback();
return self::ERROR_DB; return self::ERROR_DB;
} }
} }
...@@ -544,8 +532,6 @@ class Distribution extends ControllerBase ...@@ -544,8 +532,6 @@ class Distribution extends ControllerBase
$newlimit = $limit - $cnt; $newlimit = $limit - $cnt;
//print_r("<br>ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ:" . $limit); //print_r("<br>ΑΝΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ:" . $limit);
$transaction = $this->connection->startTransaction();
//Αν δεν απέμειναν θέσεις (δηλαδή αν η χωρητικότητα είναι μικρότερη ή ίση από το πλήθος μαθητών που ήδη φοιτούν στο σχολείο) //Αν δεν απέμειναν θέσεις (δηλαδή αν η χωρητικότητα είναι μικρότερη ή ίση από το πλήθος μαθητών που ήδη φοιτούν στο σχολείο)
//τότε διέγραψέ τους από τον προσωρινό πίνακα αποτελεσμάτων και βάλε τους στον στον πίνακα εκκρεμοτήτων //τότε διέγραψέ τους από τον προσωρινό πίνακα αποτελεσμάτων και βάλε τους στον στον πίνακα εκκρεμοτήτων
...@@ -560,7 +546,6 @@ class Distribution extends ControllerBase ...@@ -560,7 +546,6 @@ class Distribution extends ControllerBase
->execute(); ->execute();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
$transaction->rollback();
return self::ERROR_DB; return self::ERROR_DB;
} }
} // endif new limit } // endif new limit
...@@ -575,39 +560,25 @@ class Distribution extends ControllerBase ...@@ -575,39 +560,25 @@ class Distribution extends ControllerBase
return self::SUCCESS; return self::SUCCESS;
} }
public function calculatePoints()
{
return rand(0, 20);
}
private function respondWithStatus($arr, $s) private function respondWithStatus($arr, $s)
{ {
$res = new JsonResponse($arr); $res = new JsonResponse($arr);
$res->setStatusCode($s); $res->setStatusCode($s);
return $res; return $res;
} }
private function initializeResults() private function initializeResults()
{ {
//initialize/empty epal_student_class if there are already data in it!
//initialize/empty epal_student_class if there are already data in it!
try { try {
$this->connection->delete('epal_student_class')->execute(); $this->connection->delete('epal_student_class')->execute();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
return self::ERROR_DB; return self::ERROR_DB;
} }
return self::SUCCESS;
}
return self::SUCCESS;
}
private function findSmallClasses() private function findSmallClasses()
{ {
...@@ -628,9 +599,6 @@ class Distribution extends ControllerBase ...@@ -628,9 +599,6 @@ class Distribution extends ControllerBase
} }
} }
//print_r("<br>");
// Β' τάξη // Β' τάξη
$sCon = $this->connection->select('eepal_sectors_in_epal_field_data', 'eSchool') $sCon = $this->connection->select('eepal_sectors_in_epal_field_data', 'eSchool')
->fields('eSchool', array('epal_id', 'sector_id')) ->fields('eSchool', array('epal_id', 'sector_id'))
...@@ -638,12 +606,10 @@ class Distribution extends ControllerBase ...@@ -638,12 +606,10 @@ class Distribution extends ControllerBase
$eepalSectorsInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $eepalSectorsInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSectorsInEpal as $eepalSecInEp) { foreach ($eepalSectorsInEpal as $eepalSecInEp) {
if ($this->isSmallClass($eepalSchool->id, "2", $eepalSecInEp->sector_id, $eepalSchool->metathesis_region) === self::SMALL_CLASS) { if ($this->isSmallClass($eepalSchool->id, "2", $eepalSecInEp->sector_id, $eepalSchool->metathesis_region) === self::SMALL_CLASS) {
//print_r("<br> ΚΛΗΣΗ markStudentsInSmallClass: SCHOOL_ID: " . $eepalSchool->id . " CLASSID: " . "2 " . "SECTOR/COURSE ID: " . $eepalSecInEp->sector_id);
if ($this->markStudentsInSmallClass($eepalSchool->id, "2", $eepalSecInEp->sector_id) === self::ERROR_DB) { if ($this->markStudentsInSmallClass($eepalSchool->id, "2", $eepalSecInEp->sector_id) === self::ERROR_DB) {
return self::ERROR_DB; return self::ERROR_DB;
} }
} }
//print_r("<br>");
} }
// Γ' τάξη // Γ' τάξη
...@@ -653,12 +619,10 @@ class Distribution extends ControllerBase ...@@ -653,12 +619,10 @@ class Distribution extends ControllerBase
$eepalSpecialtiesInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $eepalSpecialtiesInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) { foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
if ($this->isSmallClass($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id, $eepalSchool->metathesis_region) === self::SMALL_CLASS) { if ($this->isSmallClass($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id, $eepalSchool->metathesis_region) === self::SMALL_CLASS) {
//print_r("<br> ΚΛΗΣΗ markStudentsInSmallClass: SCHOOL_ID: " . $eepalSchool->id . " CLASSID: " . "3 " . "SECTOR/COURSE ID: " . $eepalSpecialInEp->specialty_id);
if ($this->markStudentsInSmallClass($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id) === self::ERROR_DB) { if ($this->markStudentsInSmallClass($eepalSchool->id, "3", $eepalSpecialInEp->specialty_id) === self::ERROR_DB) {
return self::ERROR_DB; return self::ERROR_DB;
} }
} }
//print_r("<br>");
} }
// Δ' τάξη // Δ' τάξη
...@@ -669,14 +633,12 @@ class Distribution extends ControllerBase ...@@ -669,14 +633,12 @@ class Distribution extends ControllerBase
$eepalSpecialtiesInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $eepalSpecialtiesInEpal = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) { foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
if ($this->isSmallClass($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id, $eepalSchool->metathesis_region) === self::SMALL_CLASS) { if ($this->isSmallClass($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id, $eepalSchool->metathesis_region) === self::SMALL_CLASS) {
//print_r("<br> ΚΛΗΣΗ markStudentsInSmallClass: SCHOOL_ID: " . $eepalSchool->id . " CLASSID: " . "4 " . "SECTOR/COURSE ID: " . $eepalSpecialInEp->specialty_id);
if ($this->markStudentsInSmallClass($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id) === self::ERROR_DB) { if ($this->markStudentsInSmallClass($eepalSchool->id, "4", $eepalSpecialInEp->specialty_id) === self::ERROR_DB) {
return self::ERROR_DB; return self::ERROR_DB;
} }
} }
//print_r("<br>");
} }
} //end if ΕΣΠΕΡΙΝΟ } //end if ΕΣΠΕΡΙΝΟ
} //end for each school/department } //end for each school/department
return self::SUCCESS; return self::SUCCESS;
...@@ -686,10 +648,7 @@ class Distribution extends ControllerBase ...@@ -686,10 +648,7 @@ class Distribution extends ControllerBase
private function isSmallClass($schoolId, $classId, $sectorOrcourseId, $regionId) private function isSmallClass($schoolId, $classId, $sectorOrcourseId, $regionId)
{ {
//print_r("<br> ΚΛΗΣΗ isSmallClass: SCHOOL_ID: " . $schoolId . " CLASSID: " . $classId . "SECTOR/COURSE ID: " . $sectorOrcourseId . "ΠΕΡΙΟΧΗ ΜΕΤΑΘΕΣΗΣ: " . $regionId);
$limitDown = $this->retrieveLimitDown($classId, $regionId); $limitDown = $this->retrieveLimitDown($classId, $regionId);
//print_r("<br> ΚΑΤΩΤΑΤΟ ΟΡΙΟ ΜΑΘΗΤΩΝ: " . $limitDown);
if ($limitDown === self::NO_CLASS_LIMIT_DOWN) { if ($limitDown === self::NO_CLASS_LIMIT_DOWN) {
return self::NO_CLASS_LIMIT_DOWN; return self::NO_CLASS_LIMIT_DOWN;
...@@ -698,13 +657,12 @@ class Distribution extends ControllerBase ...@@ -698,13 +657,12 @@ class Distribution extends ControllerBase
} }
$numStudents = $this->countStudents($schoolId, $classId, $sectorOrcourseId); $numStudents = $this->countStudents($schoolId, $classId, $sectorOrcourseId);
//print_r("<br> ΑΡΙΘΜΟΣ ΜΑΘΗΤΩΝ: " . $numStudents);
if ($numStudents === self::ERROR_DB) { if ($numStudents === self::ERROR_DB) {
return self::ERROR_DB; return self::ERROR_DB;
} }
//Αν $numStudents == 0, γύρισε fasle, ώστε να μη γίνει περιττή κλήση στην markStudentsInSmallClass //Αν $numStudents == 0, γύρισε false, ώστε να μη γίνει περιττή κλήση στην markStudentsInSmallClass
if (($numStudents < $limitDown) && ($numStudents > 0)) { if (($numStudents < $limitDown) && ($numStudents > 0)) {
return self::SMALL_CLASS; return self::SMALL_CLASS;
} else { } else {
...@@ -732,11 +690,10 @@ class Distribution extends ControllerBase ...@@ -732,11 +690,10 @@ class Distribution extends ControllerBase
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
return self::ERROR_DB; return self::ERROR_DB;
} }
} //end function } //end function
private function countStudents($schoolId, $classId, $sectorOrcourseId) private function countStudents($schoolId, $classId, $sectorOrcourseId)
{ {
try { try {
$sCon = $this->connection->select('epal_student_class', 'eStudent') $sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('id')) ->fields('eStudent', array('id'))
...@@ -752,12 +709,9 @@ class Distribution extends ControllerBase ...@@ -752,12 +709,9 @@ class Distribution extends ControllerBase
private function markStudentsInSmallClass($schoolId, $classId, $sectorOrcourseId) private function markStudentsInSmallClass($schoolId, $classId, $sectorOrcourseId)
{ {
try { try {
$query = $this->connection->update('epal_student_class'); $query = $this->connection->update('epal_student_class');
$query->fields([ $query->fields(['finalized' => 0]);
'finalized' => 0,
]);
$query->condition('epal_id', $schoolId); $query->condition('epal_id', $schoolId);
$query->condition('currentclass', $classId); $query->condition('currentclass', $classId);
if ($sectorOrcourseId !== "-1") { if ($sectorOrcourseId !== "-1") {
...@@ -771,11 +725,8 @@ class Distribution extends ControllerBase ...@@ -771,11 +725,8 @@ class Distribution extends ControllerBase
return self::SUCCESS; return self::SUCCESS;
} }
public function locateSecondPeriodStudents(Request $request) public function locateSecondPeriodStudents(Request $request)
{ {
//POST method is checked //POST method is checked
if (!$request->isMethod('POST')) { if (!$request->isMethod('POST')) {
return $this->respondWithStatus([ return $this->respondWithStatus([
...@@ -800,7 +751,6 @@ class Distribution extends ControllerBase ...@@ -800,7 +751,6 @@ class Distribution extends ControllerBase
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
//check where distribution can be done now //check where distribution can be done now
$secondPeriodEnabled = "0"; $secondPeriodEnabled = "0";
...@@ -820,8 +770,11 @@ class Distribution extends ControllerBase ...@@ -820,8 +770,11 @@ class Distribution extends ControllerBase
], Response::HTTP_FORBIDDEN); ], Response::HTTP_FORBIDDEN);
} }
$transaction = $this->connection->startTransaction();
try { try {
if ($this->initializeResultsInSecondPeriod() === self::ERROR_DB) { if ($this->initializeResultsInSecondPeriod() === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([ return $this->respondWithStatus([
"message" => t("Unexpected Error in initializeResultsInSecondPeriod function") "message" => t("Unexpected Error in initializeResultsInSecondPeriod function")
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
...@@ -835,17 +788,18 @@ class Distribution extends ControllerBase ...@@ -835,17 +788,18 @@ class Distribution extends ControllerBase
//τοποθέτηση όλων των μαθητών Β' περιόδου στην πρώτη τους προτίμηση' //τοποθέτηση όλων των μαθητών Β' περιόδου στην πρώτη τους προτίμηση'
$this->globalCounterId = $this->retrieveLastStudentId() + 1; $this->globalCounterId = $this->retrieveLastStudentId() + 1;
if ($this->locateStudent(1, $epalStudents) === self::ERROR_DB) { if ($this->locateStudent(1, $epalStudents) === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([ return $this->respondWithStatus([
"message" => t("Unexpected Error in locateStudent function after calling locateSecondPeriodStudents method"), "message" => t("Unexpected Error in locateStudent function after calling locateSecondPeriodStudents method"),
"numOfDeletions" => $num "numOfDeletions" => $num
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
} }
//επαναϋπολογισμός όλων των ολιγομελών τμημάτων (Προσοχή: αφορά ΟΛΟΥΣ τους μαθητές - κανονικής και Β΄ περιόδου) //επαναϋπολογισμός όλων των ολιγομελών τμημάτων (Προσοχή: αφορά ΟΛΟΥΣ τους μαθητές - κανονικής και Β΄ περιόδου)
//αρχικοποίηση flag finalize σε 1 για όλους //αρχικοποίηση flag finalize σε 1 για όλους
if ($this->setFinalize() === self::ERROR_DB) { if ($this->setFinalize() === self::ERROR_DB) {
$transaction->rollback();
return $this->respondWithStatus([ return $this->respondWithStatus([
"message" => t("Unexpected Error in setFinalize function AFTER locateSecondPeriodStudents!") "message" => t("Unexpected Error in setFinalize function AFTER locateSecondPeriodStudents!")
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
...@@ -853,19 +807,22 @@ class Distribution extends ControllerBase ...@@ -853,19 +807,22 @@ class Distribution extends ControllerBase
//εύρεση ολιγομελών και καταχώρηση μαθητών σε αυτά με κατάλληλη ένδειξη (finalize=0) //εύρεση ολιγομελών και καταχώρηση μαθητών σε αυτά με κατάλληλη ένδειξη (finalize=0)
if ($this->findSmallClasses() === self::ERROR_DB) { if ($this->findSmallClasses() === self::ERROR_DB) {
//αν αποτύχει, δεν γίνεται rollback. --> Λύση: διαγρα΄φή των όποιων αποτελεσμάτων //αν αποτύχει, δεν γίνεται rollback. --> Λύση: διαγρα΄φή των όποιων αποτελεσμάτων
if ($this->initializeResultsInSecondPeriod() === self::ERROR_DB) { // if ($this->initializeResultsInSecondPeriod() === self::ERROR_DB) {
return $this->respondWithStatus([ // $transaction->rollback();
"message" => t("Unexpected Error in initializeResults function AFTER findSmallClasses call Function") // return $this->respondWithStatus([
], Response::HTTP_INTERNAL_SERVER_ERROR); // "message" => t("Unexpected Error in initializeResults function AFTER findSmallClasses call Function")
} // ], Response::HTTP_INTERNAL_SERVER_ERROR);
// }
$transaction->rollback();
return $this->respondWithStatus([ return $this->respondWithStatus([
"message" => t("Unexpected Error in findSmallClasses function AFTER locateSecondPeriodStudents!") "message" => t("Unexpected Error in findSmallClasses function AFTER locateSecondPeriodStudents!")
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
$transaction->rollback();
return $this->respondWithStatus([ return $this->respondWithStatus([
"message" => t("An unexpected problem occured in locateSecondPeriodStudents Method") "message" => t("An unexpected problem occured in locateSecondPeriodStudents Method")
], Response::HTTP_INTERNAL_SERVER_ERROR); ], Response::HTTP_INTERNAL_SERVER_ERROR);
...@@ -878,7 +835,6 @@ class Distribution extends ControllerBase ...@@ -878,7 +835,6 @@ class Distribution extends ControllerBase
private function setFinalize() private function setFinalize()
{ {
try { try {
$query = $this->connection->update('epal_student_class'); $query = $this->connection->update('epal_student_class');
$query->fields([ $query->fields([
...@@ -892,14 +848,11 @@ class Distribution extends ControllerBase ...@@ -892,14 +848,11 @@ class Distribution extends ControllerBase
return self::SUCCESS; return self::SUCCESS;
} }
private function initializeResultsInSecondPeriod() private function initializeResultsInSecondPeriod()
{ {
//initialize/empty epal_student_class if there are already data in it!
//initialize/empty epal_student_class if there are already data in it!
try { try {
//$this->connection->delete('epal_student_class')->execute(); //$this->connection->delete('epal_student_class')->execute();
$con = $this->connection->prepare("delete from epal_student_class where second_period = 1 "); $con = $this->connection->prepare("delete from epal_student_class where second_period = 1 ");
$con->execute(); $con->execute();
//$num = $con->rowCount(); //$num = $con->rowCount();
...@@ -907,20 +860,21 @@ class Distribution extends ControllerBase ...@@ -907,20 +860,21 @@ class Distribution extends ControllerBase
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
return self::ERROR_DB; return self::ERROR_DB;
} }
return self::SUCCESS;
return self::SUCCESS;
} }
private function retrieveLastStudentId() private function retrieveLastStudentId()
{ {
$sCon = $this->connection->select('epal_student', 'eStudent') $sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id')); ->fields('eStudent', array('id'));
$sCon->orderBy('eStudent.id', 'desc'); $sCon->orderBy('eStudent.id', 'desc');
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ); $epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
if ($epalStudents) { if ($epalStudents) {
$epalStrudent = reset($epalStudents); $epalStrudent = reset($epalStudents);
return $epalStrudent->id; return $epalStrudent->id;
} }