vendor/shopware/storefront/Theme/Subscriber/AppLifecycleSubscriber.php line 36

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme\Subscriber;
  3. use Shopware\Core\Framework\App\Event\AppDeletedEvent;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Storefront\Theme\ThemeLifecycleService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class AppLifecycleSubscriber implements EventSubscriberInterface
  9. {
  10.     private ThemeLifecycleService $themeLifecycleService;
  11.     private EntityRepositoryInterface $appRepository;
  12.     /**
  13.      * @internal
  14.      */
  15.     public function __construct(ThemeLifecycleService $themeLifecycleServiceEntityRepositoryInterface $appRepository)
  16.     {
  17.         $this->themeLifecycleService $themeLifecycleService;
  18.         $this->appRepository $appRepository;
  19.     }
  20.     /**
  21.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  22.      */
  23.     public static function getSubscribedEvents()
  24.     {
  25.         return [
  26.             AppDeletedEvent::class => 'onAppDeleted',
  27.         ];
  28.     }
  29.     public function onAppDeleted(AppDeletedEvent $event): void
  30.     {
  31.         if ($event->keepUserData()) {
  32.             return;
  33.         }
  34.         $app $this->appRepository->search((new Criteria([$event->getAppId()])), $event->getContext())->first();
  35.         if ($app === null) {
  36.             return;
  37.         }
  38.         $this->themeLifecycleService->removeTheme($app->getName(), $event->getContext());
  39.     }
  40. }