From dcccbb36f4f304e3479fba009a48ba40cf69d580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 24 Mar 2026 15:41:31 +0000 Subject: [PATCH] Resolve "Ajout d'un champ "externalId" pour les centres" --- .../unreleased/Feature-20260324-164018.yaml | 7 ++++ src/Bundle/ChillMainBundle/Entity/Center.php | 18 ++++++++++ .../Repository/CenterRepository.php | 5 +++ .../Repository/CenterRepositoryInterface.php | 2 ++ .../migrations/Version20260324144420.php | 35 +++++++++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 .changes/unreleased/Feature-20260324-164018.yaml create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20260324144420.php diff --git a/.changes/unreleased/Feature-20260324-164018.yaml b/.changes/unreleased/Feature-20260324-164018.yaml new file mode 100644 index 000000000..6a2b6822c --- /dev/null +++ b/.changes/unreleased/Feature-20260324-164018.yaml @@ -0,0 +1,7 @@ +kind: Feature +body: Add a field "externalId" on center, to ease the synchronisation of centers with external tools +time: 2026-03-24T16:40:18.159561269+01:00 +custom: + Issue: "507" + MR: "977" + SchemaChange: Add columns or tables diff --git a/src/Bundle/ChillMainBundle/Entity/Center.php b/src/Bundle/ChillMainBundle/Entity/Center.php index 1ac7f5977..e7211f88a 100644 --- a/src/Bundle/ChillMainBundle/Entity/Center.php +++ b/src/Bundle/ChillMainBundle/Entity/Center.php @@ -45,6 +45,9 @@ class Center implements HasCenterInterface, \Stringable #[ORM\ManyToMany(targetEntity: Regroupment::class, mappedBy: 'centers')] private Collection $regroupments; + #[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, options: ['default' => ''])] + private string $externalId = ''; + /** * Center constructor. */ @@ -124,4 +127,19 @@ class Center implements HasCenterInterface, \Stringable return $this; } + + public function getExternalId(): string + { + return $this->externalId; + } + + public function setExternalId(string $externalId): void + { + $this->externalId = $externalId; + } + + public function hasExternalId(): bool + { + return '' !== $this->externalId; + } } diff --git a/src/Bundle/ChillMainBundle/Repository/CenterRepository.php b/src/Bundle/ChillMainBundle/Repository/CenterRepository.php index 1bc5a7405..686476b8c 100644 --- a/src/Bundle/ChillMainBundle/Repository/CenterRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/CenterRepository.php @@ -29,6 +29,11 @@ final readonly class CenterRepository implements CenterRepositoryInterface return $this->repository->find($id, $lockMode, $lockVersion); } + public function findOneByExternalId(string $externalId): ?Center + { + return $this->repository->findOneBy(['externalId' => $externalId]); + } + /** * @return Center[] */ diff --git a/src/Bundle/ChillMainBundle/Repository/CenterRepositoryInterface.php b/src/Bundle/ChillMainBundle/Repository/CenterRepositoryInterface.php index b933a34b7..1819628f0 100644 --- a/src/Bundle/ChillMainBundle/Repository/CenterRepositoryInterface.php +++ b/src/Bundle/ChillMainBundle/Repository/CenterRepositoryInterface.php @@ -24,4 +24,6 @@ interface CenterRepositoryInterface extends ObjectRepository * @return Center[] */ public function findActive(): array; + + public function findOneByExternalId(string $externalId): ?Center; } diff --git a/src/Bundle/ChillMainBundle/migrations/Version20260324144420.php b/src/Bundle/ChillMainBundle/migrations/Version20260324144420.php new file mode 100644 index 000000000..7988c32d2 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20260324144420.php @@ -0,0 +1,35 @@ +addSql('ALTER TABLE public.centers ADD externalId TEXT DEFAULT \'\' NOT NULL'); + $this->addSql('CREATE UNIQUE INDEX centers_external_id_unique ON public.centers (externalId) WHERE externalId <> \'\''); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP INDEX public.centers_external_id_unique'); + $this->addSql('ALTER TABLE public.centers DROP externalId'); + } +}