custom/plugins/NewsletterSendinblue/src/Subscriber/EntitySubscriber.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace NewsletterSendinblue\Subscriber;
  3. use Shopware\Core\Content\Category\Aggregate\CategoryTranslation\CategoryTranslationDefinition;
  4. use Shopware\Core\Content\Category\CategoryDefinition;
  5. use Shopware\Core\Content\Product\Aggregate\ProductTranslation\ProductTranslationDefinition;
  6. use Shopware\Core\Content\Product\ProductDefinition;
  7. use Shopware\Core\Defaults;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Write\Command\ChangeSetAware;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Write\Command\UpdateCommand;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Write\Validation\PreWriteValidationEvent;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class EntitySubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @return string[]
  16.      */
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [
  20.             PreWriteValidationEvent::class => 'triggerChangeSet',
  21.         ];
  22.     }
  23.     /**
  24.      * @param PreWriteValidationEvent $event
  25.      * @return void
  26.      */
  27.     public function triggerChangeSet(PreWriteValidationEvent $event): void
  28.     {
  29.         if ($event->getContext()->getVersionId() !== Defaults::LIVE_VERSION) {
  30.             return;
  31.         }
  32.         foreach ($event->getCommands() as $command) {
  33.             if (!$command instanceof ChangeSetAware) {
  34.                 continue;
  35.             }
  36.             if (($command->getDefinition()->getEntityName() === ProductDefinition::ENTITY_NAME
  37.                     || $command->getDefinition()->getEntityName() === ProductTranslationDefinition::ENTITY_NAME
  38.                     || $command->getDefinition()->getEntityName() === CategoryDefinition::ENTITY_NAME
  39.                     || $command->getDefinition()->getEntityName() === CategoryTranslationDefinition::ENTITY_NAME)
  40.                 && $command instanceof UpdateCommand
  41.             ) {
  42.                 $command->requestChangeSet();
  43.             }
  44.         }
  45.     }
  46. }