Skip to content

Commit

Permalink
[Bug] Import stales when error in one import data record #232 (#308)
Browse files Browse the repository at this point in the history
* [Bug] Import stales when error in one import data record #232

* Apply php-cs-fixer changes

---------

Co-authored-by: mcop1 <mcop1@users.noreply.github.com>
  • Loading branch information
mcop1 and mcop1 committed Mar 1, 2023
1 parent a9d52f6 commit 423094e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
68 changes: 40 additions & 28 deletions src/Processing/ImportProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,50 @@ public function __construct(QueueService $queueService, MappingConfigurationFact

public function processQueueItem(int $id)
{
//get queue item
$queueItem = $this->queueService->getQueueEntryById($id);
if (empty($queueItem)) {
return;
}
$configName = null;
$queueItem = null;
try {
//get queue item
$queueItem = $this->queueService->getQueueEntryById($id);
if (empty($queueItem)) {
return;
}

//get config
$configName = $queueItem['configName'];
$config = $this->configLoader->prepareConfiguration($configName, null, true);
//get config
$configName = $queueItem['configName'];
$config = $this->configLoader->prepareConfiguration($configName, null, true);

//init resolver and mapping
if (empty($this->mappingConfigurationCache[$configName])) {
$this->mappingConfigurationCache[$configName] = $this->mappingConfigurationFactory->loadMappingConfiguration($configName, $config['mappingConfig']);
}
$mapping = $this->mappingConfigurationCache[$configName];
//init resolver and mapping
if (empty($this->mappingConfigurationCache[$configName])) {
$this->mappingConfigurationCache[$configName] = $this->mappingConfigurationFactory->loadMappingConfiguration($configName, $config['mappingConfig']);
}
$mapping = $this->mappingConfigurationCache[$configName];

if (empty($this->resolverCache[$configName])) {
$this->resolverCache[$configName] = $this->resolverFactory->loadResolver($config['resolverConfig']);
}
$resolver = $this->resolverCache[$configName];

//process element
if ($queueItem['jobType'] === self::JOB_TYPE_PROCESS) {
$data = json_decode($queueItem['data'], true);
$this->processElement($configName, $data, $resolver, $mapping);
} elseif ($queueItem['jobType'] === self::JOB_TYPE_CLEANUP) {
$this->cleanupElement($configName, $queueItem['data'], $resolver, $config['processingConfig']['cleanup'] ?? []);
} else {
throw new InvalidConfigurationException('Unknown job type ' . $queueItem['jobType']);
}
if (empty($this->resolverCache[$configName])) {
$this->resolverCache[$configName] = $this->resolverFactory->loadResolver($config['resolverConfig']);
}
$resolver = $this->resolverCache[$configName];

//process element
if ($queueItem['jobType'] === self::JOB_TYPE_PROCESS) {
$data = json_decode($queueItem['data'], true);
$this->processElement($configName, $data, $resolver, $mapping);
} elseif ($queueItem['jobType'] === self::JOB_TYPE_CLEANUP) {
$this->cleanupElement($configName, $queueItem['data'], $resolver, $config['processingConfig']['cleanup'] ?? []);
} else {
throw new InvalidConfigurationException('Unknown job type ' . $queueItem['jobType']);
}
} catch (\Exception $e) {
$component = $configName ? PimcoreDataImporterBundle::LOGGER_COMPONENT_PREFIX . $configName : null;
$fileObject = $queueItem ? new FileObject(json_encode($queueItem['data'])) : null;

$this->queueService->markQueueEntryAsProcessed($id);
$this->applicationLogger->error($e->getMessage() . $e->getMessage(), [
'component' => $component,
'fileObject' => $fileObject
]);
} finally {
$this->queueService->markQueueEntryAsProcessed($id);
}
}

private function flattenArray(array $arr): array
Expand Down
4 changes: 2 additions & 2 deletions src/Resolver/Load/AbstractLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function getClassName()
*
* @return ElementInterface|null
*
* @throws InvalidConfigurationException
* @throws \InvalidArgumentException
*/
public function loadElement(array $inputData): ?ElementInterface
{
Expand All @@ -94,6 +94,6 @@ public function loadElement(array $inputData): ?ElementInterface
*/
public function extractIdentifierFromData(array $inputData)
{
return $inputData[$this->dataSourceIndex] ?? null;
return $inputData[$this->dataSourceIndex] ?? throw new \InvalidArgumentException('Identifier not set.');
}
}

0 comments on commit 423094e

Please sign in to comment.