From bef5dcce149ad96f897c26ede84c8515c0e06ba7 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 18 Jun 2025 14:03:51 +0200 Subject: [PATCH] Change property on notification entity to type of NotificationEnum --- .../ChillMainBundle/Entity/Notification.php | 31 ++++++++++--------- .../Entity/NotificationEnum.php | 24 ++++++++++++++ ...10102020.php => Version20250618115938.php} | 8 ++--- 3 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Entity/NotificationEnum.php rename src/Bundle/ChillMainBundle/migrations/{Version20250610102020.php => Version20250618115938.php} (62%) diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index 425f1e47c..79741f84e 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -14,6 +14,7 @@ namespace Chill\MainBundle\Entity; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -24,7 +25,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; #[ORM\Index(name: 'chill_main_notification_related_entity_idx', columns: ['relatedentityclass', 'relatedentityid'])] class Notification implements TrackUpdateInterface { - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false)] + #[ORM\Column(type: Types::TEXT, nullable: false)] private string $accessKey; private array $addedAddresses = []; @@ -41,7 +42,7 @@ class Notification implements TrackUpdateInterface * * @var array|string[] */ - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, options: ['default' => '[]', 'jsonb' => true])] + #[ORM\Column(type: Types::JSON, options: ['default' => '[]', 'jsonb' => true])] private array $addressesEmails = []; /** @@ -60,21 +61,21 @@ class Notification implements TrackUpdateInterface #[ORM\OrderBy(['createdAt' => \Doctrine\Common\Collections\Criteria::ASC])] private Collection $comments; - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private \DateTimeImmutable $date; #[ORM\Id] #[ORM\GeneratedValue] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)] + #[ORM\Column(type: Types::INTEGER)] private ?int $id = null; - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT)] + #[ORM\Column(type: Types::TEXT)] private string $message = ''; - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)] + #[ORM\Column(type: Types::STRING, length: 255)] private string $relatedEntityClass = ''; - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)] + #[ORM\Column(type: Types::INTEGER)] private int $relatedEntityId; private array $removedAddresses = []; @@ -84,7 +85,7 @@ class Notification implements TrackUpdateInterface private ?User $sender = null; #[Assert\NotBlank(message: 'notification.Title must be defined')] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, options: ['default' => ''])] + #[ORM\Column(type: Types::TEXT, options: ['default' => ''])] private string $title = ''; /** @@ -94,14 +95,14 @@ class Notification implements TrackUpdateInterface #[ORM\JoinTable(name: 'chill_main_notification_addresses_unread')] private Collection $unreadBy; - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] private ?\DateTimeImmutable $updatedAt = null; #[ORM\ManyToOne(targetEntity: User::class)] private ?User $updatedBy = null; - #[ORM\Column(name: 'flags', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])] - private $flags = []; + #[ORM\Column(name: 'type', type: Types::STRING, nullable: true, enumType: NotificationEnum::class)] + private NotificationEnum $type; public function __construct() { @@ -393,15 +394,15 @@ class Notification implements TrackUpdateInterface return $this; } - public function setFlags(array $flags = []): self + public function setType(NotificationEnum $type): self { - $this->flags = $flags; + $this->type = $type; return $this; } - public function getFlags(): array + public function getType(): NotificationEnum { - return $this->flags; + return $this->type; } } diff --git a/src/Bundle/ChillMainBundle/Entity/NotificationEnum.php b/src/Bundle/ChillMainBundle/Entity/NotificationEnum.php new file mode 100644 index 000000000..ead6805e9 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/NotificationEnum.php @@ -0,0 +1,24 @@ +addSql(<<<'SQL' - ALTER TABLE chill_main_notification ADD flags JSONB DEFAULT '[]' NOT NULL + ALTER TABLE chill_main_notification ADD type VARCHAR(255) SQL); } public function down(Schema $schema): void { $this->addSql(<<<'SQL' - ALTER TABLE chill_main_notification DROP flags + ALTER TABLE chill_main_notification DROP type SQL); } }