vendor/shopware/core/Content/ImportExport/DataAbstractionLayer/ImportExportLogValidator.php line 28

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\ImportExport\DataAbstractionLayer;
  3. use Shopware\Core\Content\ImportExport\Aggregate\ImportExportLog\ImportExportLogDefinition;
  4. use Shopware\Core\Content\ImportExport\Exception\LogNotWritableException;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Write\Validation\PreWriteValidationEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. /**
  9.  * @internal
  10.  *
  11.  * @deprecated tag:v6.3.0 can be replaced with Definition::getProtections()
  12.  */
  13. class ImportExportLogValidator implements EventSubscriberInterface
  14. {
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             PreWriteValidationEvent::class => 'preValidate',
  19.         ];
  20.     }
  21.     /**
  22.      * @internal
  23.      */
  24.     public function preValidate(PreWriteValidationEvent $event): void
  25.     {
  26.         $ids = [];
  27.         $writeCommands $event->getCommands();
  28.         foreach ($writeCommands as $command) {
  29.             if ($command->getDefinition()->getClass() === ImportExportLogDefinition::class
  30.                 && $event->getContext()->getScope() !== Context::SYSTEM_SCOPE
  31.             ) {
  32.                 $ids[] = $command->getPrimaryKey()['id'];
  33.             }
  34.         }
  35.         if (!empty($ids)) {
  36.             $event->getExceptions()->add(new LogNotWritableException($ids));
  37.         }
  38.     }
  39. }