kernel = $kernel; $this->doctrine = $doctrine; $this->templating = $templating; $this->mailer = $mailer; parent::__construct(); } protected function configure() { $this ->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'); } /** * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError * @throws \Twig\Error\LoaderError */ protected function execute(InputInterface $input, OutputInterface $output) : int { $jobRepo = $this->doctrine->getRepository(Job::class); $failedJobs = $jobRepo->getFailingJobs(); if(!empty($failedJobs)) { $html = $this->templating->render('mail-failed-runs.html.twig', ['jobs' => $failedJobs]); $email = (new Email()) ->from($_ENV['MAILER_FROM']) ->subject('Some cronjobs are failing') ->html($html); $recipients = $input->getArgument('recipients'); foreach ($recipients as $recipient) { $email->addTo($recipient); } $this->mailer->send($email); $output->writeln('Message sent'); } return Command::SUCCESS; } }