src/Subscriber/FirstRunWizardSubscriber.php line 46

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Production\Subscriber;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\Plugin\PluginLifecycleService;
  8. use Shopware\Core\Framework\Plugin\PluginManagementService;
  9. use Shopware\Core\Framework\Store\Event\FirstRunWizardFinishedEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class FirstRunWizardSubscriber implements EventSubscriberInterface
  12. {
  13.     private const DELETABLE_PLUGINS = [
  14.         'SwagMarkets',
  15.         'SwagPayPal'
  16.     ];
  17.     private PluginLifecycleService $pluginLifecycleService;
  18.     private string $projectDir;
  19.     private EntityRepositoryInterface $pluginRepository;
  20.     private Context $context;
  21.     private PluginManagementService $pluginManagementService;
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return [FirstRunWizardFinishedEvent::class => 'onFirstRunWizardFinished'];
  25.     }
  26.     public function __construct(
  27.         string $projectDir,
  28.         PluginLifecycleService $pluginLifecycleService,
  29.         PluginManagementService $pluginManagementService,
  30.         EntityRepositoryInterface $pluginRepository
  31.     )
  32.     {
  33.         $this->pluginLifecycleService $pluginLifecycleService;
  34.         $this->projectDir $projectDir;
  35.         $this->pluginRepository $pluginRepository;
  36.         $this->context Context::createDefaultContext();
  37.         $this->pluginManagementService $pluginManagementService;
  38.     }
  39.     public function onFirstRunWizardFinished(FirstRunWizardFinishedEvent $event)
  40.     {
  41.         foreach (self::DELETABLE_PLUGINS as $plugin) {
  42.             try {
  43.                 $criteria = new Criteria();
  44.                 $criteria->addFilter(new EqualsFilter('name'$plugin));
  45.                 $plugin $this->pluginRepository->search($criteria$this->context)->first();
  46.                 $this->pluginLifecycleService->uninstallPlugin($plugin$this->contextfalse);
  47.                 $this->pluginManagementService->deletePlugin($plugin$this->context);
  48.             } catch (\Throwable $e) {
  49.             }
  50.         }
  51.     }
  52. }