deactivatePlugin example

$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;
        }

        $deactivationContext = $pluginManager->deactivatePlugin($plugin);
        $output->writeln(sprintf('Plugin %s has been deactivated', $pluginName));

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

        return 0;
    }
}
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);
            $this->pluginLifecycleService->deactivatePlugin($plugin$context);

            return;
        }

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

    public function remove(string $type, string $technicalName, Context $context): void
    {
        if ($type === 'plugin') {
            $plugin = $this->pluginService->getPluginByName($technicalName$context);
            
$io->note(sprintf('Plugin "%s" must be installed. Skipping.', $plugin->getName()));

                continue;
            }

            if ($plugin->getActive() === false) {
                $io->note(sprintf('Plugin "%s" must be activated. Skipping.', $plugin->getName()));

                continue;
            }

            $this->pluginLifecycleService->deactivatePlugin($plugin$context);
            ++$deactivatedPluginCount;

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

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

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

        
$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 {
            $result = $this->pluginManager->deactivatePlugin($plugin);
            $this->View()->assign(['success' => true, 'result' => $result]);
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
        }
    }

    public function uploadAction()
    {
        /** @var DownloadService $pluginDownloadService */
        $pluginDownloadService = Shopware()->Container()->get('shopware_plugininstaller.plugin_download_service');

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

        return $migrationCollection;
    }

    /** * @depends testUpdate */
    public function testDeactivate(MigrationCollection $migrationCollection): MigrationCollection
    {
        $migrationPlugin = $this->getMigrationTestPlugin();
        $this->pluginLifecycleService->deactivatePlugin($migrationPlugin$this->context);
        $this->assertMigrationState($migrationCollection, 4, 3, 1);

        return $migrationCollection;
    }

    /** * @depends testDeactivate */
    public function testUninstallKeepUserData(MigrationCollection $migrationCollection): void
    {
        $migrationPlugin = $this->getMigrationTestPlugin();
        
$this->container->get(ModelManager::class)->flush();
            $this->View()->assign(['success' => true, 'inSafeMode' => false]);

            return;
        }

        foreach ($plugins as $plugin) {
            if (!$plugin->getActive()) {
                continue;
            }
            $plugin->setInSafeMode(true);
            $installer->deactivatePlugin($plugin);
        }
        $this->container->get(ModelManager::class)->flush();

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

    /** * @return void */
    public function isInSafeModeAction()
    {
        
public function testDeactivatePlugin(): void
    {
        $pluginEntityMock = $this->getPluginEntityMock();
        $pluginEntityMock->setInstalledAt(new \DateTime());
        $pluginEntityMock->setActive(true);
        $context = Context::createDefaultContext();

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

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

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

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

        static::assertArrayHasKey('0', $returnedEvents);
        static::assertInstanceOf(PluginPreDeactivateEvent::class$returnedEvents[0]);
        static::assertArrayHasKey('1', $returnedEvents);
        static::assertInstanceOf(PluginPostDeactivateEvent::class$returnedEvents[1]);
        static::assertFalse($pluginEntityMock->getActive());
    }

    public function testDeactivatePluginNotInstalled(): void
    {

    public function deactivatePlugin(Plugin $plugin)
    {
        $context = new DeactivateContext($plugin$this->release->getVersion()$plugin->getVersion());
        if (!$plugin->getActive()) {
            return $context;
        }

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

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

        return $context;
    }

    /** * @return array */
    
$this->io->text(sprintf('No update available for plugin %s', $plugin->getLabel()));

            return;
        }

        $this->io->comment(sprintf('Download plugin update package %s', $plugin->getLabel()));

        $request = new DownloadRequest($plugin->getTechnicalName()$version$domain, null);

        $model = $this->getPluginModel($plugin->getTechnicalName());
        if ($plugin->isActive()) {
            $this->container->get(InstallerService::class)->deactivatePlugin($model);
        }

        $this->container->get('shopware_plugininstaller.plugin_download_service')
            ->download($request);
    }

    /** * @param string $version * @param string $domain * * @throws Exception */

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

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

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

    public function testDeactivatePluginNotInstalledThrowsException(): void
    {
        $this->deactivatePluginNotInstalledThrowsException($this->context);
    }

    public function testDeactivatePluginNotActivatedThrowsException(): void
    {
        $this->deactivatePluginNotActivatedThrowsException($this->context);
    }

    
$pluginCollection = $this->createMock(KernelPluginCollection::class);

        $pluginCollection
            ->method('getActives')
            ->willReturnCallback(fn () => array_filter($this->plugins, static fn (Plugin $plugin) => $plugin->isActive()));

        $this->pluginAclSubscriber = new PluginAclPrivilegesSubscriber($pluginCollection);
    }

    public function testAclPluginDeactivated(): void
    {
        $this->deactivatePlugin(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);

        

    }

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

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

    private function getPluginByName(string $name): ?Plugin
    {
        /** @var Plugin|null $return */
        $return = $this->get(ModelManager::class)
            ->getRepository(Plugin::class)
            ->findOneBy(['name' => $name]);

        return $return;
    }

    

    public function uninstallPlugin(
        PluginEntity $plugin,
        Context $shopwareContext,
        bool $keepUserData = false
    ): UninstallContext {
        if ($plugin->getInstalledAt() === null) {
            throw new PluginNotInstalledException($plugin->getName());
        }

        if ($plugin->getActive()) {
            $this->deactivatePlugin($plugin$shopwareContext);
        }

        $pluginBaseClassString = $plugin->getBaseClass();
        $pluginBaseClass = $this->getPluginBaseClass($pluginBaseClassString);

        $uninstallContext = new UninstallContext(
            $pluginBaseClass,
            $shopwareContext,
            $this->shopwareVersion,
            $plugin->getVersion(),
            $this->createMigrationCollection($pluginBaseClass),
            
$this->insertPlugin($active);

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

        $lifecycleService = $this->makePluginLifecycleService();

        /** @var SwagTest $oldPluginInstance */
        $oldPluginInstance = $this->kernel->getPluginLoader()->getPluginInstances()->get($active->getBaseClass());

        $lifecycleService->deactivatePlugin($active, Context::createDefaultContext());

        /** @var SwagTest $swagTestPlugin */
        $swagTestPlugin = $this->kernel->getPluginLoader()->getPluginInstances()->get($active->getBaseClass());

        // only the preDeactivate is called with the plugin still active         static::assertNull($oldPluginInstance->preActivateContext);
        static::assertNull($oldPluginInstance->postActivateContext);
        static::assertNotNull($oldPluginInstance->preDeactivateContext);
        static::assertNull($oldPluginInstance->postDeactivateContext);

        // no plugin service should be loaded after deactivating it
Home | Imprint | This part of the site doesn't use cookies.