• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fnagel / t3extblog / 31416697890

10 Aug 2026 05:58PM UTC coverage: 77.408%. Remained the same
31416697890

push

github

fnagel
[TASK] Apply CGL using PHP-CS-Fixer
5

9 of 10 new or added lines in 5 files covered. (90.0%)

2652 of 3426 relevant lines covered (77.41%)

8.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.27
/Classes/Service/BlogNotificationService.php
1
<?php
2

3
namespace FelixNagel\T3extblog\Service;
4

5
/**
6
 * This file is part of the "t3extblog" Extension for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11

12
use FelixNagel\T3extblog\Domain\Model\AbstractEntity;
13
use FelixNagel\T3extblog\Domain\Model\Post;
14
use FelixNagel\T3extblog\Domain\Model\BlogSubscriber;
15
use FelixNagel\T3extblog\Domain\Repository\AbstractSubscriberRepository;
16
use FelixNagel\T3extblog\Domain\Repository\BlogSubscriberRepository;
17
use FelixNagel\T3extblog\Domain\Repository\PostRepository;
18
use FelixNagel\T3extblog\Event;
19
use FelixNagel\T3extblog\Utility\SiteUtility;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21

22
/**
23
 * Handles all notification mails for new posts notification.
24
 */
25
class BlogNotificationService extends AbstractNotificationService
26
{
27
    /**
28
     * @var BlogSubscriberRepository
29
     */
30
    protected AbstractSubscriberRepository $subscriberRepository;
31

32
    public function initializeObject()
9✔
33
    {
34
        parent::initializeObject();
9✔
35

36
        $this->subscriberRepository = GeneralUtility::makeInstance(BlogSubscriberRepository::class);
9✔
37
        $this->subscriptionSettings = $this->settingsService->getTypoScriptByPath('subscriptionManager.blog');
9✔
38
    }
39

40
    /**
41
     * Process added subscriber.
42
     *
43
     * @param BlogSubscriber $subscriber
44
     */
45
    public function processNewEntity(AbstractEntity $subscriber)
2✔
46
    {
47
        if (!($subscriber instanceof BlogSubscriber)) {
2✔
48
            throw new \InvalidArgumentException('Object should be of type BlogSubscriber!');
×
49
        }
50

51
        /** @var Event\Post\Notification\CreateEvent $event */
52
        $event = $this->eventDispatcher->dispatch(
2✔
53
            new Event\Post\Notification\CreateEvent($subscriber)
2✔
54
        );
2✔
55
        $subscriber = $event->getSubscriber();
2✔
56

57
        if ($subscriber->isValidForOptin()) {
2✔
58
            $this->sendOptInMail($subscriber);
2✔
59
            $this->persistToDatabase();
2✔
60
        }
61
    }
62

63
    /**
64
     * Process changed status of a subscriber.
65
     *
66
     * @param BlogSubscriber $subscriber
67
     */
NEW
68
    public function processChangedStatus(AbstractEntity $subscriber)
×
69
    {
70
        if (!($subscriber instanceof BlogSubscriber)) {
×
71
            throw new \InvalidArgumentException('Object should be of type BlogSubscriber!');
×
72
        }
73

74
        /** @var Event\Post\Notification\ChangedEvent $event */
75
        $event = $this->eventDispatcher->dispatch(
×
76
            new Event\Post\Notification\ChangedEvent($subscriber)
×
77
        );
×
78
        $subscriber = $event->getSubscriber();
×
79

80
        if ($subscriber->isValidForOptin()) {
×
81
            $this->sendOptInMail($subscriber);
×
82
            $this->persistToDatabase();
×
83
        }
84
    }
85

86
    /**
87
     * Send opt-in mail for subscriber.
88
     */
89
    protected function sendOptInMail(BlogSubscriber $subscriber)
2✔
90
    {
91
        $this->getLog()->dev('Send blog subscriber opt-in mail.');
2✔
92

93
        $subscriber->updateAuth();
2✔
94
        $this->subscriberRepository->update($subscriber);
2✔
95

96
        $this->sendSubscriberEmail(
2✔
97
            $subscriber,
2✔
98
            $this->translate('subject.subscriber.blog.new', '', SiteUtility::getLocale($subscriber)),
2✔
99
            $this->subscriptionSettings['subscriber']['template']['confirm']
2✔
100
        );
2✔
101
    }
102

103
    /**
104
     * Send post notification mails.
105
     *
106
     * @param Post $post
107
     */
108
    public function notifySubscribers(AbstractEntity $post): ?int
1✔
109
    {
110
        if (!($post instanceof Post)) {
1✔
111
            throw new \InvalidArgumentException('Object should be of type Post!');
×
112
        }
113

114
        $settings = $this->subscriptionSettings['subscriber'];
1✔
115

116
        if (!$settings['enableNotifications']) {
1✔
117
            return null;
×
118
        }
119

120
        if ($post->getMailsSent()) {
1✔
121
            return null;
×
122
        }
123

124
        $subscribers = $this->subscriberRepository->findForNotification();
1✔
125
        $subject = $this->translate('subject.subscriber.blog.notify', $post->getTitle(), SiteUtility::getLocale($post));
1✔
126
        $variables = ['post' => $post];
1✔
127

128
        /** @var Event\Post\Notification\SubscribersEvent $event */
129
        $event = $this->eventDispatcher->dispatch(
1✔
130
            new Event\Post\Notification\SubscribersEvent($post, $subscribers, $subject, $variables)
1✔
131
        );
1✔
132
        $subscribers = $event->getSubscribers();
1✔
133
        $subject = $event->getSubject();
1✔
134
        $variables = $event->getVariables();
1✔
135

136
        $this->getLog()->dev('Send blog subscriber notification mails to '.count($subscribers).' users.');
1✔
137

138
        /* @var $subscriber BlogSubscriber */
139
        foreach ($subscribers as $subscriber) {
1✔
140
            $subscriber->updateAuth();
1✔
141
            $this->subscriberRepository->update($subscriber);
1✔
142

143
            $this->sendSubscriberEmail($subscriber, $subject, $settings['template']['notification'], $variables);
1✔
144
        }
145

146
        $post->setMailsSent(true);
1✔
147
        GeneralUtility::makeInstance(PostRepository::class)->update($post);
1✔
148
        $this->persistToDatabase();
1✔
149

150
        return count($subscribers);
1✔
151
    }
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc