diff --git a/src/Processing/ImportProcessingService.php b/src/Processing/ImportProcessingService.php index 82f6788d..54f19304 100644 --- a/src/Processing/ImportProcessingService.php +++ b/src/Processing/ImportProcessingService.php @@ -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 diff --git a/src/Resolver/Load/AbstractLoad.php b/src/Resolver/Load/AbstractLoad.php index 0aeb7c5b..e96406ea 100644 --- a/src/Resolver/Load/AbstractLoad.php +++ b/src/Resolver/Load/AbstractLoad.php @@ -80,7 +80,7 @@ protected function getClassName() * * @return ElementInterface|null * - * @throws InvalidConfigurationException + * @throws \InvalidArgumentException */ public function loadElement(array $inputData): ?ElementInterface { @@ -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.'); } }