platform/src/Storefront/Theme/Subscriber/AppLifecycleSubscriber.php line 30

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.     public function __construct(ThemeLifecycleService $themeLifecycleServiceEntityRepositoryInterface $appRepository)
  13.     {
  14.         $this->themeLifecycleService $themeLifecycleService;
  15.         $this->appRepository $appRepository;
  16.     }
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [
  20.             AppDeletedEvent::class => 'onAppDeleted',
  21.         ];
  22.     }
  23.     public function onAppDeleted(AppDeletedEvent $event): void
  24.     {
  25.         if ($event->keepUserData()) {
  26.             return;
  27.         }
  28.         $app $this->appRepository->search((new Criteria([$event->getAppId()])), $event->getContext())->first();
  29.         if ($app === null) {
  30.             return;
  31.         }
  32.         $this->themeLifecycleService->removeTheme($app->getName(), $event->getContext());
  33.     }
  34. }