ENHANCEMENT: Adding recipients to mailfailedruns command
This commit is contained in:
parent
4d1909ea59
commit
e0f5cae8f6
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ use App\Repository\JobRepository;
|
||||||
use App\Repository\UserRepository;
|
use App\Repository\UserRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
@ -39,7 +40,8 @@ class MailFailedRunsCommand extends Command
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setDescription('Sends email about failed runs')
|
->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)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
|
||||||
$userRepo = $this->doctrine->getRepository(User::class);
|
|
||||||
$jobRepo = $this->doctrine->getRepository(Job::class);
|
$jobRepo = $this->doctrine->getRepository(Job::class);
|
||||||
|
|
||||||
$failedJobs = $jobRepo->getFailingJobs();
|
$failedJobs = $jobRepo->getFailingJobs();
|
||||||
|
@ -63,7 +63,7 @@ class MailFailedRunsCommand extends Command
|
||||||
->subject('Some cronjobs are failing')
|
->subject('Some cronjobs are failing')
|
||||||
->html($html);
|
->html($html);
|
||||||
|
|
||||||
$recipients = $userRepo->getMailAddresses();
|
$recipients = $input->getArgument('recipients');
|
||||||
foreach ($recipients as $recipient) {
|
foreach ($recipients as $recipient) {
|
||||||
$email->addTo($recipient);
|
$email->addTo($recipient);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||||
#[ORM\Column(type: "string", length: 60)]
|
#[ORM\Column(type: "string", length: 60)]
|
||||||
private string $password;
|
private string $password;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
#[ORM\Column(type: "boolean")]
|
|
||||||
private bool $sendmail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
|
@ -90,24 +84,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||||
return $this;
|
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
|
public function getRoles(): array
|
||||||
{
|
{
|
||||||
return array_unique(['ROLE_USER']);
|
return array_unique(['ROLE_USER']);
|
||||||
|
|
Loading…
Reference in New Issue