getPluginByName example

/** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var InstallerService $pluginManager */
        $pluginManager = $this->container->get(InstallerService::class);
        $pluginName = $input->getArgument('plugin');

        try {
            $plugin = $pluginManager->getPluginByName($pluginName);
        } catch (Exception $e) {
            $output->writeln(sprintf('Plugin by name "%s" was not found.', $pluginName));

            return 1;
        }

        if (!$plugin->getInstalled()) {
            $output->writeln(sprintf('The plugin %s is already uninstalled.', $pluginName));

            return 1;
        }

        
/** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var InstallerService $pluginManager */
        $pluginManager = $this->container->get(InstallerService::class);
        $pluginName = $input->getArgument('plugin');

        try {
            $plugin = $pluginManager->getPluginByName($pluginName);
        } catch (Exception $e) {
            $output->writeln(sprintf('Plugin by name "%s" was not found.', $pluginName));

            return 1;
        }

        if ($plugin->getInstalled()) {
            $output->writeln('The Plugin has to be uninstalled first.');

            return 1;
        }

        
$this->pluginFinder
        );

        $this->addTestPluginToKernel(
            __DIR__ . '/_fixtures/plugins/' . self::PLUGIN_NAME,
            self::PLUGIN_NAME
        );

        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $this->pluginLifecycleService->installPlugin(
            $this->pluginService->getPluginByName(
                self::PLUGIN_NAME,
                $this->context
            ),
            $this->context
        );

        $installedPlugin = $this->pluginService->getPluginByName(self::PLUGIN_NAME, $this->context);
        static::assertNotNull($installedPlugin->getInstalledAt());

        return $installedPlugin;
    }

    
/** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var InstallerService $pluginManager */
        $pluginManager = $this->container->get(InstallerService::class);
        $pluginName = $input->getArgument('plugin');

        try {
            $plugin = $pluginManager->getPluginByName($pluginName);
        } catch (Exception $e) {
            $output->writeln(sprintf('Plugin by name "%s" was not found.', $pluginName));

            return 1;
        }

        if ($plugin->getActive()) {
            $output->writeln(sprintf('The plugin %s is already activated.', $pluginName));

            return 0;
        }

        
protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var InstallerService $pluginManager */
        $pluginManager = $this->container->get(InstallerService::class);
        if (!$input->getOption('no-refresh')) {
            $pluginManager->refreshPluginList();
            $output->writeln('Successfully refreshed');
        }
        $pluginName = $input->getArgument('plugin');

        try {
            $plugin = $pluginManager->getPluginByName($pluginName);
        } catch (Exception $e) {
            $output->writeln(sprintf('Plugin by name "%s" was not found.', $pluginName));

            return 1;
        }

        $installationContext = null;

        if ($plugin->getInstalled()) {
            $output->writeln(sprintf('The plugin %s is already installed.', $pluginName));
        } else {
            


    /** * @param string $pluginName * * @throws Exception * * @return string */
    public function getPluginPath($pluginName)
    {
        $plugin = $this->getPluginByName($pluginName);

        if (!$plugin->isLegacyPlugin()) {
            return $this->pluginInstaller->getPluginPath($plugin);
        }

        return $this->legacyPluginInstaller->getPluginPath($plugin);
    }

    /** * @param string $pluginName * * @throws Exception * * @return Plugin */
protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var InstallerService $pluginManager */
        $pluginManager = $this->container->get(\Shopware\Bundle\PluginInstallerBundle\Service\InstallerService::class);
        if (!$input->getOption('no-refresh')) {
            $pluginManager->refreshPluginList();
            $output->writeln('Successfully refreshed');
        }
        $pluginName = $input->getArgument('plugin');

        try {
            $plugin = $pluginManager->getPluginByName($pluginName);
        } catch (Exception $e) {
            $output->writeln(sprintf('Plugin by name "%s" was not found.', $pluginName));

            return 1;
        }

        $removeData = $input->getOption('removedata');

        $uninstallationContext = $pluginManager->uninstallPlugin($plugin$removeData);
        $installationContext = $pluginManager->installPlugin($plugin);
        $activationContext = $pluginManager->activatePlugin($plugin);
        

    protected $configData = [];

    /** * get productive mode */
    public function getProductiveModeAction()
    {
        $httpCache = $this->getPluginByName('HttpCache');

        $active = $httpCache->getActive() && $httpCache->getInstalled() != null;

        $this->View()->assign([
            'success' => true,
            'productiveMode' => $active,
        ]);
    }

    /** * Set productive mode true or false * Enable and disable caching by enable or disable plugin 'HttpCache' */


    /** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $pluginManager = $this->container->get(InstallerService::class);
        $pluginName = $input->getArgument('plugin');

        try {
            $plugin = $pluginManager->getPluginByName($pluginName);
        } catch (Exception $e) {
            $output->writeln(sprintf('Plugin by name "%s" was not found.', $pluginName));

            return 1;
        }
        $em = $this->container->get(ModelManager::class);

        $shops = null;
        $shopId = null;

        if ($input->getOption('shop')) {
            
/** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var InstallerService $pluginManager */
        $pluginManager = $this->container->get(InstallerService::class);
        $pluginName = $input->getArgument('plugin');

        try {
            $plugin = $pluginManager->getPluginByName($pluginName);
        } catch (Exception $e) {
            $output->writeln(sprintf('Plugin by name "%s" was not found.', $pluginName));

            return 1;
        }

        if (!$plugin->getActive()) {
            $output->writeln(sprintf('The plugin %s is already deactivated.', $pluginName));

            return 1;
        }

        
/** @var PluginEntity $plugin */
        $plugin = $pluginCollection->filterByProperty('baseClass', SwagTest::class)->first();

        $this->assertDefaultPlugin($plugin);
        static::assertNull($plugin->getUpgradeVersion());
    }

    public function testGetPluginByName(): void
    {
        $this->createPlugin($this->pluginRepo, $this->context);

        $plugin = $this->pluginService->getPluginByName('SwagTest', $this->context);

        $this->assertDefaultPlugin($plugin);
    }

    public function testGetPluginByNameThrowsException(): void
    {
        $this->createPlugin($this->pluginRepo, $this->context);

        $this->expectException(PluginNotFoundException::class);
        $this->expectExceptionMessage('Plugin by name "SwagFoo" not found');
        $this->pluginService->getPluginByName('SwagFoo', $this->context);
    }
