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

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\Storefront\Theme\ThemeEntity;
  8. use Shopware\Storefront\Theme\ThemeLifecycleService;
  9. use Shopware\Storefront\Theme\ThemeService;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class UpdateSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var ThemeService
  15.      */
  16.     private $themeService;
  17.     /**
  18.      * @var ThemeLifecycleService
  19.      */
  20.     private $themeLifecycleService;
  21.     /**
  22.      * @var EntityRepositoryInterface
  23.      */
  24.     private $themeRepository;
  25.     public function __construct(
  26.         ThemeService $themeService,
  27.         ThemeLifecycleService $themeLifecycleService,
  28.         EntityRepositoryInterface $themeRepository
  29.     ) {
  30.         $this->themeService $themeService;
  31.         $this->themeLifecycleService $themeLifecycleService;
  32.         $this->themeRepository $themeRepository;
  33.     }
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             UpdatePostFinishEvent::class => 'updateFinished',
  38.         ];
  39.     }
  40.     /**
  41.      * @internal
  42.      */
  43.     public function updateFinished(UpdatePostFinishEvent $event): void
  44.     {
  45.         $context $event->getContext();
  46.         $this->themeLifecycleService->refreshThemes($context);
  47.         $criteria = new Criteria();
  48.         $criteria->addAssociation('salesChannels');
  49.         $criteria->addFilter(new EqualsFilter('technicalName''Storefront'));
  50.         /** @var ThemeEntity|null $theme */
  51.         $theme $this->themeRepository->search($criteria$context)->first();
  52.         if (!$theme) {
  53.             throw new \RuntimeException('Default theme not found');
  54.         }
  55.         foreach ($theme->getSalesChannels() as $salesChannel) {
  56.             $salesChannelId $salesChannel->getId();
  57.             $this->themeService->compileTheme($salesChannelId$theme->getId(), $context);
  58.         }
  59.     }
  60. }