<?php
/**
* This file is part of the Pimcore X Installation by
* ercas GmbH & CO. KG <https://www.ercasdieagentur.de>
*
* @license GPLv3
*/
namespace App\mvk\Import\EventListener;
use App\mvk\Import\Messenger\ImportHighPrioHandler;
use App\mvk\Import\Messenger\ImportLowPrioHandler;
use App\mvk\Import\Messenger\ImportSpecialPrioHandler;
use Pimcore\Bundle\DataImporterBundle\Event\PostPreparationEvent;
use Pimcore\Bundle\DataImporterBundle\PimcoreDataImporterBundle;
use Pimcore\Bundle\DataImporterBundle\Processing\ImportProcessingService;
use Pimcore\Log\ApplicationLogger;
class DataImporterListener
{
public function __construct(
protected ImportHighPrioHandler $importHighPrioHandler,
protected ImportLowPrioHandler $importLowPrioHandler,
protected ImportSpecialPrioHandler $importSpecialPrioHandler,
protected ApplicationLogger $applicationLogger,
protected ImportProcessingService $importProcessingService
) {
$this->applicationLogger = $applicationLogger;
$this->importProcessingService = $importProcessingService;
}
public function importPrepared(PostPreparationEvent $event)
{
$configName = $event->getConfigName();
// add Log Entry with some information about count of changes
$importStatus = $this->importProcessingService->getImportStatus($configName);
if (isset($importStatus['isRunning'])) {
if ($importStatus['isRunning'] === false) {
$importStatus['isRunning'] = 'NO';
} else {
$importStatus['isRunning'] = 'YES';
}
}
$message = 'Import Status '.$configName.': '.$this->mapped_implode(', ', $importStatus, ' is ');
$this->applicationLogger->info($message, [
'component' => PimcoreDataImporterBundle::LOGGER_COMPONENT_PREFIX . $configName,
]);
if (str_contains($configName, 'Relation_') == true) {
if ($configName=='Relation_Agent_Policy') {
$this->importSpecialPrioHandler->dispatchMessages($event->getExecutionType());
} else {
// if the current config is a relation config use low prio messenger transport. Otherwise always use high transport message
$this->importLowPrioHandler->dispatchMessages($event->getExecutionType());
}
} else {
$this->importHighPrioHandler->dispatchMessages($event->getExecutionType());
}
}
/**
* helper function to implode the key value pairs from import status return array to a string message for application logger
*/
public function mapped_implode($glue, $array, $symbol = '=')
{
return implode($glue, array_map(
function ($k, $v) use ($symbol) {
return $k . $symbol . $v;
},
array_keys($array),
array_values($array)
)
);
}
}