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

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.     protected FilesystemOperator $pimcoreDataImporterUploadStorage;
  40.     protected FilesystemOperator $pimcoreDataImporterPreviewStorage;
  41.     public function __construct(DeltaChecker $deltaCheckerQueueService $queueServiceExecutionService $executionServiceFilesystemOperator $pimcoreDataImporterUploadStorageFilesystemOperator $pimcoreDataImporterPreviewStorage)
  42.     {
  43.         $this->deltaChecker $deltaChecker;
  44.         $this->queueService $queueService;
  45.         $this->executionService $executionService;
  46.         $this->pimcoreDataImporterUploadStorage $pimcoreDataImporterUploadStorage;
  47.         $this->pimcoreDataImporterPreviewStorage $pimcoreDataImporterPreviewStorage;
  48.     }
  49.     /**
  50.      * @return string[]
  51.      */
  52.     public static function getSubscribedEvents()
  53.     {
  54.         return [
  55.             ConfigurationEvents::CONFIGURATION_POST_DELETE => 'postDelete',
  56.             ConfigurationEvents::CONFIGURATION_POST_SAVE => 'postSave'
  57.         ];
  58.     }
  59.     /**
  60.      * @param GenericEvent $event
  61.      */
  62.     public function postDelete(GenericEvent $event)
  63.     {
  64.         /** @var Configuration $config */
  65.         $config $event->getSubject();
  66.         if ($config->getType() === 'dataImporterDataObject') {
  67.             //cleanup delta cache
  68.             $this->deltaChecker->cleanup($config->getName());
  69.             //cleanup queue
  70.             $this->queueService->cleanupQueueItems($config->getName());
  71.             //cleanup preview files
  72.             try {
  73.                 $this->pimcoreDataImporterPreviewStorage->deleteDirectory($config->getName());
  74.             } catch (FilesystemException $e) {
  75.                 Logger::info($e);
  76.             }
  77.             //cleanup upload files
  78.             try {
  79.                 $this->pimcoreDataImporterUploadStorage->deleteDirectory($config->getName());
  80.             } catch (FilesystemException $e) {
  81.                 Logger::info($e);
  82.             }
  83.             //cleanup cron execution
  84.             $this->executionService->cleanup($config->getName());
  85.         }
  86.     }
  87.     public function postSave(GenericEvent $event)
  88.     {
  89.         /** @var Configuration $config */
  90.         $config $event->getSubject();
  91.         if ($config->getType() === 'dataImporterDataObject') {
  92.             $this->executionService->initExecution($config->getName());
  93.         }
  94.     }
  95. }