kernel = $kernel; 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'); } protected function execute(InputInterface $input, OutputInterface $output) { $userRepo = new User($this->kernel->getDbCon()); $jobRepo = new Job($this->kernel->getDbCon()); $failedJobs = $jobRepo->getFailingJobs(); if(!empty($failedJobs)) { $twig = new Twig($this->kernel); $html = $twig->render('mail-failed-runs.html.twig', ['jobs' => $failedJobs]); $transport = Transport::fromDsn($_ENV['MAILER_DSN']); $mailer = new Mailer($transport); $email = (new Email()) ->from($_ENV['MAILER_FROM']) ->subject('Some cronjobs are failing') ->html($html); $recipients = $userRepo->getMailAddresses(); foreach ($recipients as $recipient) { $email->addTo($recipient); } $mailer->send($email); $output->writeln('Message sent'); } return Command::SUCCESS; } }