vendor/shopware/platform/src/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.         $alreadyCompiled = [];
  47.         /** @var SalesChannelEntity $salesChannel */
  48.         foreach ($this->salesChannelRepository->search($criteria$context) as $salesChannel) {
  49.             $themes $salesChannel->getExtension('themes');
  50.             if (!$themes instanceof ThemeCollection) {
  51.                 continue;
  52.             }
  53.             foreach ($themes as $theme) {
  54.                 if (\in_array($theme->getId(), $alreadyCompiledtrue) !== false) {
  55.                     continue;
  56.                 }
  57.                 $alreadyCompiled += $this->themeService->compileThemeById($theme->getId(), $context);
  58.             }
  59.         }
  60.     }
  61. }