ENHANCEMENT: Adding recipients to mailfailedruns command

This commit is contained in:
Jeroen De Meerleer 2022-09-07 12:52:44 +02:00
parent 4d1909ea59
commit e0f5cae8f6
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
3 changed files with 35 additions and 28 deletions

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version1001 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}

View File

@ -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);
}

View File

@ -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']);