コード例 #1
0
 /**
  * Send reminder using email
  *
  * @param Reminder $reminder
  */
 public function sendReminderEmail(Reminder $reminder)
 {
     $this->emailNotification->setReminder($reminder);
     try {
         $this->emailNotificationProcessor->process($this->emailNotification->getEntity(), [$this->emailNotification]);
         $reminder->setState(Reminder::STATE_SENT);
     } catch (\Exception $exception) {
         $reminder->setState(Reminder::STATE_FAIL);
         $reminder->setFailureException($exception);
     }
 }
コード例 #2
0
 /**
  * Handle event
  *
  * @param NotificationEvent   $event
  * @param EmailNotification[] $matchedNotifications
  * @return mixed
  */
 public function handle(NotificationEvent $event, $matchedNotifications)
 {
     $entity = $event->getEntity();
     // convert notification rules to a list of EmailNotificationInterface
     $notifications = array();
     foreach ($matchedNotifications as $notification) {
         $notifications[] = new EmailNotificationAdapter($entity, $notification, $this->em);
     }
     // send notifications
     $this->processor->process($entity, $notifications);
 }
コード例 #3
0
 /**
  * Send reminder using email
  *
  * @param Reminder $reminder
  */
 public function sendReminderEmail(Reminder $reminder)
 {
     $event = new SendReminderEmailEvent($reminder);
     $this->eventDispatcher->dispatch(ReminderEvents::BEFORE_REMINDER_EMAIL_NOTIFICATION_SEND, $event);
     $this->emailNotification->setReminder($reminder);
     try {
         $this->emailNotificationProcessor->process($this->emailNotification->getEntity(), [$this->emailNotification]);
         $reminder->setState(Reminder::STATE_SENT);
     } catch (\Exception $exception) {
         $reminder->setState(Reminder::STATE_FAIL);
         $reminder->setFailureException($exception);
     }
 }
コード例 #4
0
 /**
  * Test processor with exception and empty recipients
  */
 public function testProcessErrors()
 {
     $object = $this->getMock('Oro\\Bundle\\TagBundle\\Entity\\ContainAuthorInterface');
     $notification = $this->getMock('Oro\\Bundle\\NotificationBundle\\Processor\\EmailNotificationInterface');
     $notifications = array($notification);
     $template = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailTemplate');
     $notification->expects($this->once())->method('getTemplate')->will($this->returnValue($template));
     $this->twig->expects($this->once())->method('compileMessage')->will($this->throwException(new \Twig_Error('bla bla bla')));
     $this->logger->expects($this->once())->method('error');
     $notification->expects($this->never())->method('getRecipientEmails');
     $this->mailer->expects($this->never())->method('send');
     $this->processor->process($object, $notifications);
 }
コード例 #5
0
 public function process()
 {
     foreach ($this->emailNotifications as $notification) {
         $this->emailNotificationProcessor->process($notification->getEntity(), [$notification]);
     }
     $this->emailNotifications = [];
     $this->em->flush();
 }
コード例 #6
0
 /**
  * Sends reminders for calendar events
  *
  * @throws \RuntimeException
  */
 public function send()
 {
     if ($this->logger === null) {
         $this->logger = new NullLogger();
     }
     $currentTime = new \DateTime('now', new \DateTimeZone('UTC'));
     $events = $this->getEventsToRemind($currentTime);
     if (empty($events)) {
         // there are no events require a reminder for now
         $this->logger->notice('Exit because nothing to remind.');
         return;
     }
     $template = $this->getTemplate();
     $processorLogger = new RaiseExceptionLogger($this->logger);
     $failedEventIds = array();
     foreach ($events as $event) {
         try {
             $toEmail = $event->getCalendar()->getOwner()->getEmail();
             // @todo: need to be refactored to dispatch a notification event instead of then use processor directly
             //        wait till owner will be added to the recipient list in the notification bundle
             $this->notificationProcessor->process($event, array(new EmailNotificationAdapter($template, $toEmail)), $processorLogger);
             // mark an event as processed
             $event->setReminded(true);
             $this->em->flush($event);
         } catch (RaiseExceptionLoggerException $processorEx) {
             // we do not need to write this type of exception to a log because it was already done
             $failedEventIds[] = $event->getId();
         } catch (\Exception $ex) {
             $failedEventIds[] = $event->getId();
             $this->logger->error(sprintf('A reminder sending failed. Calendar event id: %d. Error: %s.', $event->getId(), $ex->getMessage()), array('exception' => $ex));
         }
     }
     $sentCount = count($events) - count($failedEventIds);
     if ($sentCount > 0) {
         $this->logger->notice(sprintf('Sent %d reminder(s).', $sentCount));
     }
     if (!empty($failedEventIds)) {
         throw new \RuntimeException(sprintf('The sending of reminders failed for the following calendar events: %s.', implode(', ', $failedEventIds)));
     }
 }