diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index b2fe40c60..5257a7a90 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -105,12 +105,25 @@ class Notification implements TrackUpdateInterface */ private ?User $updatedBy; + /** + * a list of destinee which will receive notifications + * @var array|string[] + * @ORM\Column(type="json") + */ + public array $adressesEmails = []; + + /** + * @ORM\Column(type="text", nullable=false) + */ + private string $accessKey; + public function __construct() { $this->addressees = new ArrayCollection(); $this->unreadBy = new ArrayCollection(); $this->comments = new ArrayCollection(); $this->setDate(new DateTimeImmutable()); + $this->accessKey = bin2hex(openssl_random_pseudo_bytes(24)); } public function addAddressee(User $addressee): self diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220413154743.php b/src/Bundle/ChillMainBundle/migrations/Version20220413154743.php new file mode 100644 index 000000000..88a31c92c --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220413154743.php @@ -0,0 +1,39 @@ +addSql('ALTER TABLE chill_main_notification ADD adressesEmails JSON NOT NULL DEFAULT \'[]\';'); + $this->addSql('ALTER TABLE chill_main_notification ADD accessKey TEXT DEFAULT NULL'); + $this->addSql('WITH randoms AS (select + n.id, + string_agg(substr(characters, (random() * length(characters) + 0.5)::integer, 1), \'\') as random_word + from (values(\'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\')) as symbols(characters) + -- length of word + join generate_series(1, 16) on 1 = 1 + JOIN chill_main_notification n ON true + GROUP BY n.id) + UPDATE chill_main_notification SET accessKey = randoms.random_word FROM randoms WHERE chill_main_notification.id = randoms.id'); + $this->addSql('ALTER TABLE chill_main_notification ALTER accessKey DROP DEFAULT'); + $this->addSql('ALTER TABLE chill_main_notification ALTER accessKey SET NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_notification DROP adressesEmails'); + $this->addSql('ALTER TABLE chill_main_notification DROP accessKey'); + } +}