diff --git a/.changes/unreleased/Fixed-20231030-115441.yaml b/.changes/unreleased/Fixed-20231030-115441.yaml new file mode 100644 index 000000000..144658fff --- /dev/null +++ b/.changes/unreleased/Fixed-20231030-115441.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: Fix merging of double person files. Adjustement relationship sql statement +time: 2023-10-30T11:54:41.028058144+01:00 +custom: + Issue: "182" diff --git a/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php index d4e9be2a2..3d64515d3 100644 --- a/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php +++ b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php @@ -24,9 +24,19 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface public function getSqls(string $className, string $field, Person $from, Person $to): array { + /* Insert sql statement taking into account two cases. + One where the person is the fromperson and another where the person is the toperson in the relationship.*/ $insertSql = sprintf(<<<'SQL' INSERT INTO chill_person_relationships (id, relation_id, reverse, createdat, createdby_id, fromperson_id, toperson_id) - SELECT nextval('chill_person_relationships_id_seq'), relation_id, reverse, createdat, createdby_id, fromperson_id, toperson_id + SELECT nextval('chill_person_relationships_id_seq'), relation_id, reverse, createdat, createdby_id, + CASE + WHEN cpr.fromperson_id = %d THEN %d + ELSE cpr.fromperson_id + END as fromperson, + CASE + WHEN cpr.toperson_id = %d THEN %d + ELSE cpr.toperson_id + END as toperson FROM chill_person_relationships cpr WHERE fromperson_id = %d OR toperson_id = %d AND NOT EXISTS ( @@ -35,7 +45,7 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface cpr2.fromperson_id = %d AND cpr2.toperson_id = %d OR cpr2.fromperson_id = %d AND cpr2.toperson_id = %d ); - SQL, $from->getId(), $from->getId(), $to->getId(), $from->getId(), $from->getId(), $to->getId()); + SQL, $from->getId(), $to->getId(), $from->getId(), $to->getId(), $from->getId(), $from->getId(), $to->getId(), $from->getId(), $from->getId(), $to->getId()); $deleteSql = [ sprintf('DELETE FROM chill_person_relationships WHERE fromperson_id = %d', $from->getId()),