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

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