Resolve "Ajout d'un champ "externalId" pour les centres"

This commit is contained in:
2026-03-24 15:41:31 +00:00
parent d1fe1be0f8
commit dcccbb36f4
5 changed files with 67 additions and 0 deletions

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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[]
*/

View File

@@ -24,4 +24,6 @@ interface CenterRepositoryInterface extends ObjectRepository
* @return Center[]
*/
public function findActive(): array;
public function findOneByExternalId(string $externalId): ?Center;
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260324144420 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add an external id for centers';
}
public function up(Schema $schema): void
{
$this->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');
}
}