44
55namespace PhpList \Core \Domain \Messaging \Command ;
66
7- use DateTimeImmutable ;
87use Exception ;
98use PhpList \Core \Domain \Messaging \Model \Bounce ;
109use PhpList \Core \Domain \Messaging \Model \UserMessage ;
1110use PhpList \Core \Domain \Messaging \Model \UserMessageBounce ;
12- use PhpList \Core \Domain \Messaging \Service \BounceProcessingService ;
1311use PhpList \Core \Domain \Messaging \Service \Processor \BounceProtocolProcessor ;
1412use PhpList \Core \Domain \Messaging \Service \Processor \AdvancedBounceRulesProcessor ;
13+ use PhpList \Core \Domain \Messaging \Service \Processor \UnidentifiedBounceReprocessor ;
1514use PhpList \Core \Domain \Messaging \Service \LockService ;
1615use PhpList \Core \Domain \Messaging \Service \Manager \BounceManager ;
1716use 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 ' );
0 commit comments