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

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\Plugin\PluginLifecycleService;
  7. use Shopware\Core\Framework\Update\Event\UpdatePostFinishEvent;
  8. use Shopware\Core\System\SalesChannel\SalesChannelEntity;
  9. use Shopware\Storefront\Theme\ThemeCollection;
  10. use Shopware\Storefront\Theme\ThemeLifecycleService;
  11. use Shopware\Storefront\Theme\ThemeService;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. /**
  14.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  15.  */
  16. class UpdateSubscriber implements EventSubscriberInterface
  17. {
  18.     private ThemeService $themeService;
  19.     private ThemeLifecycleService $themeLifecycleService;
  20.     private EntityRepositoryInterface $salesChannelRepository;
  21.     /**
  22.      * @internal
  23.      */
  24.     public function __construct(
  25.         ThemeService $themeService,
  26.         ThemeLifecycleService $themeLifecycleService,
  27.         EntityRepositoryInterface $salesChannelRepository
  28.     ) {
  29.         $this->themeService $themeService;
  30.         $this->themeLifecycleService $themeLifecycleService;
  31.         $this->salesChannelRepository $salesChannelRepository;
  32.     }
  33.     /**
  34.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  35.      */
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             UpdatePostFinishEvent::class => 'updateFinished',
  40.         ];
  41.     }
  42.     /**
  43.      * @internal
  44.      */
  45.     public function updateFinished(UpdatePostFinishEvent $event): void
  46.     {
  47.         $context $event->getContext();
  48.         $this->themeLifecycleService->refreshThemes($context);
  49.         if ($context->hasState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING)) {
  50.             return;
  51.         }
  52.         $criteria = new Criteria();
  53.         $criteria->addFilter(new EqualsFilter('active'true));
  54.         $criteria->getAssociation('themes')
  55.             ->addFilter(new EqualsFilter('active'true));
  56.         $alreadyCompiled = [];
  57.         /** @var SalesChannelEntity $salesChannel */
  58.         foreach ($this->salesChannelRepository->search($criteria$context) as $salesChannel) {
  59.             $themes $salesChannel->getExtension('themes');
  60.             if (!$themes instanceof ThemeCollection) {
  61.                 continue;
  62.             }
  63.             foreach ($themes as $theme) {
  64.                 // NEXT-21735 - his is covered randomly
  65.                 // @codeCoverageIgnoreStart
  66.                 if (\in_array($theme->getId(), $alreadyCompiledtrue) !== false) {
  67.                     continue;
  68.                 }
  69.                 // @codeCoverageIgnoreEnd
  70.                 $alreadyCompiled += $this->themeService->compileThemeById($theme->getId(), $context);
  71.             }
  72.         }
  73.     }
  74. }