@@ -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