vendor/shopware/storefront/Theme/Subscriber/UpdateSubscriber.php line 46

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme\Subscriber;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\Update\Event\UpdatePostFinishEvent;
  7. use Shopware\Core\System\SalesChannel\SalesChannelEntity;
  8. use Shopware\Storefront\Theme\ThemeCollection;
  9. use Shopware\Storefront\Theme\ThemeLifecycleService;
  10. use Shopware\Storefront\Theme\ThemeService;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class UpdateSubscriber implements EventSubscriberInterface
  13. {
  14.     private ThemeService $themeService;
  15.     private ThemeLifecycleService $themeLifecycleService;
  16.     private EntityRepositoryInterface $salesChannelRepository;
  17.     public function __construct(
  18.         ThemeService $themeService,
  19.         ThemeLifecycleService $themeLifecycleService,
  20.         EntityRepositoryInterface $salesChannelRepository
  21.     ) {
  22.         $this->themeService $themeService;
  23.         $this->themeLifecycleService $themeLifecycleService;
  24.         $this->salesChannelRepository $salesChannelRepository;
  25.     }
  26.     /**
  27.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  28.      */
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             UpdatePostFinishEvent::class => 'updateFinished',
  33.         ];
  34.     }
  35.     /**
  36.      * @internal
  37.      */
  38.     public function updateFinished(UpdatePostFinishEvent $event): void
  39.     {
  40.         $context $event->getContext();
  41.         $this->themeLifecycleService->refreshThemes($context);
  42.         $criteria = new Criteria();
  43.         $criteria->addFilter(new EqualsFilter('active'true));
  44.         $criteria->getAssociation('themes')
  45.             ->addFilter(new EqualsFilter('active'true));
  46.         /** @var SalesChannelEntity $salesChannel */
  47.         foreach ($this->salesChannelRepository->search($criteria$context) as $salesChannel) {
  48.             $themes $salesChannel->getExtension('themes');
  49.             if (!$themes instanceof ThemeCollection) {
  50.                 continue;
  51.             }
  52.             foreach ($themes as $theme) {
  53.                 $salesChannelId $salesChannel->getId();
  54.                 $this->themeService->compileTheme($salesChannelId$theme->getId(), $context);
  55.             }
  56.         }
  57.     }
  58. }