<?php
namespace App\Cron\Job; class SendCalendarEventsEmails extends \App\Cron\Job\Utils\GeneralAbstract { protected $category = 'operational'; protected function executeJob() { $CalendarEventList = new \App\EntityList\CalendarEvents(); $CalendarEventList->setFilter('alertDateTime', '!=', DATETIME_LIMIT_MIN); $CalendarEventList->setFilter('alertDateTime', '<', DATETIME); $CalendarEventList->setFilter('dismissDateTime', '=', DATETIME_LIMIT_MIN); $CalendarEventList->setFilter('mailStatus', '=', 1); $CalendarEventList->setOrderBy('startDateTime', 'ASC'); $CalendarEventList->setOrderBy('endDateTime', 'ASC'); $remindersList = $CalendarEventList->exportRecords(); if ($remindersList) { $sentCount = 0; $notSentCount = 0; foreach ($remindersList as $reminder) { \DB::startTransaction(); try { $event = \Entity\CalendarEvent::sendMail($reminder['id']); $event->save(); \DB::commitTransaction(); $sentCount++; } catch (\App\Entity\Exception $ex) { \DB::rollbackTransaction(); $notSentCount++; $this->logger->error(sprintf("Problem sending email for event '%s': %s", $reminder['id'], $ex->getMessagesListFormattedSimple())); } } $this->logger->success(sprintf("Emails sent to queue: %s", $sentCount)); if ($notSentCount) { $this->logger->error(sprintf("Emails not sent to queue: %s", $notSentCount)); } } else { $this->logger->idle("No calendar events alerts found."); } } } 