mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
WIP started center_history query for duplicate person merge
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace Chill\PersonBundle\Actions\Remove\Handler;
|
||||
|
||||
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class PersonMoveAccompanyingPeriodParticipationHandler
|
||||
class PersonMoveAccompanyingPeriodParticipationHandler implements PersonMoveSqlHandlerInterface
|
||||
{
|
||||
public function supports(string $className, string $field): bool
|
||||
{
|
||||
@@ -13,6 +15,7 @@ class PersonMoveAccompanyingPeriodParticipationHandler
|
||||
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
{
|
||||
var_dump(__METHOD__);
|
||||
$insertSql = sprintf(<<<SQL
|
||||
INSERT INTO chill_person_accompanying_period_participation (person_id, accompanyingperiod_id, id, startdate, enddate)
|
||||
SELECT %d, accompanyingperiod_id, nextval('chill_person_person_center_history_id_seq'), startdate, enddate
|
||||
@@ -22,7 +25,7 @@ class PersonMoveAccompanyingPeriodParticipationHandler
|
||||
SELECT 1 FROM chill_person_accompanying_period_participation cpapp2
|
||||
WHERE
|
||||
person_id = %d
|
||||
AND daterange(cpapp.startdate, cpapp.enddate) && daterange(cpapp2.startdate, cpapp2.enddate)
|
||||
AND (cpapp.startdate, COALESCE(cpapp.enddate, 'infinity'::date)) OVERLAPS (cpapp2.startdate, COALESCE(cpapp2.enddate, 'infinity'::date))
|
||||
)
|
||||
SQL, $to->getId(), $from->getId(), $to->getId());
|
||||
|
||||
@@ -30,6 +33,6 @@ class PersonMoveAccompanyingPeriodParticipationHandler
|
||||
DELETE FROM chill_person_accompanying_period_participation WHERE person_id = %d
|
||||
SQL, $from->getId());
|
||||
|
||||
return [$sqlInsert, $deleteSql];
|
||||
return [$insertSql, $deleteSql];
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Actions\Remove\Handler;
|
||||
|
||||
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
{
|
||||
public function supports(string $className, string $field): bool
|
||||
{
|
||||
return $className === Person\PersonCenterHistory::class;
|
||||
}
|
||||
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
{
|
||||
$insertSql = sprintf(<<<SQL
|
||||
INSERT INTO chill_person_person_center_history (id, person_id, center_id, startdate, enddate, createdat, updatedat, createdby_id, updatedby_id)
|
||||
SELECT nextval('chill_person_person_center_history_id_seq'), %d, center_id, startdate, enddate, createdat, updatedat, createdby_id, updatedby_id
|
||||
FROM chill_person_person_center_history cppch
|
||||
WHERE person_id = %d
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM chill_person_person_center_history cppch2
|
||||
WHERE
|
||||
person_id = %d
|
||||
AND daterange(cppch.startdate, cppch.enddate) && daterange(cppch2.startdate, cppch2.enddate)
|
||||
)
|
||||
SQL, $to->getId(), $from->getId(), $to->getId());
|
||||
|
||||
$updateSql = sprintf(<<<SQL
|
||||
UPDATE chill_person_person_center_history cppch
|
||||
SET startdate =
|
||||
WHERE person_id = %d
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM chill_person_person_center_history cppch2
|
||||
WHERE
|
||||
person_id = %d
|
||||
AND daterange(cppch.startdate, cppch.enddate) && daterange(cppch2.startdate, cppch2.enddate)
|
||||
)
|
||||
|
||||
|
||||
SQL, $to->getId());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user