recipientIds = $recipientIds; $this->contextId = $contextId; $this->issue = $issue; $this->locale = $locale; $this->sender = $sender; } public function handle() { $context = Application::getContextDAO()->getById($this->contextId); $template = Repo::emailTemplate()->getByKey($this->contextId, IssuePublishedNotify::getEmailTemplateKey()); foreach ($this->recipientIds as $recipientId) { /** @var int $recipientId */ $recipient = Repo::user()->get($recipientId); if (!$recipient) { continue; } $notificationManager = new NotificationManager(); $notification = $notificationManager->createNotification( null, $recipientId, Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE, $this->contextId, Application::ASSOC_TYPE_ISSUE, $this->issue->getId() ); if (!$this->sender) { continue; } $mailable = $this->createMailable($context, $this->issue, $recipient, $template, $notification); $mailable->setData($this->locale); Mail::send($mailable); } } /** * Creates new issue published notification email */ protected function createMailable( Context $context, Issue $issue, User $recipient, EmailTemplate $template, Notification $notification ): IssuePublishedNotify { $mailable = new IssuePublishedNotify($context, $issue); $mailable ->recipients([$recipient]) ->sender($this->sender) ->body($template->getLocalizedData('body', $this->locale)) ->subject($template->getLocalizedData('subject', $this->locale)) ->allowUnsubscribe($notification); return $mailable; } }