src/mvk/Import/EventListener/DataImporterListener.php line 38

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace App\mvk\Import\EventListener;
  15. use Pimcore\Bundle\DataImporterBundle\Event\PostPreparationEvent;
  16. use App\mvk\Import\Messenger\ImportHighPrioHandler;
  17. use App\mvk\Import\Messenger\ImportLowPrioHandler;
  18. use Pimcore\Log\ApplicationLogger;
  19. use Pimcore\Bundle\DataImporterBundle\PimcoreDataImporterBundle;
  20. use Pimcore\Bundle\DataImporterBundle\Processing\ImportProcessingService;
  21. class DataImporterListener
  22. {
  23.     public function __construct(
  24.         protected ImportHighPrioHandler $importHighPrioHandler,
  25.         protected ImportLowPrioHandler $importLowPrioHandler,
  26.         protected ApplicationLogger $applicationLogger,
  27.         protected ImportProcessingService $importProcessingService
  28.     ) {
  29.         $this->applicationLogger $applicationLogger;
  30.         $this->importProcessingService $importProcessingService;
  31.     }
  32.     public function importPrepared(PostPreparationEvent $event)
  33.     {
  34.         $configName $event->getConfigName();
  35.         // add Log Entry with some information about count of changes
  36.         $importStatus $this->importProcessingService->getImportStatus($configName);
  37.         if (isset($importStatus['isRunning'])) {
  38.             if($importStatus['isRunning'] === false) {
  39.                 $importStatus['isRunning'] = 'NO';
  40.             } else {
  41.                 $importStatus['isRunning'] = 'YES';
  42.             }
  43.         }
  44.         $message 'Import Status '.$configName.': '.$this->mapped_implode(', '$importStatus' is ');
  45.         $this->applicationLogger->info($message, [
  46.             'component' => PimcoreDataImporterBundle::LOGGER_COMPONENT_PREFIX $configName,
  47.         ]);
  48.         if (str_contains($configName'Relation_') == true) {
  49.             // if the current config is a relation config use low prio messenger transport. Otherwise always use high transport message
  50.             $this->importLowPrioHandler->dispatchMessages($event->getExecutionType());
  51.         } else {
  52.             $this->importHighPrioHandler->dispatchMessages($event->getExecutionType());
  53.         }
  54.     }
  55.     /**
  56.      * helper function to implode the key value pairs from import status return array to a string message for application logger
  57.      */
  58.     function mapped_implode($glue$array$symbol '=') {
  59.         return implode($gluearray_map(
  60.             function($k$v) use($symbol) { 
  61.                 return $k $symbol $v;
  62.             }, 
  63.             array_keys($array), 
  64.             array_values($array)
  65.             )
  66.         );
  67.     }
  68. }