Skip to content

Commit

Permalink
METSUP:68: Fix url-conflict in import
Browse files Browse the repository at this point in the history
  • Loading branch information
kenza-ya committed Apr 16, 2024
1 parent ce18b07 commit ad12091
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
48 changes: 46 additions & 2 deletions src/Observers/UrlRewriteObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,29 @@ protected function process()
try {
// persist the URL rewrite
if ($this->hasChanges($urlRewrite)) {
$this->urlRewriteId = $this->persistUrlRewrite($urlRewrite);
try {
$this->urlRewriteId = $this->persistUrlRewrite($urlRewrite);
} catch (\PDOException $pdoe) {
$message = sprintf('%s with Urlrewrite Data %s "', $pdoe->getMessage(), $urlRewrite);
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);
}
}
} else {
$this->urlRewriteId = $urlRewrite[MemberNames::URL_REWRITE_ID];
}
Expand All @@ -335,7 +357,29 @@ protected function process()

// persist the URL rewrite product category relation
if ($this->hasChanges($urlRewriteProductCategory)) {
$this->persistUrlRewriteProductCategory($urlRewriteProductCategory);
try {
$this->persistUrlRewriteProductCategory($urlRewriteProductCategory);
} catch (\PDOException $pdoe) {
$message = sprintf('%s with Urlrewrite Data %s "', $pdoe->getMessage(), $urlRewriteProductCategory);
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);
}
}
}
} catch (\Exception $e) {
if (!$this->getSubject()->isStrictMode()) {
Expand Down
27 changes: 25 additions & 2 deletions src/Observers/UrlRewriteUpdateObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace TechDivision\Import\Product\UrlRewrite\Observers;

use TechDivision\Import\Utils\RegistryKeys;
use TechDivision\Import\Utils\StoreViewCodes;
use TechDivision\Import\Product\Utils\CoreConfigDataKeys;
use TechDivision\Import\Product\UrlRewrite\Utils\MemberNames;
Expand Down Expand Up @@ -129,8 +130,30 @@ protected function process()
// merge and return the prepared URL rewrite
$existingUrlRewrite = $this->mergeEntity($existingUrlRewrite, $attr);

// create the URL rewrite
$this->persistUrlRewrite($existingUrlRewrite);
try {
// create the URL rewrite
$this->persistUrlRewrite($existingUrlRewrite);
} catch (\PDOException $pdoe) {
if (!$this->getSubject()->isStrictMode()) {
$message = sprintf('%s with Urlrewrite Data %s "', $pdoe->getMessage(), $existingUrlRewrite);
$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);
}
}
} else {
// query whether or not the URL rewrite has to be removed
if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_URL_REWRITES) &&
Expand Down

0 comments on commit ad12091

Please sign in to comment.