vendor/shopware/core/Content/Flow/Dispatching/Action/RemoveCustomerTagAction.php line 61

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Flow\Dispatching\Action;
  3. use Shopware\Core\Content\Flow\Dispatching\DelayableAction;
  4. use Shopware\Core\Content\Flow\Dispatching\StorableFlow;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  7. use Shopware\Core\Framework\Event\CustomerAware;
  8. use Shopware\Core\Framework\Event\FlowEvent;
  9. use Shopware\Core\Framework\Feature;
  10. use Shopware\Core\Framework\Log\Package;
  11. /**
  12.  * @deprecated tag:v6.5.0 - reason:remove-subscriber - FlowActions won't be executed over the event system anymore,
  13.  * therefore the actions won't implement the EventSubscriberInterface anymore.
  14.  */
  15. #[Package('business-ops')]
  16. class RemoveCustomerTagAction extends FlowAction implements DelayableAction
  17. {
  18.     private EntityRepositoryInterface $customerTagRepository;
  19.     /**
  20.      * @internal
  21.      */
  22.     public function __construct(EntityRepositoryInterface $customerTagRepository)
  23.     {
  24.         $this->customerTagRepository $customerTagRepository;
  25.     }
  26.     public static function getName(): string
  27.     {
  28.         return 'action.remove.customer.tag';
  29.     }
  30.     /**
  31.      * @deprecated tag:v6.5.0 - reason:remove-subscriber - Will be removed
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         if (Feature::isActive('v6.5.0.0')) {
  36.             return [];
  37.         }
  38.         return [
  39.             self::getName() => 'handle',
  40.         ];
  41.     }
  42.     /**
  43.      * @return array<int, string>
  44.      */
  45.     public function requirements(): array
  46.     {
  47.         return [CustomerAware::class];
  48.     }
  49.     /**
  50.      * @deprecated tag:v6.5.0 Will be removed, implement handleFlow instead
  51.      */
  52.     public function handle(FlowEvent $event): void
  53.     {
  54.         Feature::triggerDeprecationOrThrow(
  55.             'v6.5.0.0',
  56.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0')
  57.         );
  58.         $baseEvent $event->getEvent();
  59.         if (!$baseEvent instanceof CustomerAware) {
  60.             return;
  61.         }
  62.         $this->update($baseEvent->getContext(), $event->getConfig(), $baseEvent->getCustomerId());
  63.     }
  64.     public function handleFlow(StorableFlow $flow): void
  65.     {
  66.         if (!$flow->hasStore(CustomerAware::CUSTOMER_ID)) {
  67.             return;
  68.         }
  69.         $this->update($flow->getContext(), $flow->getConfig(), $flow->getStore(CustomerAware::CUSTOMER_ID));
  70.     }
  71.     /**
  72.      * @param array<string, mixed> $config
  73.      */
  74.     private function update(Context $context, array $configstring $customerId): void
  75.     {
  76.         if (!\array_key_exists('tagIds'$config)) {
  77.             return;
  78.         }
  79.         $tagIds array_keys($config['tagIds']);
  80.         if (empty($tagIds)) {
  81.             return;
  82.         }
  83.         $tags array_map(static function ($tagId) use ($customerId) {
  84.             return [
  85.                 'customerId' => $customerId,
  86.                 'tagId' => $tagId,
  87.             ];
  88.         }, $tagIds);
  89.         $this->customerTagRepository->delete($tags$context);
  90.     }
  91. }