Skip to content

Commit ad12091

Browse files
committed
METSUP:68: Fix url-conflict in import
1 parent ce18b07 commit ad12091

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

src/Observers/UrlRewriteObserver.php

+46-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,29 @@ protected function process()
315315
try {
316316
// persist the URL rewrite
317317
if ($this->hasChanges($urlRewrite)) {
318-
$this->urlRewriteId = $this->persistUrlRewrite($urlRewrite);
318+
try {
319+
$this->urlRewriteId = $this->persistUrlRewrite($urlRewrite);
320+
} catch (\PDOException $pdoe) {
321+
$message = sprintf('%s with Urlrewrite Data %s "', $pdoe->getMessage(), $urlRewrite);
322+
if (!$this->getSubject()->isStrictMode()) {
323+
$this->getSubject()
324+
->getSystemLogger()
325+
->warning($this->getSubject()->appendExceptionSuffix($message));
326+
$this->mergeStatus(
327+
array(
328+
RegistryKeys::NO_STRICT_VALIDATIONS => array(
329+
basename($this->getFilename()) => array(
330+
$this->getLineNumber() => array(
331+
ColumnKeys::URL_KEY => $message
332+
)
333+
)
334+
)
335+
)
336+
);
337+
} else {
338+
throw new \PDOException($pdoe);
339+
}
340+
}
319341
} else {
320342
$this->urlRewriteId = $urlRewrite[MemberNames::URL_REWRITE_ID];
321343
}
@@ -335,7 +357,29 @@ protected function process()
335357

336358
// persist the URL rewrite product category relation
337359
if ($this->hasChanges($urlRewriteProductCategory)) {
338-
$this->persistUrlRewriteProductCategory($urlRewriteProductCategory);
360+
try {
361+
$this->persistUrlRewriteProductCategory($urlRewriteProductCategory);
362+
} catch (\PDOException $pdoe) {
363+
$message = sprintf('%s with Urlrewrite Data %s "', $pdoe->getMessage(), $urlRewriteProductCategory);
364+
if (!$this->getSubject()->isStrictMode()) {
365+
$this->getSubject()
366+
->getSystemLogger()
367+
->warning($this->getSubject()->appendExceptionSuffix($message));
368+
$this->mergeStatus(
369+
array(
370+
RegistryKeys::NO_STRICT_VALIDATIONS => array(
371+
basename($this->getFilename()) => array(
372+
$this->getLineNumber() => array(
373+
ColumnKeys::URL_KEY => $message
374+
)
375+
)
376+
)
377+
)
378+
);
379+
} else {
380+
throw new \PDOException($pdoe);
381+
}
382+
}
339383
}
340384
} catch (\Exception $e) {
341385
if (!$this->getSubject()->isStrictMode()) {

src/Observers/UrlRewriteUpdateObserver.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace TechDivision\Import\Product\UrlRewrite\Observers;
1616

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

132-
// create the URL rewrite
133-
$this->persistUrlRewrite($existingUrlRewrite);
133+
try {
134+
// create the URL rewrite
135+
$this->persistUrlRewrite($existingUrlRewrite);
136+
} catch (\PDOException $pdoe) {
137+
if (!$this->getSubject()->isStrictMode()) {
138+
$message = sprintf('%s with Urlrewrite Data %s "', $pdoe->getMessage(), $existingUrlRewrite);
139+
$this->getSubject()
140+
->getSystemLogger()
141+
->warning($this->getSubject()->appendExceptionSuffix($message));
142+
$this->mergeStatus(
143+
array(
144+
RegistryKeys::NO_STRICT_VALIDATIONS => array(
145+
basename($this->getFilename()) => array(
146+
$this->getLineNumber() => array(
147+
ColumnKeys::URL_KEY => $message
148+
)
149+
)
150+
)
151+
)
152+
);
153+
} else {
154+
throw new \PDOException($pdoe);
155+
}
156+
}
134157
} else {
135158
// query whether or not the URL rewrite has to be removed
136159
if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_URL_REWRITES) &&

0 commit comments

Comments
 (0)