@@ -182,20 +182,14 @@ private function processRow(
182182 return null ;
183183 }
184184
185- $ subscriberByEmail = $ this ->subscriberRepository ->findOneByEmail ($ dto ->email );
186- $ subscriberByFk = null ;
187- if ($ dto ->foreignKey !== null ) {
188- $ subscriberByFk = $ this ->subscriberRepository ->findOneByForeignKey ($ dto ->foreignKey );
189- }
185+ [$ subscriber , $ conflictError ] = $ this ->resolveSubscriber ($ dto );
190186
191- if ($ subscriberByEmail && $ subscriberByFk && $ subscriberByEmail -> getId () !== $ subscriberByFk -> getId () ) {
187+ if ($ conflictError !== null ) {
192188 $ stats ['skipped ' ]++;
193- $ stats ['errors ' ][] = $ this -> translator -> trans ( ' Conflict: email and foreign key refer to different subscribers. ' ) ;
189+ $ stats ['errors ' ][] = $ conflictError ;
194190 return null ;
195191 }
196192
197- $ subscriber = $ subscriberByFk ?? $ subscriberByEmail ;
198-
199193 if ($ this ->handleSkipCase ($ subscriber , $ options , $ stats )) {
200194 return null ;
201195 }
@@ -239,6 +233,22 @@ private function processRow(
239233 return $ this ->prepareConfirmationMessage ($ subscriber , $ options , $ dto , $ addedNewSubscriberToList );
240234 }
241235
236+ private function resolveSubscriber (ImportSubscriberDto $ dto ): array
237+ {
238+ $ byEmail = $ this ->subscriberRepository ->findOneByEmail ($ dto ->email );
239+ $ byFk = null ;
240+
241+ if ($ dto ->foreignKey !== null ) {
242+ $ byFk = $ this ->subscriberRepository ->findOneByForeignKey ($ dto ->foreignKey );
243+ }
244+
245+ if ($ byEmail && $ byFk && $ byEmail ->getId () !== $ byFk ->getId ()) {
246+ return [null , $ this ->translator ->trans ('Conflict: email and foreign key refer to different subscribers. ' )];
247+ }
248+
249+ return [$ byFk ?? $ byEmail , null ];
250+ }
251+
242252 private function handleInvalidEmail (
243253 ImportSubscriberDto $ dto ,
244254 SubscriberImportOptions $ options ,
0 commit comments