/** * 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); } }
/** * 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); } }
/** * @param bool $hasReminder * @param bool $hasConfig * @param bool $hasRecipient * @param bool $hasSender * @param array $templates * @return EmailNotification */ protected function createNotification($hasReminder = true, $hasConfig = false, $hasRecipient = false, $hasSender = false, $templates = null) { $repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $repository->expects($this->any())->method('find')->will($this->returnValue(new CalendarEvent())); $templates = is_array($templates) ? $templates : [$this->createTemplate()]; $repository->expects($this->any())->method('findBy')->will($this->returnValue($templates)); $this->em->expects($this->any())->method('getRepository')->will($this->returnValue($repository)); $this->provider = $this->getMockBuilder('\\Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock(); $config = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMock(); $config->expects($this->any())->method('has')->will($this->returnValue($hasConfig)); $config->expects($this->any())->method('get')->will($this->returnValue(self::TEMPLATE)); $this->provider->expects($this->any())->method('getConfig')->will($this->returnValue($config)); $notification = new EmailNotification($this->em, $this->provider, $this->entityNameResolver); if ($hasReminder) { $reminder = new Reminder(); if (!$hasConfig) { $reminder->setRelatedEntityClassName(self::ENTITY)->setRelatedEntityId(1); } if ($hasRecipient) { $user = new User(); $user->setEmail(self::EMAIL); $reminder->setRecipient($user); } if ($hasSender) { $reminder->setSender($this->sender); } $notification->setReminder($reminder); } return $notification; }