vendor/shopware/core/Content/ImportExport/DataAbstractionLayer/SystemDefaultValidator.php line 39

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\ImportExport\DataAbstractionLayer;
  3. use Doctrine\DBAL\Connection;
  4. use Doctrine\DBAL\FetchMode;
  5. use Shopware\Core\Content\ImportExport\Exception\DeleteDefaultProfileException;
  6. use Shopware\Core\Content\ImportExport\ImportExportProfileDefinition;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Write\Command\DeleteCommand;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Write\Validation\PreWriteValidationEvent;
  9. use Shopware\Core\Framework\Log\Package;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. /**
  12.  * @internal
  13.  */
  14. #[Package('system-settings')]
  15. class SystemDefaultValidator implements EventSubscriberInterface
  16. {
  17.     private Connection $connection;
  18.     public function __construct(Connection $connection)
  19.     {
  20.         $this->connection $connection;
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             PreWriteValidationEvent::class => 'preValidate',
  26.         ];
  27.     }
  28.     /**
  29.      * @internal
  30.      *
  31.      * @throws DeleteDefaultProfileException
  32.      */
  33.     public function preValidate(PreWriteValidationEvent $event): void
  34.     {
  35.         $ids = [];
  36.         $writeCommands $event->getCommands();
  37.         foreach ($writeCommands as $command) {
  38.             if ($command->getDefinition()->getClass() === ImportExportProfileDefinition::class
  39.                 && $command instanceof DeleteCommand
  40.             ) {
  41.                 $ids[] = $command->getPrimaryKey()['id'];
  42.             }
  43.         }
  44.         $filteredIds $this->filterSystemDefaults($ids);
  45.         if (!empty($filteredIds)) {
  46.             $event->getExceptions()->add(new DeleteDefaultProfileException($filteredIds));
  47.         }
  48.     }
  49.     private function filterSystemDefaults(array $ids): array
  50.     {
  51.         if (empty($ids)) {
  52.             return [];
  53.         }
  54.         $result $this->connection->executeQuery(
  55.             'SELECT id FROM import_export_profile WHERE id IN (:idList) AND system_default = 1',
  56.             ['idList' => $ids],
  57.             ['idList' => Connection::PARAM_STR_ARRAY]
  58.         );
  59.         return $result->fetchAll(FetchMode::COLUMN);
  60.     }
  61. }