/** * Process task notification * @param NotificationMessage $message * @param TaskNotificationRules $rule * @param string $action */ protected static function processTaskNotification(NotificationMessage $message, TaskNotificationRules $rule, $action) { assert('is_string($action)'); $users = $rule->getUsers(); //This scenario would be there when there is only one subscriber. In that case users would //be zero if (count($users) == 0) { return; } $notifications = static::resolveAndGetNotifications($users, $rule->getType(), $message, $rule->allowDuplicates()); if (static::resolveShouldSendEmailIfCritical() && $rule->isCritical()) { foreach ($notifications as $notification) { static::sendTaskEmail($notification, $rule, $action); } } }
/** * Send task email * @param Notification $notification * @param TaskNotificationRules $rule * @param string $action */ protected static function sendTaskEmail(Notification $notification, TaskNotificationRules $rule, $action) { assert('is_string($action)'); $notificationSettingName = static::resolveNotificationSettingNameFromType($rule->getType()); if ($notification->owner->primaryEmail->emailAddress !== null && UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($notification->owner, $notificationSettingName, 'email')) { $emailMessage = static::makeEmailMessage(); $emailMessage->subject = static::getEmailSubject($notification, $rule); $emailMessage->content = static::makeEmailContent($notification); $emailMessage->sender = static::makeSender(); $emailMessage->recipients->add(static::makeRecipient($notification)); $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT); try { Yii::app()->emailHelper->send($emailMessage); } catch (CException $e) { //Not sure what to do yet when catching an exception here. Currently ignoring gracefully. } } }