From e0f5cae8f646067f8d364ca55ee6311a6cbcc66a Mon Sep 17 00:00:00 2001 From: jeroen Date: Wed, 7 Sep 2022 12:52:44 +0200 Subject: [PATCH] ENHANCEMENT: Adding recipients to mailfailedruns command --- migrations/Version1001.php | 31 +++++++++++++++++++++++++++ src/Command/MailFailedRunsCommand.php | 8 +++---- src/Entity/User.php | 24 --------------------- 3 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 migrations/Version1001.php diff --git a/migrations/Version1001.php b/migrations/Version1001.php new file mode 100644 index 0000000..f4ad7d9 --- /dev/null +++ b/migrations/Version1001.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE user DROP sendmail'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE user ADD sendmail TINYINT(1) NOT NULL'); + } +} diff --git a/src/Command/MailFailedRunsCommand.php b/src/Command/MailFailedRunsCommand.php index 52a8ea6..a5ad886 100644 --- a/src/Command/MailFailedRunsCommand.php +++ b/src/Command/MailFailedRunsCommand.php @@ -8,6 +8,7 @@ use App\Repository\JobRepository; use App\Repository\UserRepository; use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\HttpKernel\KernelInterface; @@ -39,7 +40,8 @@ class MailFailedRunsCommand extends Command { $this ->setDescription('Sends email about failed runs') - ->setHelp('This command will send emails to the users when jobs are failing'); + ->setHelp('This command will send emails to the users when jobs are failing') + ->addArgument('recipients', InputArgument::REQUIRED + InputArgument::IS_ARRAY, 'Which e-mailaddress should receive the notifications'); } /** @@ -49,8 +51,6 @@ class MailFailedRunsCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - - $userRepo = $this->doctrine->getRepository(User::class); $jobRepo = $this->doctrine->getRepository(Job::class); $failedJobs = $jobRepo->getFailingJobs(); @@ -63,7 +63,7 @@ class MailFailedRunsCommand extends Command ->subject('Some cronjobs are failing') ->html($html); - $recipients = $userRepo->getMailAddresses(); + $recipients = $input->getArgument('recipients'); foreach ($recipients as $recipient) { $email->addTo($recipient); } diff --git a/src/Entity/User.php b/src/Entity/User.php index 55db648..29720a3 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -30,12 +30,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: "string", length: 60)] private string $password; - /** - * @var bool - */ - #[ORM\Column(type: "boolean")] - private bool $sendmail; - /** * @return int|null */ @@ -90,24 +84,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } - /** - * @return bool - */ - public function isSendmail(): bool - { - return $this->sendmail; - } - - /** - * @param bool $sendmail - * @return User - */ - public function setSendmail(bool $sendmail): User - { - $this->sendmail = $sendmail; - return $this; - } - public function getRoles(): array { return array_unique(['ROLE_USER']);