$this->logger = $logger;
        $this->kernel = $kernel;
    }

    /** * @throws Exception * * @return InstallContext */
    public function installPlugin(Plugin $plugin)
    {
        $pluginBootstrap = $this->getPluginByName($plugin->getName());

        $context = new InstallContext($plugin$this->release->getVersion()$plugin->getVersion());

        $this->requirementValidator->validate($pluginBootstrap->getPath() . '/plugin.xml', $this->release->getVersion());

        $this->events->notify(PluginEvent::PRE_INSTALL, new PrePluginInstallEvent($context$pluginBootstrap));
        $this->installResources($pluginBootstrap$plugin);

        // Makes sure the version is updated in the db after a re-installation         if ($plugin->getUpdateVersion() && $this->hasInfoNewerVersion($plugin->getUpdateVersion()$plugin->getVersion())) {
            $plugin->setVersion($plugin->getUpdateVersion());
        }
static::assertFalse($plugin->getActive());
    }

    public function testDeactivatePluginWithDependencies(): void
    {
        $this->addTestPluginToKernel(
            __DIR__ . '/_fixture/plugins/' . self::DEPENDENT_PLUGIN_NAME,
            self::DEPENDENT_PLUGIN_NAME
        );
        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $basePlugin = $this->pluginService->getPluginByName(self::PLUGIN_NAME, $this->context);
        $this->pluginLifecycleService->installPlugin($basePlugin$this->context);
        $this->pluginLifecycleService->activatePlugin($basePlugin$this->context);

        $dependentPlugin = $this->pluginService->getPluginByName(self::DEPENDENT_PLUGIN_NAME, $this->context);
        $this->pluginLifecycleService->installPlugin($dependentPlugin$this->context);
        $this->pluginLifecycleService->activatePlugin($dependentPlugin$this->context);

        $this->expectException(PluginHasActiveDependantsException::class);

        try {
            $this->pluginLifecycleService->deactivatePlugin($basePlugin$this->context);
        }
public function __construct(
        private readonly AbstractStoreAppLifecycleService $storeAppLifecycleService,
        private readonly PluginService $pluginService,
        private readonly PluginLifecycleService $pluginLifecycleService,
        private readonly PluginManagementService $pluginManagementService
    ) {
    }

    public function install(string $type, string $technicalName, Context $context): void
    {
        if ($type === 'plugin') {
            $plugin = $this->pluginService->getPluginByName($technicalName$context);
            $this->pluginLifecycleService->installPlugin($plugin$context);

            return;
        }

        $this->storeAppLifecycleService->installExtension($technicalName$context);
    }

    public function update(string $type, string $technicalName, bool $allowNewPermissions, Context $context): void
    {
        if ($type === 'plugin') {
            
$this->container->get(CustomEntityPersister::class),
            $this->container->get(CustomEntitySchemaUpdater::class),
            $this->container->get(CustomEntityLifecycleService::class),
            $this->container->get(PluginService::class),
            $this->container->get(VersionSanitizer::class),
        );
    }

    private function getMigrationTestPlugin(): PluginEntity
    {
        return $this->pluginService
            ->getPluginByName('SwagManualMigrationTest', $this->context);
    }

    private function requireMigrationFiles(): void
    {
        require_once __DIR__ . '/_fixture/plugins/SwagManualMigrationTest/src/Migration/Migration1.php';
        require_once __DIR__ . '/_fixture/plugins/SwagManualMigrationTest/src/Migration/Migration2.php';
        require_once __DIR__ . '/_fixture/plugins/SwagManualMigrationTest/src/Migration/Migration3.php';
        require_once __DIR__ . '/_fixture/plugins/SwagManualMigrationTest/src/Migration/Migration4.php';
    }
}
Home | Imprint | This part of the site doesn't use cookies.