mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
FIX [duplicate] adding test and handlers to handle fusion of doublons with special cases - after codewithme session
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Actions\Remove\Handler;
|
||||
|
||||
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class PersonMoveHouseholdHandler implements PersonMoveSqlHandlerInterface
|
||||
{
|
||||
public function supports(string $className, string $field): bool
|
||||
{
|
||||
return $className === HouseholdMember::class;
|
||||
}
|
||||
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
{
|
||||
$sqlInsert = sprintf(<<<SQL
|
||||
INSERT INTO chill_person_household_members (id, person_id, household_id, startdate, enddate, comment, sharedhousehold, position_id, holder)
|
||||
SELECT nextval('chill_person_household_members_id_seq'), %d, household_id, startdate, enddate, comment, sharedhousehold, position_id, holder
|
||||
FROM chill_person_household_members cphm
|
||||
WHERE person_id = %d
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM chill_person_household_members cphm_inner
|
||||
WHERE
|
||||
person_id = %d
|
||||
AND daterange(cphm.startdate, cphm.enddate) && daterange(cphm_inner.startdate, cphm_inner.enddate)
|
||||
)
|
||||
SQL, $to->getId(), $from->getId(), $to->getId());
|
||||
|
||||
$deleteSql = sprintf(<<<SQL
|
||||
DELETE FROM chill_person_household_members WHERE person_id = %d
|
||||
SQL, $from->getId());
|
||||
|
||||
return [$sqlInsert, $deleteSql];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user