src/Storefront/Theme/Subscriber/AppLifecycleSubscriber.php line 35

  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(private readonly ThemeLifecycleService $themeLifecycleService, private readonly EntityRepository $appRepository)
  19.     {
  20.     }
  21.     /**
  22.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  23.      */
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             AppDeletedEvent::class => 'onAppDeleted',
  28.         ];
  29.     }
  30.     public function onAppDeleted(AppDeletedEvent $event): void
  31.     {
  32.         if ($event->keepUserData()) {
  33.             return;
  34.         }
  35.         $app $this->appRepository->search((new Criteria([$event->getAppId()])), $event->getContext())->first();
  36.         if ($app === null) {
  37.             return;
  38.         }
  39.         $this->themeLifecycleService->removeTheme($app->getName(), $event->getContext());
  40.     }
  41. }