From ab5191078374d16b3ea85ae513eb44be4ccfd75c Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 26 Mar 2020 15:01:33 +0400 Subject: [PATCH] Fix NotificationReport --- src/Command/NotifyCommand.php | 2 +- src/Entity/NotificationReport.php | 12 ++++---- src/Migrations/Version20200326105828.php | 36 ++++++++++++++++++++++++ src/Migrations/Version20200326110140.php | 35 +++++++++++++++++++++++ 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 src/Migrations/Version20200326105828.php create mode 100644 src/Migrations/Version20200326110140.php diff --git a/src/Command/NotifyCommand.php b/src/Command/NotifyCommand.php index 3a2f7ef..ac849ef 100644 --- a/src/Command/NotifyCommand.php +++ b/src/Command/NotifyCommand.php @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $email = $this->redis->get($key, function (){}); $email = unserialize($email); $this->emailService->sendEmail($email); - report->changeStatus($status); +// report->changeStatus($status); $this->redis->delete($key); } diff --git a/src/Entity/NotificationReport.php b/src/Entity/NotificationReport.php index 1abae8f..658167d 100644 --- a/src/Entity/NotificationReport.php +++ b/src/Entity/NotificationReport.php @@ -25,9 +25,9 @@ class NotificationReport private $sender; /** - * @ORM\Column(type="object") + * @ORM\Column(type="integer") */ - private $recipient; + private $recipientId; /** * @ORM\Column(type="string", length=15) @@ -37,7 +37,7 @@ class NotificationReport public function __construct(User $sender, User $recipient) { $this->sender = $sender; - $this->recipient = $recipient; + $this->recipientId = $recipient->getId(); $this->status = self::NOTIFICATION_STATUS_PENDING; } @@ -58,14 +58,14 @@ public function setSender(User $sender): self return $this; } - public function getRecipient(): ?User + public function getRecipient(): int { - return $this->recipient; + return $this->recipientId; } public function setRecipient(User $recipient): self { - $this->recipient = $recipient; + $this->recipientId = $recipient->getId(); return $this; } diff --git a/src/Migrations/Version20200326105828.php b/src/Migrations/Version20200326105828.php new file mode 100644 index 0000000..4487231 --- /dev/null +++ b/src/Migrations/Version20200326105828.php @@ -0,0 +1,36 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE notification_report (id INT AUTO_INCREMENT NOT NULL, sender_id INT DEFAULT NULL, recipient LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', status VARCHAR(15) NOT NULL, INDEX IDX_8889D9F624B39D (sender_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE notification_report ADD CONSTRAINT FK_8889D9F624B39D FOREIGN KEY (sender_id) REFERENCES user (id)'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE notification_report'); + } +} diff --git a/src/Migrations/Version20200326110140.php b/src/Migrations/Version20200326110140.php new file mode 100644 index 0000000..5c2f0da --- /dev/null +++ b/src/Migrations/Version20200326110140.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE notification_report CHANGE recipient recipient INT NOT NULL'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE notification_report CHANGE recipient recipient LONGTEXT CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci` COMMENT \'(DC2Type:object)\''); + } +}