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
This commit is contained in:
Daniel Siepmann 2023-08-29 11:56:06 +02:00 committed by GitHub
parent 773098623e
commit 2a39dc7753
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 17 deletions

View file

@ -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;
}
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));
}
}

View file

@ -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
-----------

View file

@ -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' => '',