From 2a39dc7753e239352995ee09e648b4c4432fa2fa Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 29 Aug 2023 11:56:06 +0200 Subject: [PATCH] Catch mapping exceptions during converting entities. (#109) Those are handled the same way, the entity is skipped and errors are logged. That way further entities can be imported while only none working entities are skipped. Relates: #10653 --- Classes/Domain/Import/Importer.php | 44 ++++++++++++++++++++---------- Documentation/Changelog/2.1.0.rst | 8 ++++-- ext_emconf.php | 2 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Classes/Domain/Import/Importer.php b/Classes/Domain/Import/Importer.php index fd3f0d4..e67f056 100644 --- a/Classes/Domain/Import/Importer.php +++ b/Classes/Domain/Import/Importer.php @@ -162,11 +162,11 @@ class Importer } foreach ($content['@graph'] as $jsonEntity) { - $this->importJsonEntity($jsonEntity); + $this->importJsonEntity($jsonEntity, $url); } } - private function importJsonEntity(array $jsonEntity): void + private function importJsonEntity(array $jsonEntity, string $url): void { if ($this->entityAllowed($jsonEntity) === false) { return; @@ -191,12 +191,7 @@ class Importer ] ); } catch (MappingException $e) { - $this->logger->error('Could not map data to entity.', [ - 'url' => $e->getUrl(), - 'language' => $language, - 'mappingError' => $e->getMessage(), - ]); - $this->import->getLog()->addEntry(new MappingError($e)); + $this->handleMappingException($e, $language); continue; } @@ -205,14 +200,25 @@ class Importer continue; } - $convertedEntity = $this->converter->convert( - $mappedEntity, - $this->import->getConfiguration(), - $language - ); + try { + $convertedEntity = $this->converter->convert( + $mappedEntity, + $this->import->getConfiguration(), + $language + ); + } catch (MappingException $e) { + $this->handleMappingException($e, $language); + $convertedEntity = null; + } if ($convertedEntity === null) { - $this->logger->error('Could not convert entity.', ['language' => $language, 'targetEntity' => $targetEntity]); + $this->logger->notice( + 'Could not convert entity.', + [ + 'url' => $url, + 'language' => $language, + 'targetEntity' => $targetEntity, + ]); continue; } $entities->add($convertedEntity); @@ -239,4 +245,14 @@ class Importer $this->logger->notice('Deny entity as type is not allowed.', ['types' => $jsonEntity['@type']]); return false; } + + private function handleMappingException(MappingException $exception, string $language): void + { + $this->logger->error('Could not map data to entity.', [ + 'url' => $exception->getUrl(), + 'language' => $language, + 'mappingError' => $exception->getMessage(), + ]); + $this->import->getLog()->addEntry(new MappingError($exception)); + } } diff --git a/Documentation/Changelog/2.1.0.rst b/Documentation/Changelog/2.1.0.rst index 09919e5..c050ced 100644 --- a/Documentation/Changelog/2.1.0.rst +++ b/Documentation/Changelog/2.1.0.rst @@ -17,12 +17,16 @@ Features Fixes ----- -Nothing +* Catch mapping exceptions during converting entities. + Those are handled the same way, the entity is skipped and errors are logged. + That way further entities can be imported while only none working entities are skipped. Tasks ----- -Nothing +* Converted log entry for none converted entity from error to notice. + As this might hint at an issue but most probably is okay, e.g. due to none active + language, missing name, etc. Deprecation ----------- diff --git a/ext_emconf.php b/ext_emconf.php index 159eaaa..ec918cb 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -11,7 +11,7 @@ $EM_CONF[$_EXTKEY] = [ 'author' => 'Daniel Siepmann', 'author_email' => 'coding@daniel-siepmann.de', 'author_company' => '', - 'version' => '2.0.0', + 'version' => '2.1.0', 'constraints' => [ 'depends' => [ 'core' => '',