Skip to content

Commit

Permalink
METSUP:68: Fix static test issue && update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
kenza-ya committed Apr 19, 2024
1 parent c2c56ab commit 09b4ccb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 57 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
96 changes: 40 additions & 56 deletions src/Observers/UrlRewriteObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/Observers/UrlRewriteUpdateObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 09b4ccb

Please sign in to comment.