/** * Finds subscriber without opt-in mail sent before * * @param Comment $comment * * @return object */ public function findForSubscriptionMail(Comment $comment) { $query = $this->createQuery(); $query->getQuerySettings()->setIgnoreEnableFields(TRUE); $query->matching($query->logicalAnd($query->equals('postUid', $comment->getPostId()), $query->equals('email', $comment->getEmail()), $query->equals('lastSent', 0), $query->equals('hidden', 1), $query->equals('deleted', 0))); return $query->execute()->getFirst(); }
/** * Send comment notification mails * * @param Comment $comment * * @return void */ protected function notifySubscribers(Comment $comment) { $settings = $this->settings['subscriptionManager']['subscriber']; if (!$settings['enableNewCommentNotifications']) { return; } if ($comment->getMailsSent()) { return; } $this->log->dev('Send subscriber notification mails.'); /* @var $post Post */ $post = $comment->getPost(); $subscribers = $this->subscriberRepository->findForNotification($post); $subject = $this->translate('subject.subscriber.notify', $post->getTitle()); /* @var $subscriber Subscriber */ foreach ($subscribers as $subscriber) { // make sure we do not notify the author of the triggering comment if ($comment->getEmail() === $subscriber->getEmail()) { continue; } $subscriber->updateAuth(); $this->subscriberRepository->update($subscriber); $variables = array('post' => $post, 'comment' => $comment, 'subscriber' => $subscriber, 'subject' => $subject, 'validUntil' => $this->getValidUntil()); $emailBody = $this->emailService->render($variables, 'SubscriberNewCommentMail.txt'); $this->emailService->send($subscriber->getMailTo(), array($settings['mailFrom']['email'] => $settings['mailFrom']['name']), $subject, $emailBody); } $comment->setMailsSent(TRUE); $this->objectManager->get('TYPO3\\T3extblog\\Domain\\Repository\\CommentRepository')->update($comment); }