Skip to content

Commit b181d31

Browse files
committed
Fix style
1 parent 504034c commit b181d31

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
lines changed

resources/translations/messages.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,10 @@ Thank you.</target>
726726
<source>No data changed</source>
727727
<target>__No data changed</target>
728728
</trans-unit>
729+
<trans-unit id="n7nf5lh" resname="Campaign not found or not in submitted status">
730+
<source>Campaign not found or not in submitted status</source>
731+
<target>__Campaign not found or not in submitted status</target>
732+
</trans-unit>
729733
</body>
730734
</file>
731735
</xliff>

src/Domain/Messaging/Command/ProcessQueueCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
use Symfony\Contracts\Translation\TranslatorInterface;
2222
use Throwable;
2323

24+
/**
25+
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
26+
*/
2427
#[AsCommand(
2528
name: 'phplist:process-queue',
2629
description: 'Processes the email campaign queue.'
@@ -93,8 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9396

9497
try {
9598
foreach ($campaigns as $campaign) {
96-
$message = new CampaignProcessorMessage(messageId: $campaign->getId());
97-
$this->messageBus->dispatch($message);
99+
$this->messageBus->dispatch(new CampaignProcessorMessage(messageId: $campaign->getId()));
98100
}
99101
} catch (Throwable $throwable) {
100102
$output->writeln($throwable->getMessage());

src/Domain/Messaging/MessageHandler/CampaignProcessorMessageHandler.php

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -104,39 +104,12 @@ public function __invoke(CampaignProcessorMessage $message): void
104104
$this->userMessageRepository->save($userMessage);
105105

106106
if (!filter_var($subscriber->getEmail(), FILTER_VALIDATE_EMAIL)) {
107-
$this->updateUserMessageStatus($userMessage, UserMessageStatus::InvalidEmailAddress);
108-
$this->unconfirmSubscriber($subscriber);
109-
$this->logger->warning($this->translator->trans('Invalid email, marking unconfirmed: %email%', [
110-
'%email%' => $subscriber->getEmail(),
111-
]));
112-
$this->subscriberHistoryManager->addHistory(
113-
subscriber: $subscriber,
114-
message: $this->translator->trans('Subscriber marked unconfirmed for invalid email address'),
115-
details: $this->translator->trans(
116-
'Marked unconfirmed while sending campaign %message_id%',
117-
['%message_id%' => $campaign->getId()]
118-
)
119-
);
107+
$this->handleInvalidEmail($userMessage, $subscriber, $campaign);
120108
$this->entityManager->flush();
121109
continue;
122110
}
123111

124-
$processed = $this->messagePreparator->processMessageLinks($campaign, $subscriber->getId());
125-
126-
try {
127-
$email = $this->mailer->composeEmail($processed, $subscriber);
128-
$this->mailer->send($email);
129-
$this->updateUserMessageStatus($userMessage, UserMessageStatus::Sent);
130-
} catch (Throwable $e) {
131-
$this->updateUserMessageStatus($userMessage, UserMessageStatus::NotSent);
132-
$this->logger->error($e->getMessage(), [
133-
'subscriber_id' => $subscriber->getId(),
134-
'campaign_id' => $campaign->getId(),
135-
]);
136-
$this->logger->warning($this->translator->trans('Failed to send to: %email%', [
137-
'%email%' => $subscriber->getEmail(),
138-
]));
139-
}
112+
$this->handleEmailSending($campaign, $subscriber, $userMessage);
140113
}
141114

142115
if ($stoppedEarly && $this->requeueHandler->handle($campaign)) {
@@ -166,4 +139,41 @@ private function updateUserMessageStatus(UserMessage $userMessage, UserMessageSt
166139
$userMessage->setStatus($status);
167140
$this->entityManager->flush();
168141
}
142+
143+
private function handleInvalidEmail(UserMessage $userMessage, Subscriber $subscriber, mixed $campaign): void
144+
{
145+
$this->updateUserMessageStatus($userMessage, UserMessageStatus::InvalidEmailAddress);
146+
$this->unconfirmSubscriber($subscriber);
147+
$this->logger->warning($this->translator->trans('Invalid email, marking unconfirmed: %email%', [
148+
'%email%' => $subscriber->getEmail(),
149+
]));
150+
$this->subscriberHistoryManager->addHistory(
151+
subscriber: $subscriber,
152+
message: $this->translator->trans('Subscriber marked unconfirmed for invalid email address'),
153+
details: $this->translator->trans(
154+
'Marked unconfirmed while sending campaign %message_id%',
155+
['%message_id%' => $campaign->getId()]
156+
)
157+
);
158+
}
159+
160+
private function handleEmailSending(mixed $campaign, Subscriber $subscriber, UserMessage $userMessage): void
161+
{
162+
$processed = $this->messagePreparator->processMessageLinks($campaign, $subscriber->getId());
163+
164+
try {
165+
$email = $this->mailer->composeEmail($processed, $subscriber);
166+
$this->mailer->send($email);
167+
$this->updateUserMessageStatus($userMessage, UserMessageStatus::Sent);
168+
} catch (Throwable $e) {
169+
$this->updateUserMessageStatus($userMessage, UserMessageStatus::NotSent);
170+
$this->logger->error($e->getMessage(), [
171+
'subscriber_id' => $subscriber->getId(),
172+
'campaign_id' => $campaign->getId(),
173+
]);
174+
$this->logger->warning($this->translator->trans('Failed to send to: %email%', [
175+
'%email%' => $subscriber->getEmail(),
176+
]));
177+
}
178+
}
169179
}

0 commit comments

Comments
 (0)