|
5 | 5 | namespace PhpList\Core\Domain\Messaging\Service\Processor; |
6 | 6 |
|
7 | 7 | use DateTimeImmutable; |
| 8 | +use PhpList\Core\Domain\Messaging\Model\BounceStatus; |
8 | 9 | use PhpList\Core\Domain\Messaging\Service\MessageParser; |
9 | 10 | use PhpList\Core\Domain\Messaging\Service\Manager\BounceManager; |
10 | 11 | use Symfony\Component\Console\Style\SymfonyStyle; |
| 12 | +use Symfony\Contracts\Translation\TranslatorInterface; |
11 | 13 |
|
12 | 14 | class UnidentifiedBounceReprocessor |
13 | 15 | { |
14 | 16 | private BounceManager $bounceManager; |
15 | 17 | private MessageParser $messageParser; |
16 | 18 | private BounceDataProcessor $bounceDataProcessor; |
17 | | - |
| 19 | + private TranslatorInterface $translator; |
18 | 20 |
|
19 | 21 | public function __construct( |
20 | 22 | BounceManager $bounceManager, |
21 | 23 | MessageParser $messageParser, |
22 | 24 | BounceDataProcessor $bounceDataProcessor, |
| 25 | + TranslatorInterface $translator, |
23 | 26 | ) { |
24 | 27 | $this->bounceManager = $bounceManager; |
25 | 28 | $this->messageParser = $messageParser; |
26 | 29 | $this->bounceDataProcessor = $bounceDataProcessor; |
| 30 | + $this->translator = $translator; |
27 | 31 | } |
28 | 32 |
|
29 | 33 | public function process(SymfonyStyle $inputOutput): void |
30 | 34 | { |
31 | | - $inputOutput->section('Reprocessing unidentified bounces'); |
32 | | - $bounces = $this->bounceManager->findByStatus('unidentified bounce'); |
| 35 | + $inputOutput->section($this->translator->trans('Reprocessing unidentified bounces')); |
| 36 | + $bounces = $this->bounceManager->findByStatus(BounceStatus::UnidentifiedBounce->value); |
33 | 37 | $total = count($bounces); |
34 | | - $inputOutput->writeln(sprintf('%d bounces to reprocess', $total)); |
| 38 | + $inputOutput->writeln($this->translator->trans('%total% bounces to reprocess', ['%total%' => $total])); |
35 | 39 |
|
36 | 40 | $count = 0; |
37 | 41 | $reparsed = 0; |
38 | 42 | $reidentified = 0; |
39 | 43 | foreach ($bounces as $bounce) { |
40 | 44 | $count++; |
41 | 45 | if ($count % 25 === 0) { |
42 | | - $inputOutput->writeln(sprintf('%d out of %d processed', $count, $total)); |
| 46 | + $inputOutput->writeln($this->translator->trans('%count% out of %total% processed', [ |
| 47 | + '%count%' => $count, |
| 48 | + '%total%' => $total |
| 49 | + ])); |
43 | 50 | } |
44 | 51 |
|
45 | | - $decodedBody = $this->messageParser->decodeBody($bounce->getHeader(), $bounce->getData()); |
| 52 | + $decodedBody = $this->messageParser->decodeBody(header: $bounce->getHeader(), body: $bounce->getData()); |
46 | 53 | $userId = $this->messageParser->findUserId($decodedBody); |
47 | 54 | $messageId = $this->messageParser->findMessageId($decodedBody); |
48 | 55 |
|
49 | 56 | if ($userId || $messageId) { |
50 | 57 | $reparsed++; |
51 | 58 | if ($this->bounceDataProcessor->process( |
52 | | - $bounce, |
53 | | - $messageId, |
54 | | - $userId, |
55 | | - new DateTimeImmutable() |
| 59 | + bounce: $bounce, |
| 60 | + msgId: $messageId, |
| 61 | + userId: $userId, |
| 62 | + bounceDate: new DateTimeImmutable() |
56 | 63 | ) |
57 | 64 | ) { |
58 | 65 | $reidentified++; |
59 | 66 | } |
60 | 67 | } |
61 | 68 | } |
62 | 69 |
|
63 | | - $inputOutput->writeln(sprintf('%d out of %d processed', $count, $total)); |
64 | | - $inputOutput->writeln(sprintf( |
65 | | - '%d bounces were re-processed and %d bounces were re-identified', |
66 | | - $reparsed, |
67 | | - $reidentified |
| 70 | + $inputOutput->writeln($this->translator->trans('%count% out of %total% processed', [ |
| 71 | + '%count%' => $count, |
| 72 | + '%total%' => $total |
| 73 | + ])); |
| 74 | + $inputOutput->writeln($this->translator->trans( |
| 75 | + '%reparsed% bounces were re-processed and %reidentified% bounces were re-identified', [ |
| 76 | + '%reparsed%' => $reparsed, |
| 77 | + '%reidentified%' => $reidentified, |
| 78 | + ] |
68 | 79 | )); |
69 | 80 | } |
70 | 81 | } |
0 commit comments