From 39bb06b99134ef4dc3d66ad56b8202d531d5b1a7 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 30 Oct 2023 11:53:41 +0100 Subject: [PATCH] Adjust query to transfer relationship from one person to another depending on whether original person was in the to or from position --- .../Remove/Handler/PersonMoveRelationHandler.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php index d4e9be2a2..1ba1f6766 100644 --- a/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php +++ b/src/Bundle/ChillPersonBundle/Actions/Remove/Handler/PersonMoveRelationHandler.php @@ -26,7 +26,15 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface { $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 +43,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()),