vendor/pimcore/data-importer/src/EventListener/ConfigurationEventSubscriber.php line 85

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 Pimcore\Bundle\DataImporterBundle\EventListener;
  15. use League\Flysystem\FilesystemException;
  16. use League\Flysystem\FilesystemOperator;
  17. use Pimcore\Bundle\DataHubBundle\Configuration;
  18. use Pimcore\Bundle\DataHubBundle\Event\ConfigurationEvents;
  19. use Pimcore\Bundle\DataImporterBundle\DataSource\Interpreter\DeltaChecker\DeltaChecker;
  20. use Pimcore\Bundle\DataImporterBundle\Processing\ExecutionService;
  21. use Pimcore\Bundle\DataImporterBundle\Queue\QueueService;
  22. use Pimcore\Logger;
  23. use Symfony\Component\EventDispatcher\EventSubscriberInterface as EventSubscriberInterfaceAlias;
  24. use Symfony\Component\EventDispatcher\GenericEvent;
  25. class ConfigurationEventSubscriber implements EventSubscriberInterfaceAlias
  26. {
  27.     /**
  28.      * @var DeltaChecker
  29.      */
  30.     protected $deltaChecker;
  31.     /**
  32.      * @var QueueService
  33.      */
  34.     protected $queueService;
  35.     /**
  36.      * @var ExecutionService
  37.      */
  38.     protected $executionService;
  39.     /**
  40.      * @var FilesystemOperator
  41.      */
  42.     protected FilesystemOperator $pimcoreDataImporterUploadStorage;
  43.     /**
  44.      * @var FilesystemOperator
  45.      */
  46.     protected FilesystemOperator $pimcoreDataImporterPreviewStorage;
  47.     /**
  48.      * @param DeltaChecker $deltaChecker
  49.      * @param QueueService $queueService
  50.      * @param ExecutionService $executionService
  51.      * @param FilesystemOperator $pimcoreDataImporterUploadStorage
  52.      * @param FilesystemOperator $pimcoreDataImporterPreviewStorage
  53.      */
  54.     public function __construct(DeltaChecker $deltaCheckerQueueService $queueServiceExecutionService $executionServiceFilesystemOperator $pimcoreDataImporterUploadStorageFilesystemOperator $pimcoreDataImporterPreviewStorage)
  55.     {
  56.         $this->deltaChecker $deltaChecker;
  57.         $this->queueService $queueService;
  58.         $this->executionService $executionService;
  59.         $this->pimcoreDataImporterUploadStorage $pimcoreDataImporterUploadStorage;
  60.         $this->pimcoreDataImporterPreviewStorage $pimcoreDataImporterPreviewStorage;
  61.     }
  62.     public static function getSubscribedEvents()
  63.     {
  64.         return [
  65.             ConfigurationEvents::CONFIGURATION_POST_DELETE => 'postDelete',
  66.             ConfigurationEvents::CONFIGURATION_POST_SAVE => 'postSave'
  67.         ];
  68.     }
  69.     /**
  70.      * @param GenericEvent $event
  71.      *
  72.      * @throws \Doctrine\DBAL\DBALException
  73.      */
  74.     public function postDelete(GenericEvent $event)
  75.     {
  76.         /** @var Configuration $config */
  77.         $config $event->getSubject();
  78.         if ($config->getType() === 'dataImporterDataObject') {
  79.             //cleanup delta cache
  80.             $this->deltaChecker->cleanup($config->getName());
  81.             //cleanup queue
  82.             $this->queueService->cleanupQueueItems($config->getName());
  83.             //cleanup preview files
  84.             try {
  85.                 $this->pimcoreDataImporterPreviewStorage->deleteDirectory($config->getName());
  86.             } catch (FilesystemException $e) {
  87.                 Logger::info($e);
  88.             }
  89.             //cleanup upload files
  90.             try {
  91.                 $this->pimcoreDataImporterUploadStorage->deleteDirectory($config->getName());
  92.             } catch (FilesystemException $e) {
  93.                 Logger::info($e);
  94.             }
  95.             //cleanup cron execution
  96.             $this->executionService->cleanup($config->getName());
  97.         }
  98.     }
  99.     public function postSave(GenericEvent $event)
  100.     {
  101.         /** @var Configuration $config */
  102.         $config $event->getSubject();
  103.         if ($config->getType() === 'dataImporterDataObject') {
  104.             $this->executionService->initExecution($config->getName());
  105.         }
  106.     }
  107. }