Skip to content

Commit 741e6e6

Browse files
committed
UnidentifiedBounceReprocessor
1 parent 92ff09d commit 741e6e6

File tree

3 files changed

+64
-32
lines changed

3 files changed

+64
-32
lines changed

config/services/processor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ services:
1111
tags: ['phplist.bounce_protocol_processor']
1212

1313
PhpList\Core\Domain\Messaging\Service\Processor\AdvancedBounceRulesProcessor: ~
14+
15+
PhpList\Core\Domain\Messaging\Service\Processor\UnidentifiedBounceReprocessor: ~

src/Domain/Messaging/Command/ProcessBouncesCommand.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
namespace PhpList\Core\Domain\Messaging\Command;
66

7-
use DateTimeImmutable;
87
use Exception;
98
use PhpList\Core\Domain\Messaging\Model\Bounce;
109
use PhpList\Core\Domain\Messaging\Model\UserMessage;
1110
use PhpList\Core\Domain\Messaging\Model\UserMessageBounce;
12-
use PhpList\Core\Domain\Messaging\Service\BounceProcessingService;
1311
use PhpList\Core\Domain\Messaging\Service\Processor\BounceProtocolProcessor;
1412
use PhpList\Core\Domain\Messaging\Service\Processor\AdvancedBounceRulesProcessor;
13+
use PhpList\Core\Domain\Messaging\Service\Processor\UnidentifiedBounceReprocessor;
1514
use PhpList\Core\Domain\Messaging\Service\LockService;
1615
use PhpList\Core\Domain\Messaging\Service\Manager\BounceManager;
1716
use PhpList\Core\Domain\Subscription\Repository\SubscriberRepository;
@@ -54,10 +53,10 @@ public function __construct(
5453
private readonly SubscriberManager $subscriberManager,
5554
private readonly SubscriberHistoryManager $subscriberHistoryManager,
5655
private readonly SubscriberRepository $subscriberRepository,
57-
private readonly BounceProcessingService $processingService,
5856
/** @var iterable<BounceProtocolProcessor> */
5957
private readonly iterable $protocolProcessors,
6058
private readonly AdvancedBounceRulesProcessor $advancedRulesProcessor,
59+
private readonly UnidentifiedBounceReprocessor $unidentifiedBounceReprocessor,
6160
) {
6261
parent::__construct();
6362
}
@@ -102,9 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102101
}
103102

104103
$downloadReport .= $processor->process($input, $io);
105-
106-
$this->reprocessUnidentified($io);
107-
104+
$this->unidentifiedBounceReprocessor->process($io);
108105
$this->advancedRulesProcessor->process($io, (int)$input->getOption('rules-batch-size'));
109106

110107
$this->handleConsecutiveBounces(
@@ -128,32 +125,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
128125
}
129126
}
130127

131-
private function reprocessUnidentified(SymfonyStyle $io): void
132-
{
133-
$io->section('Reprocessing unidentified bounces');
134-
$bounces = $this->bounceManager->findByStatus('unidentified bounce');
135-
$total = count($bounces);
136-
$io->writeln(sprintf('%d bounces to reprocess', $total));
137-
$count = 0; $reparsed = 0; $reidentified = 0;
138-
foreach ($bounces as $bounce) {
139-
$count++;
140-
if ($count % 25 === 0) {
141-
$io->writeln(sprintf('%d out of %d processed', $count, $total));
142-
}
143-
$decodedBody = $this->processingService->decodeBody($bounce->getHeader(), $bounce->getData());
144-
$userId = $this->processingService->findUserId($decodedBody);
145-
$messageId = $this->processingService->findMessageId($decodedBody);
146-
if ($userId || $messageId) {
147-
$reparsed++;
148-
if ($this->processingService->processBounceData($bounce, $messageId, $userId, new DateTimeImmutable())) {
149-
$reidentified++;
150-
}
151-
}
152-
}
153-
$io->writeln(sprintf('%d out of %d processed', $count, $total));
154-
$io->writeln(sprintf('%d bounces were re-processed and %d bounces were re-identified', $reparsed, $reidentified));
155-
}
156-
157128
private function handleConsecutiveBounces(SymfonyStyle $io, int $unsubscribeThreshold, int $blacklistThreshold): void
158129
{
159130
$io->section('Identifying consecutive bounces');
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Domain\Messaging\Service\Processor;
6+
7+
use DateTimeImmutable;
8+
use PhpList\Core\Domain\Messaging\Service\BounceProcessingService;
9+
use PhpList\Core\Domain\Messaging\Service\Manager\BounceManager;
10+
use Symfony\Component\Console\Style\SymfonyStyle;
11+
12+
class UnidentifiedBounceReprocessor
13+
{
14+
public function __construct(
15+
private readonly BounceManager $bounceManager,
16+
private readonly BounceProcessingService $processingService,
17+
) {
18+
}
19+
20+
public function process(SymfonyStyle $io): void
21+
{
22+
$io->section('Reprocessing unidentified bounces');
23+
$bounces = $this->bounceManager->findByStatus('unidentified bounce');
24+
$total = count($bounces);
25+
$io->writeln(sprintf('%d bounces to reprocess', $total));
26+
27+
$count = 0;
28+
$reparsed = 0;
29+
$reidentified = 0;
30+
foreach ($bounces as $bounce) {
31+
$count++;
32+
if ($count % 25 === 0) {
33+
$io->writeln(sprintf('%d out of %d processed', $count, $total));
34+
}
35+
36+
$decodedBody = $this->processingService->decodeBody($bounce->getHeader(), $bounce->getData());
37+
$userId = $this->processingService->findUserId($decodedBody);
38+
$messageId = $this->processingService->findMessageId($decodedBody);
39+
40+
if ($userId || $messageId) {
41+
$reparsed++;
42+
if ($this->processingService->processBounceData(
43+
$bounce,
44+
$messageId,
45+
$userId,
46+
new DateTimeImmutable())
47+
) {
48+
$reidentified++;
49+
}
50+
}
51+
}
52+
53+
$io->writeln(sprintf('%d out of %d processed', $count, $total));
54+
$io->writeln(sprintf(
55+
'%d bounces were re-processed and %d bounces were re-identified',
56+
$reparsed, $reidentified
57+
));
58+
}
59+
}

0 commit comments

Comments
 (0)