From a9152148f1c86babede42d22668fc658254a1a52 Mon Sep 17 00:00:00 2001 From: Boris Waaub Date: Wed, 25 Mar 2026 11:38:52 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liorer=20la=20gestion=20des=20adresses?= =?UTF-8?q?=20dans=20PersonUpsertHandler=20en=20ajoutant=20des=20v=C3=A9ri?= =?UTF-8?q?fications=20pour=20les=20codes=20postaux=20et=20en=20=C3=A9vita?= =?UTF-8?q?nt=20d'ajouter=20des=20adresses=20nulles.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Upsert/Handler/PersonUpsertHandler.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Actions/Upsert/Handler/PersonUpsertHandler.php b/src/Bundle/ChillPersonBundle/Actions/Upsert/Handler/PersonUpsertHandler.php index ab8be0101..b37a0c453 100644 --- a/src/Bundle/ChillPersonBundle/Actions/Upsert/Handler/PersonUpsertHandler.php +++ b/src/Bundle/ChillPersonBundle/Actions/Upsert/Handler/PersonUpsertHandler.php @@ -54,7 +54,7 @@ readonly class PersonUpsertHandler private ValidatorInterface $validator, ) {} - private function createAddressWithMessage(UpsertMessage $message): Address + private function createAddressWithMessage(UpsertMessage $message): ?Address { $newAddress = new Address(); if (null !== $message->addressStreet) { @@ -65,9 +65,14 @@ readonly class PersonUpsertHandler } if (null !== $message->addressPostcode) { $postalCode = $this->postalCodeRepository->findOneBy(['code' => $message->addressPostcode]); - if (null !== $postalCode) { - $newAddress->setPostcode($postalCode); + if (null === $postalCode) { + // Si aucun code postal trouvé, on ne gère pas l'adresse + return null; } + $newAddress->setPostcode($postalCode); + } else { + // Si pas de postcode fourni, on ne gère pas l'adresse + return null; } if (null !== $message->addressExtra) { $newAddress->setExtra($message->addressExtra); @@ -116,7 +121,7 @@ readonly class PersonUpsertHandler * Si externalId existe, retourne le Center associé. * Sinon, cherche par nom, sinon crée un nouveau Center. */ - private function findOrCreateCenter(?string $externalId, ?string $centerName): object | null + private function findOrCreateCenter(?string $externalId, ?string $centerName): ?object { if (null === $externalId && null === $centerName) { return null; @@ -173,7 +178,9 @@ readonly class PersonUpsertHandler $messageAddressMatch = $this->isMessageAddressMatch($lastCurrentAddress, $message); if (!$messageAddressMatch) { $newAddress = $this->createAddressWithMessage($message); - $currentHousehold->addAddress($newAddress); + if (null !== $newAddress) { + $currentHousehold->addAddress($newAddress); + } } } } elseif (null === $currentHousehold && $hasAddressInfo) { @@ -182,7 +189,9 @@ readonly class PersonUpsertHandler // Create the new address $newAddress = $this->createAddressWithMessage($message); - $newHousehold->addAddress($newAddress); + if (null !== $newAddress) { + $newHousehold->addAddress($newAddress); + } // Create a MembersEditor with the new household and add the person $membersEditor = $this->membersEditorFactory->createEditor($newHousehold);