From f3f914ca75906dd6d3a83914cf9feae72624c811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 18 Sep 2025 12:09:06 +0200 Subject: [PATCH] Refactor `PersonIdentifierDefinition`: Replace fully qualified `\Doctrine\DBAL\Types\Types` references with simplified `Types` aliases. --- .../ChillJobBundle/src/Entity/Immersion.php | 1 - .../Serializer/Normalizer/DateNormalizer.php | 2 +- .../Identifier/IdentifierPresenceEnum.php | 42 +++++++++++++++++++ .../Entity/Identifier/PersonIdentifier.php | 2 +- .../Identifier/PersonIdentifierDefinition.php | 41 +++++++++--------- .../Normalizer/PersonJsonDenormalizer.php | 4 ++ .../migrations/Version20250918095044.php | 37 ++++++++++++++++ 7 files changed, 107 insertions(+), 22 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Entity/Identifier/IdentifierPresenceEnum.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20250918095044.php diff --git a/src/Bundle/ChillJobBundle/src/Entity/Immersion.php b/src/Bundle/ChillJobBundle/src/Entity/Immersion.php index 2d8ee6281..80d05062e 100644 --- a/src/Bundle/ChillJobBundle/src/Entity/Immersion.php +++ b/src/Bundle/ChillJobBundle/src/Entity/Immersion.php @@ -19,7 +19,6 @@ use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\Address; use libphonenumber\PhoneNumber; use Symfony\Component\Validator\Constraints as Assert; -use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint; /** * Immersion. diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php index a98339d4b..187199432 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php @@ -22,7 +22,7 @@ class DateNormalizer implements ContextAwareNormalizerInterface, DenormalizerInt { public function __construct(private readonly RequestStack $requestStack, private readonly ParameterBagInterface $parameterBag) {} - public function denormalize($data, $type, $format = null, array $context = []): ?DateTimeInterface + public function denormalize($data, $type, $format = null, array $context = []): ?\DateTimeInterface { if (null === $data) { return null; diff --git a/src/Bundle/ChillPersonBundle/Entity/Identifier/IdentifierPresenceEnum.php b/src/Bundle/ChillPersonBundle/Entity/Identifier/IdentifierPresenceEnum.php new file mode 100644 index 000000000..120fed3f0 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/Identifier/IdentifierPresenceEnum.php @@ -0,0 +1,42 @@ + '[]', 'jsonb' => true])] private array $value = []; - #[ORM\Column(name: 'canonical', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => '[]'])] + #[ORM\Column(name: 'canonical', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])] private string $canonical = ''; public function __construct( diff --git a/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifierDefinition.php b/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifierDefinition.php index 6d6112569..392125b23 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifierDefinition.php +++ b/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifierDefinition.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Entity\Identifier; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] @@ -18,23 +19,23 @@ use Doctrine\ORM\Mapping as ORM; class PersonIdentifierDefinition { #[ORM\Id] - #[ORM\Column(name: 'id', type: \Doctrine\DBAL\Types\Types::INTEGER)] + #[ORM\Column(name: 'id', type: Types::INTEGER)] #[ORM\GeneratedValue] private ?int $id = null; - #[ORM\Column(name: 'active', type: \Doctrine\DBAL\Types\Types::BOOLEAN, nullable: false, options: ['default' => true])] + #[ORM\Column(name: 'active', type: Types::BOOLEAN, nullable: false, options: ['default' => true])] private bool $active = true; public function __construct( - #[ORM\Column(name: 'label', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]'])] + #[ORM\Column(name: 'label', type: Types::JSON, nullable: false, options: ['default' => '[]'])] private array $label, - #[ORM\Column(name: 'engine', type: \Doctrine\DBAL\Types\Types::STRING, length: 100)] + #[ORM\Column(name: 'engine', type: Types::STRING, length: 100)] private string $engine, - #[ORM\Column(name: 'is_searchable', type: \Doctrine\DBAL\Types\Types::BOOLEAN, options: ['default' => false])] + #[ORM\Column(name: 'is_searchable', type: Types::BOOLEAN, options: ['default' => false])] private bool $isSearchable = false, - #[ORM\Column(name: 'is_editable_by_users', type: \Doctrine\DBAL\Types\Types::BOOLEAN, nullable: false, options: ['default' => false])] - private bool $isEditableByUsers = false, - #[ORM\Column(name: 'data', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])] + #[ORM\Column(name: 'presence', type: Types::STRING, nullable: false, enumType: IdentifierPresenceEnum::class, options: ['default' => IdentifierPresenceEnum::ON_EDIT])] + private IdentifierPresenceEnum $presence = IdentifierPresenceEnum::ON_EDIT, + #[ORM\Column(name: 'data', type: Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])] private array $data = [], ) {} @@ -58,11 +59,6 @@ class PersonIdentifierDefinition return $this->engine; } - public function setEngine(string $engine): void - { - $this->engine = $engine; - } - public function isSearchable(): bool { return $this->isSearchable; @@ -75,12 +71,7 @@ class PersonIdentifierDefinition public function isEditableByUsers(): bool { - return $this->isEditableByUsers; - } - - public function setIsEditableByUsers(bool $isEditableByUsers): void - { - $this->isEditableByUsers = $isEditableByUsers; + return $this->presence->isEditableByUser(); } public function isActive(): bool @@ -104,4 +95,16 @@ class PersonIdentifierDefinition { $this->data = $data; } + + public function getPresence(): IdentifierPresenceEnum + { + return $this->presence; + } + + public function setPresence(IdentifierPresenceEnum $presence): self + { + $this->presence = $presence; + + return $this; + } } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonDenormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonDenormalizer.php index d32fabe44..cfd43ca6d 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonDenormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonDenormalizer.php @@ -117,6 +117,10 @@ final class PersonJsonDenormalizer implements DenormalizerInterface, Denormalize $worker = $this->personIdentifierManager->buildWorkerByPersonIdentifierDefinition($definitionId); + if (!$worker->getDefinition()->isEditableByUsers()) { + continue; + } + $personIdentifier = $person->getIdentifiers()->findFirst(fn (int $key, PersonIdentifier $personIdentifier) => $personIdentifier->getId() === $definitionId); if (null === $personIdentifier) { $personIdentifier = new PersonIdentifier($worker->getDefinition()); diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20250918095044.php b/src/Bundle/ChillPersonBundle/migrations/Version20250918095044.php new file mode 100644 index 000000000..9ec97e337 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20250918095044.php @@ -0,0 +1,37 @@ +addSql('ALTER TABLE chill_person_identifier_definition ADD presence VARCHAR(255) DEFAULT \'ON_EDIT\' NOT NULL'); + $this->addSql('UPDATE chill_person_identifier_definition SET presence = \'NOT_EDITABLE\' WHERE is_editable_by_users IS FALSE'); + $this->addSql('ALTER TABLE chill_person_identifier_definition DROP is_editable_by_users'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_identifier_definition ADD is_editable_by_users BOOLEAN DEFAULT false NOT NULL'); + $this->addSql('UPDATE chill_person_identifier_definition SET is_editable_by_users = true WHERE presence <> \'NOT_EDITABLE\' '); + $this->addSql('ALTER TABLE chill_person_identifier_definition DROP presence'); + } +}