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

  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\EntityRepository;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Shopware\Storefront\Theme\ThemeLifecycleService;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10.  * @internal
  11.  */
  12. #[Package('storefront')]
  13. class AppLifecycleSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @internal
  17.      */
  18.     public function __construct(
  19.         private readonly ThemeLifecycleService $themeLifecycleService,
  20.         private readonly EntityRepository $appRepository
  21.     ) {
  22.     }
  23.     /**
  24.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  25.      */
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             AppDeletedEvent::class => 'onAppDeleted',
  30.         ];
  31.     }
  32.     public function onAppDeleted(AppDeletedEvent $event): void
  33.     {
  34.         if ($event->keepUserData()) {
  35.             return;
  36.         }
  37.         $app $this->appRepository->search((new Criteria([$event->getAppId()])), $event->getContext())->first();
  38.         if ($app === null) {
  39.             return;
  40.         }
  41.         $this->themeLifecycleService->removeTheme($app->getName(), $event->getContext());
  42.     }
  43. }