mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
[centerHistory] add conditions to be sure at least one center history exists per person
This commit is contained in:
@@ -20,10 +20,11 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
{
|
||||
$sqlStatements = [];
|
||||
$oldestDateA = null;
|
||||
$oldestDateB = null;
|
||||
|
||||
$centerHistoriesA = $this->em->getRepository(Person\PersonCenterHistory::class)->findBy(['person' => $from->getId()]);
|
||||
// $centerHistoriesA = $from->getCenterHistory()->toArray();
|
||||
// var_dump($centerHistoriesA);
|
||||
$datesArrayA = array_map(fn($centerHistory) => $centerHistory->getStartDate(), $centerHistoriesA);
|
||||
if (!count($datesArrayA) === 0) {
|
||||
$oldestDateA = min($datesArrayA);
|
||||
@@ -31,7 +32,6 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
|
||||
$centerHistoriesB = $this->em->getRepository(Person\PersonCenterHistory::class)->findBy(['person' => $to->getId()]);
|
||||
// $centerHistoriesB = $to->getCenterHistory()->toArray();
|
||||
// var_dump($centerHistoriesB);
|
||||
$datesArrayB = array_map(fn($centerHistory) => $centerHistory->getStartDate(), $centerHistoriesB);
|
||||
|
||||
if (!count($datesArrayB) === 0) {
|
||||
@@ -45,12 +45,13 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
|
||||
$sqlStatements = [$sqlDelete];
|
||||
|
||||
if ($oldestDateA <= $oldestDateB) {
|
||||
if ((null !== $oldestDateA && null !== $oldestDateB) && $oldestDateA <= $oldestDateB) {
|
||||
$sqlInsert = sprintf("update chill_person_person_center_history set startDate = '%s'::date WHERE id = %d", $oldestDateA->format('Y-m-d'), $oldestCenterHistoryB->getId());
|
||||
|
||||
$sqlStatements = [$sqlInsert, $sqlDelete];
|
||||
}
|
||||
|
||||
var_dump($sqlStatements);
|
||||
return $sqlStatements;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user