@@ -48,7 +48,6 @@ class DbStorage extends AbstractStorage
48
48
*/
49
49
private $ logger ;
50
50
51
-
52
51
/**
53
52
* @var int
54
53
*/
@@ -273,8 +272,8 @@ private function checkDuplicates(array $uniqueEntities): void
273
272
foreach ($ uniqueEntities as $ storeId => $ entityTypes ) {
274
273
$ newRequestPaths = [];
275
274
foreach ($ entityTypes as $ entityType => $ entities ) {
275
+ // phpcs:ignore Magento2.Performance.ForeachArrayMerge
276
276
$ requestPaths = array_merge (...$ entities );
277
- $ requestPathFilter = '' ;
278
277
if (empty ($ requestPaths )) {
279
278
continue ;
280
279
}
@@ -289,7 +288,7 @@ private function checkDuplicates(array $uniqueEntities): void
289
288
. ') AND ' . $ this ->connection ->quoteIdentifier (UrlRewrite::REQUEST_PATH )
290
289
. ' IN ( ' . $ this ->connection ->quote ($ requestPaths ) . ') '
291
290
);
292
- foreach ($ requestPaths as $ requestPath ) {
291
+ foreach ($ requestPaths as $ requestPath ) {
293
292
if (isset ($ newRequestPaths [$ requestPath ])) {
294
293
throw new \Magento \Framework \Exception \AlreadyExistsException ();
295
294
}
@@ -340,7 +339,7 @@ protected function doReplace(array $urls): array
340
339
foreach ($ urls as $ url ) {
341
340
$ data [] = $ url ->toArray ();
342
341
}
343
- for ($ tries = 0 ; ; $ tries ++) {
342
+ for ($ tries = 0 ;; $ tries ++) {
344
343
$ this ->connection ->beginTransaction ();
345
344
try {
346
345
$ this ->deleteOldUrls ($ uniqueEntities );
@@ -355,26 +354,7 @@ protected function doReplace(array $urls): array
355
354
continue ;
356
355
} catch (\Magento \Framework \Exception \AlreadyExistsException $ e ) {
357
356
$ this ->connection ->rollBack ();
358
- /** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urlConflicted */
359
- $ urlConflicted = [];
360
- foreach ($ urls as $ url ) {
361
- $ urlFound = $ this ->doFindOneByData (
362
- [
363
- UrlRewrite::REQUEST_PATH => $ url ->getRequestPath (),
364
- UrlRewrite::STORE_ID => $ url ->getStoreId (),
365
- ]
366
- );
367
- if (isset ($ urlFound [UrlRewrite::URL_REWRITE_ID ])) {
368
- if (isset ($ uniqueEntities
369
- [$ urlFound [UrlRewrite::STORE_ID ]]
370
- [$ urlFound [UrlRewrite::ENTITY_TYPE ]]
371
- [$ urlFound [UrlRewrite::ENTITY_ID ]
372
- ])) {
373
- continue ; // Note: If it's one of the entities we are updating, then it is okay.
374
- }
375
- $ urlConflicted [$ urlFound [UrlRewrite::URL_REWRITE_ID ]] = $ url ->toArray ();
376
- }
377
- }
357
+ $ urlConflicted = $ this ->findUrlConflicted ($ urls , $ uniqueEntities );
378
358
if ($ urlConflicted ) {
379
359
throw new \Magento \UrlRewrite \Model \Exception \UrlAlreadyExistsException (
380
360
__ ('URL key for specified store already exists. ' ),
@@ -389,8 +369,39 @@ protected function doReplace(array $urls): array
389
369
$ this ->connection ->rollBack ();
390
370
throw $ e ;
391
371
}
392
- return $ urls ;
372
+ break ;
393
373
}
374
+ return $ urls ;
375
+ }
376
+
377
+ /**
378
+ * Searches existing rewrites with same requestPath & store, but ignores ones to be updated.
379
+ *
380
+ * @param array $urls
381
+ * @return array
382
+ */
383
+ private function findUrlConflicted (array $ urls , array $ uniqueEntities ): array
384
+ {
385
+ $ urlConflicted = [];
386
+ foreach ($ urls as $ url ) {
387
+ $ urlFound = $ this ->doFindOneByData (
388
+ [
389
+ UrlRewrite::REQUEST_PATH => $ url ->getRequestPath (),
390
+ UrlRewrite::STORE_ID => $ url ->getStoreId (),
391
+ ]
392
+ );
393
+ if (isset ($ urlFound [UrlRewrite::URL_REWRITE_ID ])) {
394
+ if (isset ($ uniqueEntities
395
+ [$ urlFound [UrlRewrite::STORE_ID ]]
396
+ [$ urlFound [UrlRewrite::ENTITY_TYPE ]]
397
+ [$ urlFound [UrlRewrite::ENTITY_ID ]
398
+ ])) {
399
+ continue ; // Note: If it's one of the entities we are updating, then it is okay.
400
+ }
401
+ $ urlConflicted [$ urlFound [UrlRewrite::URL_REWRITE_ID ]] = $ url ->toArray ();
402
+ }
403
+ }
404
+ return $ urlConflicted ;
394
405
}
395
406
396
407
/**
@@ -436,7 +447,7 @@ private function upsertMultiple(array $data): void
436
447
* Get filter for url rows deletion due to provided urls
437
448
*
438
449
* @param UrlRewrite[] $urls
439
- * @return array
450
+ * @return array~/tmp/system.log
440
451
* @deprecated 101.0.3 Not used anymore.
441
452
* @see nothing
442
453
*/
0 commit comments