custom/plugins/NetiNextStoreLocator/src/Subscriber/ImportExportSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextStoreLocator\Subscriber;
  4. use Shopware\Core\Content\ImportExport\Event\ImportExportAfterImportRecordEvent;
  5. use Shopware\Core\Content\ImportExport\Event\ImportExportBeforeImportRecordEvent;
  6. use Shopware\Core\Content\ImportExport\Event\ImportExportExceptionImportRecordEvent;
  7. use Shopware\Core\Framework\Context;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class ImportExportSubscriber implements EventSubscriberInterface
  10. {
  11.     public const STATE_IMPORT 'neti_sl_import';
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             ImportExportBeforeImportRecordEvent::class    => 'onBeforeImport',
  16.             ImportExportAfterImportRecordEvent::class     => 'onAfterImport',
  17.             ImportExportExceptionImportRecordEvent::class => 'onExceptionImport',
  18.         ];
  19.     }
  20.     public function onBeforeImport(ImportExportBeforeImportRecordEvent $event): void
  21.     {
  22.         $this->setState($event->getContext());
  23.     }
  24.     public function onAfterImport(ImportExportAfterImportRecordEvent $event): void
  25.     {
  26.         $this->removeState($event->getContext());
  27.     }
  28.     public function onExceptionImport(ImportExportExceptionImportRecordEvent $event): void
  29.     {
  30.         $this->removeState($event->getContext());
  31.     }
  32.     protected function setState(Context $context): void
  33.     {
  34.         $context->addState(self::STATE_IMPORT);
  35.     }
  36.     protected function removeState(Context $context): void
  37.     {
  38.         if ($context->hasState(self::STATE_IMPORT)) {
  39.             $context->removeState(self::STATE_IMPORT);
  40.         }
  41.     }
  42. }