diff --git a/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveAccompanyingPeriodParticipationHandler.php b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveAccompanyingPeriodParticipationHandler.php index 83d8f201a..5acd67126 100644 --- a/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveAccompanyingPeriodParticipationHandler.php +++ b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveAccompanyingPeriodParticipationHandler.php @@ -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(<<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]; } } diff --git a/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveCenterHistoryHandler.php b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveCenterHistoryHandler.php new file mode 100644 index 000000000..25767d175 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveCenterHistoryHandler.php @@ -0,0 +1,45 @@ +getId(), $from->getId(), $to->getId()); + + $updateSql = sprintf(<<getId()); + } + +} diff --git a/src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php b/src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php index b0530d6c3..ecf17d3b4 100644 --- a/src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php +++ b/src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php @@ -78,9 +78,9 @@ class PersonMove foreach ($metadata->getAssociationMappings() as $field => $mapping) { - if ($this->personMoveManager->hasHandler($metadata->getName(), $field)) { - $sqls = array_merge($sqls, $this->personMoveManager->getSqls($metadata->getName(), $field, $from, $to)); - continue; + if ($this->personMoveManager->hasHandler($metadata->getName(), $field)) { + $sqls = array_merge($sqls, $this->personMoveManager->getSqls($metadata->getName(), $field, $from, $to)); + continue; } if (in_array($mapping['sourceEntity'], $this->getIgnoredEntities(), true)) { @@ -152,29 +152,28 @@ class PersonMove $tableName = (null !== ($mapping['joinTable']['schema'] ?? null) ? $mapping['joinTable']['schema'] . '.' : '') . $mapping['joinTable']['name']; - $sqlInsert = sprintf( - "INSERT INTO %s (%s, %s) SELECT %d, %s FROM %s WHERE %s = %d ON CONFLICT DO NOTHING", - $tableName, - $mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id - $mapping['joinTable']['joinColumns'][0]['name'], // something_else_id - $to->getId(), - $mapping['joinTable']['joinColumns'][0]['name'], // something_else_id - $tableName, - $mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id - $from->getId() + $sqlInsert = sprintf( + "INSERT INTO %s (%s, %s) SELECT %d, %s FROM %s WHERE %s = %d ON CONFLICT DO NOTHING", + $tableName, + $mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id + $mapping['joinTable']['joinColumns'][0]['name'], // something_else_id + $to->getId(), + $mapping['joinTable']['joinColumns'][0]['name'], // something_else_id + $tableName, + $mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id + $from->getId() + ); - ); - $deleteSql = sprintf( - "DELETE FROM %s WHERE %s = %d", - $tableName, - $mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id - $from->getId() + $deleteSql = sprintf( + "DELETE FROM %s WHERE %s = %d", + $tableName, + $mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id + $from->getId() + ); - ); - - return [ - $sqlInsert, $deleteSql - ]; + return [ + $sqlInsert, $deleteSql + ]; foreach ($mapping['joinTable']['inverseJoinColumns'] as $columns) { $sets[] = sprintf('%s = %d', $columns['name'], $to->getId()); @@ -183,6 +182,7 @@ class PersonMove foreach ($mapping['joinTable']['inverseJoinColumns'] as $columns) { $conditions[] = sprintf('%s = %d', $columns['name'], $from->getId()); } + } elseif (array_key_exists('joinColumns', $mapping)) { $tableName = $this->getTableName($metadata); foreach ($mapping['joinColumns'] as $columns) { @@ -210,7 +210,6 @@ class PersonMove { return [ Person\PersonCenterHistory::class, - AccompanyingPeriodParticipation::class, AccompanyingPeriod\AccompanyingPeriodWork::class, Relationship::class ]; diff --git a/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php b/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php index 1a49783c8..05fc98aa6 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php @@ -59,12 +59,13 @@ class PersonMoveTest extends KernelTestCase { $move = new PersonMove($this->em, $this->personMoveManager, $this->eventDispatcher); $sqls = $move->getSQL($personA, $personB); - //$conn = $this->em->getConnection(); - $this->em->getConnection()->transactional(function (Connection $conn) use ($personA, $personB, $sqls) { + $conn = $this->em->getConnection(); +// $this->em->getConnection()->transactional(function (Connection $conn) use ($personA, $personB, $sqls) { foreach ($sqls as $sql) { +// var_dump($sql); $conn->executeStatement($sql); } - }); +// }); $personA = $this->em->find(Person::class, $personA->getId()); $personB = $this->em->find(Person::class, $personB->getId()); @@ -118,8 +119,6 @@ class PersonMoveTest extends KernelTestCase ->setStartDate(new \DateTimeImmutable('2023-01-01')) ); - - $this->em->persist($personA); $this->em->persist($personB); $this->em->persist($household);