activatePlugin example

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

            return 0;
        }

        if (!$plugin->getInstalled()) {
            $output->writeln(sprintf('The plugin %s has to be installed first.', $pluginName));

            return 1;
        }

        $activationContext = $pluginManager->activatePlugin($plugin);
        $output->writeln(sprintf('Plugin %s has been activated.', $pluginName));

        $this->clearCachesIfRequested($input$output$activationContext);

        return 0;
    }
}
$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);
        $output->writeln(sprintf('Plugin %s has been reinstalled successfully.', $pluginName));

        $this->clearCachesIfRequested($input$output$uninstallationContext$installationContext$activationContext);

        return 0;
    }
}

        $context = new ActivateContext($plugin$this->release->getVersion()$plugin->getVersion());
        if ($plugin->getActive()) {
            return $context;
        }

        if (!$plugin->getInstalled()) {
            throw new Exception(sprintf('Plugin "%s" has to be installed first before it can be activated.', $plugin->getName()));
        }

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

        $result = $this->legacyPluginInstaller->activatePlugin($plugin);
        $this->applyLegacyResultToContext($result$context);

        return $context;
    }

    /** * @throws Exception * * @return DeactivateContext */
if ($plugin->getInstalled()) {
            $output->writeln(sprintf('The plugin %s is already installed.', $pluginName));
        } else {
            $installationContext = $pluginManager->installPlugin($plugin);
            $output->writeln(sprintf('Plugin %s has been installed successfully.', $pluginName));
        }

        $activationContext = null;

        if ($input->getOption('activate')) {
            $activationContext = $pluginManager->activatePlugin($plugin);
            $output->writeln(sprintf('Plugin %s has been activated successfully.', $pluginName));
        }

        $this->clearCachesIfRequested($input$output$installationContext$activationContext);

        return 0;
    }
}
return;
        }

        $this->storeAppLifecycleService->uninstallExtension($technicalName$context$keepUserData);
    }

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

            return;
        }

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

    public function deactivate(string $type, string $technicalName, Context $context): void
    {
        if ($type === 'plugin') {
            $plugin = $this->pluginService->getPluginByName($technicalName$context);
            
$activatePlugins = $input->getOption('activate');

        $installedPluginCount = 0;
        foreach ($plugins as $plugin) {
            if ($input->getOption('reinstall') && $plugin->getInstalledAt()) {
                $this->pluginLifecycleService->uninstallPlugin($plugin$context);
            }

            if ($activatePlugins && $plugin->getInstalledAt() && $plugin->getActive() === false) {
                $io->note(sprintf('Plugin "%s" is already installed. Activating.', $plugin->getName()));
                $this->pluginLifecycleService->activatePlugin($plugin$context);

                continue;
            }

            if ($plugin->getInstalledAt()) {
                $io->note(sprintf('Plugin "%s" is already installed. Skipping.', $plugin->getName()));

                continue;
            }

            $activationSuffix = '';
            
private function activeHttpCache(Plugin $httpCache): void
    {
        /** @var InstallerService $service */
        $service = $this->get('shopware.plugin_manager');

        if (!$httpCache->getInstalled()) {
            $service->installPlugin($httpCache);
        }

        if (!$httpCache->getActive()) {
            $service->activatePlugin($httpCache);
        }
    }

    private function deactivateHttpCache(Plugin $httpCache): void
    {
        if (!$httpCache->getActive()) {
            return;
        }

        /** @var InstallerService $service */
        $service = $this->get('shopware.plugin_manager');
        

        }

        return $this->View()->assign('success', true);
    }

    public function activatePluginAction()
    {
        $plugin = $this->getPluginModel($this->Request()->getParam('technicalName'));

        try {
            $result = $this->pluginManager->activatePlugin($plugin);
            $this->View()->assign(['success' => true, 'result' => $result]);
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
        }
    }

    public function deactivatePluginAction()
    {
        $plugin = $this->getPluginModel($this->Request()->getParam('technicalName'));

        try {
            
public function testActivate(): void
    {
        $inactive = $this->getInstalledInactivePlugin();
        $this->insertPlugin($inactive);

        $loader = new DbalKernelPluginLoader($this->classLoader, null, $this->connection);
        $this->kernel = $this->makeKernel($loader);
        $this->kernel->boot();

        $lifecycleService = $this->makePluginLifecycleService();
        $lifecycleService->activatePlugin($inactive, Context::createDefaultContext());

        /** @var SwagTest $swagTestPlugin */
        $swagTestPlugin = $this->kernel->getPluginLoader()->getPluginInstances()->get($inactive->getBaseClass());
        static::assertNotNull($swagTestPlugin);

        // autowired         static::assertInstanceOf(SystemConfigService::class$swagTestPlugin->systemConfig);

        // manually set         static::assertSame($this->kernel->getContainer()->get('category.repository')$swagTestPlugin->categoryRepository);

        
$this->assertMigrationState($migrationCollection, 4, 1);

        return $migrationCollection;
    }

    /** * @depends testInstall */
    public function testActivate(MigrationCollection $migrationCollection): MigrationCollection
    {
        $migrationPlugin = $this->getMigrationTestPlugin();
        $this->pluginLifecycleService->activatePlugin($migrationPlugin$this->context);
        $this->assertMigrationState($migrationCollection, 4, 2);

        return $migrationCollection;
    }

    /** * @depends testActivate */
    public function testUpdate(MigrationCollection $migrationCollection): MigrationCollection
    {
        $migrationPlugin = $this->getMigrationTestPlugin();
        
$io->note(sprintf('Plugin "%s" must be installed. Skipping.', $plugin->getName()));

                continue;
            }

            if ($plugin->getActive()) {
                $io->note(sprintf('Plugin "%s" is already active. Skipping.', $plugin->getName()));

                continue;
            }

            $this->pluginLifecycleService->activatePlugin($plugin$context);
            ++$activatedPluginCount;

            $io->text(sprintf('Plugin "%s" has been activated successfully.', $plugin->getName()));
        }

        if ($activatedPluginCount !== 0) {
            $io->success(sprintf('Activated %d plugin(s).', $activatedPluginCount));
        }

        $this->handleClearCacheOption($input$io, 'activating');

        

        $this->updatePlugin($this->context);
    }

    public function testUpdatePluginThrowsIfPluginIsNotInstalled(): void
    {
        $this->updatePluginThrowsIfPluginIsNotInstalled($this->context);
    }

    public function testActivatePlugin(): void
    {
        $this->activatePlugin($this->context);
    }

    public function testActivatePluginThrowsException(): void
    {
        $this->activatePluginThrowsException($this->context);
    }

    public function testDeactivatePlugin(): void
    {
        $this->deactivatePlugin($this->context);
    }

    
$plugins = $this->getThirdPartyPluginsQuery()->getQuery()->getResult(AbstractQuery::HYDRATE_OBJECT);

        $pluginsInSafeMode = $this->getPluginsInSafeMode($plugins);

        $installer = $this->container->get(InstallerService::class);

        if ($pluginsInSafeMode) {
            foreach ($pluginsInSafeMode as $plugin) {
                $plugin->setInSafeMode(false);

                if (!$plugin->getActive()) {
                    $installer->activatePlugin($plugin);
                }
            }
            $this->container->get(ModelManager::class)->flush();
            $this->View()->assign(['success' => true, 'inSafeMode' => false]);

            return;
        }

        foreach ($plugins as $plugin) {
            if (!$plugin->getActive()) {
                continue;
            }
$this->pluginAclSubscriber->onAclRoleLoaded($event);

        /** @var AclRoleEntity $enrichedAclRole */
        $enrichedAclRole = $event->getEntities()[0];

        static::assertSame(['product.viewer', 'product:read']$enrichedAclRole->getPrivileges());
    }

    public function testAclPluginActivated(): void
    {
        $this->activatePlugin(self::PLUGIN_ACL_PRODUCT_VIEWER);

        $aclRoles = [$this->getAclRoleMock('pluginAclTestProductViewer', ['product.viewer', 'product:read'])];

        $event = new EntityLoadedEvent(
            $this->createMock(AclRoleDefinition::class),
            $aclRoles,
            Context::createDefaultContext()
        );

        $this->pluginAclSubscriber->onAclRoleLoaded($event);

        

        $pluginEntityMock = $this->getPluginEntityMock();
        $pluginEntityMock->setInstalledAt(new \DateTime());
        $pluginEntityMock->setActive(false);

        $context = Context::createDefaultContext();

        $this->cacheItemPoolInterfaceMock->method('getItem')->willReturn(new CacheItem());

        $this->pluginMock->expects(static::once())->method('activate');

        $this->pluginLifecycleService->activatePlugin($pluginEntityMock$context);

        $returnedEvents = $this->eventDispatcher->getEvents();

        static::assertInstanceOf(PluginPreActivateEvent::class$returnedEvents[0]);
        static::assertInstanceOf(PluginPostActivateEvent::class$returnedEvents[1]);
        static::assertTrue($pluginEntityMock->getActive());
    }

    public function testActivatePluginNotInstalled(): void
    {
        $pluginEntityMock = $this->getPluginEntityMock();
        
Home | Imprint | This part of the site doesn't use cookies.