custom/plugins/PickwareErpStarter/src/ImportExport/ModelSubscriber/IsDownloadReadyFieldCalculationSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Pickware GmbH. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Pickware\PickwareErpStarter\ImportExport\ModelSubscriber;
  11. use Pickware\PickwareErpStarter\ImportExport\Model\ImportExportDefinition;
  12. use Pickware\PickwareErpStarter\ImportExport\Model\ImportExportEntity;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class IsDownloadReadyFieldCalculationSubscriber implements EventSubscriberInterface
  16. {
  17.     private const ALLOW_DOWNLOAD_STATES = [
  18.         ImportExportDefinition::STATE_COMPLETED,
  19.         ImportExportDefinition::STATE_COMPLETED_WITH_ERRORS,
  20.     ];
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             ImportExportDefinition::EVENT_LOADED => 'onImportExportLoaded',
  25.         ];
  26.     }
  27.     public function onImportExportLoaded(EntityLoadedEvent $event): void
  28.     {
  29.         /** @var ImportExportEntity $importExport */
  30.         foreach ($event->getEntities() as $importExport) {
  31.             $importExport->assign([
  32.                 'isDownloadReady' => false,
  33.             ]);
  34.             if (!$importExport->getDocumentId()) {
  35.                 continue;
  36.             }
  37.             if ($importExport->getType() === ImportExportDefinition::TYPE_IMPORT || (
  38.                     $importExport->getType() === ImportExportDefinition::TYPE_EXPORT
  39.                     && in_array($importExport->getState(), self::ALLOW_DOWNLOAD_STATES)
  40.                 )) {
  41.                 $importExport->assign([
  42.                     'isDownloadReady' => true,
  43.                 ]);
  44.             }
  45.         }
  46.     }
  47. }