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

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.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(
  21.         ThemeService $themeService,
  22.         ThemeLifecycleService $themeLifecycleService,
  23.         EntityRepositoryInterface $salesChannelRepository
  24.     ) {
  25.         $this->themeService $themeService;
  26.         $this->themeLifecycleService $themeLifecycleService;
  27.         $this->salesChannelRepository $salesChannelRepository;
  28.     }
  29.     /**
  30.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  31.      */
  32.     public static function getSubscribedEvents()
  33.     {
  34.         return [
  35.             UpdatePostFinishEvent::class => 'updateFinished',
  36.         ];
  37.     }
  38.     /**
  39.      * @internal
  40.      */
  41.     public function updateFinished(UpdatePostFinishEvent $event): void
  42.     {
  43.         $context $event->getContext();
  44.         $this->themeLifecycleService->refreshThemes($context);
  45.         $criteria = new Criteria();
  46.         $criteria->addFilter(new EqualsFilter('active'true));
  47.         $criteria->getAssociation('themes')
  48.             ->addFilter(new EqualsFilter('active'true));
  49.         $alreadyCompiled = [];
  50.         /** @var SalesChannelEntity $salesChannel */
  51.         foreach ($this->salesChannelRepository->search($criteria$context) as $salesChannel) {
  52.             $themes $salesChannel->getExtension('themes');
  53.             if (!$themes instanceof ThemeCollection) {
  54.                 continue;
  55.             }
  56.             foreach ($themes as $theme) {
  57.                 // NEXT-21735 - his is covered randomly
  58.                 // @codeCoverageIgnoreStart
  59.                 if (\in_array($theme->getId(), $alreadyCompiledtrue) !== false) {
  60.                     continue;
  61.                 }
  62.                 // @codeCoverageIgnoreEnd
  63.                 $alreadyCompiled += $this->themeService->compileThemeById($theme->getId(), $context);
  64.             }
  65.         }
  66.     }
  67. }