From 09b4ccb59442a96af8baf2a1f15fefefc83a54f1 Mon Sep 17 00:00:00 2001 From: yamlahik Date: Fri, 19 Apr 2024 08:19:45 +0200 Subject: [PATCH] METSUP:68: Fix static test issue && update changelog --- CHANGELOG.md | 7 ++ src/Observers/UrlRewriteObserver.php | 96 +++++++++------------- src/Observers/UrlRewriteUpdateObserver.php | 2 +- 3 files changed, 48 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c2d84..1e624ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 25.0.5 + +## Bugfixes + +* Handle Duplicate UrlKey Exception With StrictMode(METSUP-68): + * to make the error message for URL conflicts in the import contain more and more precise data than is currently the case + # 25.0.4 ## Features diff --git a/src/Observers/UrlRewriteObserver.php b/src/Observers/UrlRewriteObserver.php index aa919ce..2534729 100644 --- a/src/Observers/UrlRewriteObserver.php +++ b/src/Observers/UrlRewriteObserver.php @@ -318,34 +318,7 @@ protected function process() try { $this->urlRewriteId = $this->persistUrlRewrite($urlRewrite); } catch (\PDOException $pdoe) { - $message = sprintf( - 'Is a PDO exception is thrown: with Urlrewrite Data \\n - ("entity_id": "%s" && "request_path": "%s" && "target_path": "%s" && "entity_type": "%s" && "redirect_type": "%s" && "store_id": "%s")', - $urlRewriteProductCategory[MemberNames::ENTITY_ID], - $urlRewriteProductCategory[MemberNames::REQUEST_PATH], - $urlRewriteProductCategory[MemberNames::TARGET_PATH], - $urlRewriteProductCategory[MemberNames::ENTITY_TYPE], - $urlRewriteProductCategory[MemberNames::REDIRECT_TYPE], - $urlRewriteProductCategory[MemberNames::STORE_ID] - ); - if (!$this->getSubject()->isStrictMode()) { - $this->getSubject() - ->getSystemLogger() - ->warning($this->getSubject()->appendExceptionSuffix($message)); - $this->mergeStatus( - array( - RegistryKeys::NO_STRICT_VALIDATIONS => array( - basename($this->getFilename()) => array( - $this->getLineNumber() => array( - ColumnKeys::URL_KEY => $message - ) - ) - ) - ) - ); - } else { - throw new \PDOException($pdoe); - } + $this->handleDuplicateUrlKeyExceptionWithStrictMode($urlRewrite, $pdoe); } } else { $this->urlRewriteId = $urlRewrite[MemberNames::URL_REWRITE_ID]; @@ -369,34 +342,7 @@ protected function process() try { $this->persistUrlRewriteProductCategory($urlRewriteProductCategory); } catch (\PDOException $pdoe) { - $message = sprintf( - 'Is a PDO exception is thrown: with Urlrewrite Data \\n - ("entity_id": "%s" && "request_path": "%s" && "target_path": "%s" && "entity_type": "%s" && "redirect_type": "%s" && "store_id": "%s")', - $urlRewriteProductCategory[MemberNames::ENTITY_ID], - $urlRewriteProductCategory[MemberNames::REQUEST_PATH], - $urlRewriteProductCategory[MemberNames::TARGET_PATH], - $urlRewriteProductCategory[MemberNames::ENTITY_TYPE], - $urlRewriteProductCategory[MemberNames::REDIRECT_TYPE], - $urlRewriteProductCategory[MemberNames::STORE_ID] - ); - if (!$this->getSubject()->isStrictMode()) { - $this->getSubject() - ->getSystemLogger() - ->warning($this->getSubject()->appendExceptionSuffix($message)); - $this->mergeStatus( - array( - RegistryKeys::NO_STRICT_VALIDATIONS => array( - basename($this->getFilename()) => array( - $this->getLineNumber() => array( - ColumnKeys::URL_KEY => $message - ) - ) - ) - ) - ); - } else { - throw new \PDOException($pdoe); - } + $this->handleDuplicateUrlKeyExceptionWithStrictMode($urlRewriteProductCategory, $pdoe); } } } catch (\Exception $e) { @@ -921,4 +867,42 @@ protected function loadProduct($sku) { return $this->getProductUrlRewriteProcessor()->loadProduct($sku); } + + /** + * @param array $urlRewriteData + * @param \PDOException|\Exception $pdoe + * @return void + * @throws \Exception + */ + public function handleDuplicateUrlKeyExceptionWithStrictMode(array $urlRewriteData, \PDOException|\Exception $pdoe): void + { + $message = sprintf( + 'Is a "Duplicate entry" PDO exception is thrown: with Urlrewrite Data \\n + ("entity_id": "%s" && "request_path": "%s" && "target_path": "%s" && "entity_type": "%s" && "redirect_type": "%s" && "store_id": "%s")', + $urlRewriteData[MemberNames::ENTITY_ID], + $urlRewriteData[MemberNames::REQUEST_PATH], + $urlRewriteData[MemberNames::TARGET_PATH], + $urlRewriteData[MemberNames::ENTITY_TYPE], + $urlRewriteData[MemberNames::REDIRECT_TYPE], + $urlRewriteData[MemberNames::STORE_ID] + ); + if (!$this->getSubject()->isStrictMode()) { + $this->getSubject() + ->getSystemLogger() + ->warning($this->getSubject()->appendExceptionSuffix($message)); + $this->mergeStatus( + array( + RegistryKeys::NO_STRICT_VALIDATIONS => array( + basename($this->getFilename()) => array( + $this->getLineNumber() => array( + ColumnKeys::URL_KEY => $message + ) + ) + ) + ) + ); + } else { + throw new \PDOException($pdoe); + } + } } diff --git a/src/Observers/UrlRewriteUpdateObserver.php b/src/Observers/UrlRewriteUpdateObserver.php index 5d19cdd..d1bab6e 100644 --- a/src/Observers/UrlRewriteUpdateObserver.php +++ b/src/Observers/UrlRewriteUpdateObserver.php @@ -136,7 +136,7 @@ protected function process() } catch (\PDOException $pdoe) { if (!$this->getSubject()->isStrictMode()) { $message = sprintf( - 'Is a PDO exception is thrown: with Urlrewrite Data \\n + 'Is a "Duplicate entry" PDO exception is thrown: with Urlrewrite Data \\n ("entity_id": "%s" && "request_path": "%s" && "target_path": "%s" && "entity_type": "%s" && "redirect_type": "%s" && "store_id": "%s")', $existingUrlRewrite[MemberNames::ENTITY_ID], $existingUrlRewrite[MemberNames::REQUEST_PATH],