kernel = $kernel; $this->doctrine = $doctrine; $this->templating = $templating; $this->mailer = $mailer; parent::__construct(); } protected function configure() { $this ->setDescription('Sends email about failed runs') ->setHelp('This command will send emails to the users when jobs are failing'); } /** * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError * @throws \Twig\Error\LoaderError */ protected function execute(InputInterface $input, OutputInterface $output) { $userRepo = $this->doctrine->getRepository(User::class); $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 = $userRepo->getMailAddresses(); foreach ($recipients as $recipient) { $email->addTo($recipient); } $this->mailer->send($email); $output->writeln('Message sent'); } return Command::SUCCESS; } }