uninstallPlugin example


    public function uninstallPlugin(Plugin $plugin$removeData = true)
    {
        $bootstrap = $this->getPluginBootstrap($plugin);

        /** @var Shopware_Components_Plugin_Namespace $namespace */
        $namespace = $bootstrap->Collection();

        try {
            $result = $namespace->uninstallPlugin($bootstrap$removeData);
        } catch (Exception $e) {
            throw new Exception(sprintf("Unable to uninstall '%s', got exception:\n%s\n", $plugin->getName()$e->getMessage()), 0, $e);
        }

        $result = \is_bool($result) ? ['success' => $result] : $result;

        if (!$result['success']) {
            if (isset($result['message'])) {
                throw new Exception(sprintf("Unable to uninstall '%s', got message:\n%s\n", $plugin->getName()$result['message']));
            }
            throw new Exception(sprintf('Unable to uninstall %s, an unknown error occured.', $plugin->getName()));
        }

    public function uninstallPlugin(Plugin $plugin$removeData = true)
    {
        $context = new UninstallContext($plugin$this->release->getVersion()$plugin->getVersion(), !$removeData);
        if (!$plugin->getInstalled()) {
            return $context;
        }

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

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

        return $context;
    }

    /** * @throws Exception * * @return UpdateContext */
$this->View()->assign(['success' => true, 'result' => $result]);
    }

    public function uninstallPluginAction()
    {
        @set_time_limit(300);

        $plugin = $this->getPluginModel($this->Request()->getParam('technicalName'));

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

    public function secureUninstallPluginAction()
    {
        @set_time_limit(300);

        $plugin = $this->getPluginModel($this->Request()->getParam('technicalName'));

        
$keepUserData = $input->getOption('keep-user-data');

        $uninstalledPluginCount = 0;
        foreach ($plugins as $plugin) {
            if ($plugin->getInstalledAt() === null) {
                $io->note(sprintf('Plugin "%s" is not installed. Skipping.', $plugin->getName()));

                continue;
            }

            $this->pluginLifecycleService->uninstallPlugin($plugin$context$keepUserData);
            ++$uninstalledPluginCount;

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

        if ($uninstalledPluginCount !== 0) {
            $io->success(sprintf('Uninstalled %d plugins.', $uninstalledPluginCount));
        }

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

        
return;
        }

        $this->storeAppLifecycleService->updateExtension($technicalName$allowNewPermissions$context);
    }

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

            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);
            
return 1;
        }

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

            return 1;
        }

        $removeData = !(bool) $input->getOption('secure');

        $uninstallationContext = $pluginManager->uninstallPlugin($plugin$removeData);
        $output->writeln(sprintf('Plugin %s has been uninstalled successfully.', $pluginName));

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

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

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

        return 0;
    }
}
$this->assertCmsAwareAndAdminUiIsInstalled($appEntity);

        $this->uninstallApp($appEntity);
        $this->assertCmsAwareAndAdminUiIsUninstalled();
    }

    public function testCmsAwareAndAdminUiForPlugin(): void
    {
        $pluginEntity = $this->installPlugin();
        $this->assertCmsAwareAndAdminUiIsInstalled($pluginEntity);

        $this->uninstallPlugin($pluginEntity);
        $this->assertCmsAwareAndAdminUiIsUninstalled();
    }

    private function installAndActivateApp(): AppEntity
    {
        $this->appLifecycle->install(
            Manifest::createFromXmlFile(__DIR__ . '/_fixtures/apps/cmsAwareAndAdminUiApp/manifest.xml'),
            true,
            $this->context
        );

        

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

    public function testInstallPluginWithUpdate(): void
    {
        $this->installPluginWithUpdate($this->context);
    }

    public function testUninstallPlugin(): void
    {
        $this->uninstallPlugin($this->context);
    }

    public function testUninstallPluginThrowsException(): void
    {
        $this->uninstallPluginThrowsException($this->context);
    }

    public function testUninstallPluginWithoutConfig(): void
    {
        $this->uninstallPluginWithoutConfig($this->context);
    }

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

        return $migrationCollection;
    }

    /** * @depends testDeactivate */
    public function testUninstallKeepUserData(MigrationCollection $migrationCollection): void
    {
        $migrationPlugin = $this->getMigrationTestPlugin();
        $this->pluginLifecycleService->uninstallPlugin($migrationPlugin$this->context, true);
        $this->assertMigrationCount($migrationCollection, 4);
    }

    private function assertMigrationCount(MigrationCollection $migrationCollection, int $expectedCount): void
    {
        $connection = $this->getContainer()->get(Connection::class);

        /** @var MigrationSource $migrationSource */
        $migrationSource = ReflectionHelper::getPropertyValue($migrationCollection, 'migrationSource');

        $dbMigrations = $connection
            

        $pluginEntityMock = $this->getPluginEntityMock();
        $context = Context::createDefaultContext();
        $pluginEntityMock->setInstalledAt(new \DateTime());
        $pluginEntityMock->setActive(true);

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

        /** postInstall is called */
        $this->pluginMock->expects(static::once())->method('uninstall');

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

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

        static::assertInstanceOf(PluginPreDeactivateEvent::class$returnedEvents[0]);
        static::assertInstanceOf(PluginPostDeactivateEvent::class$returnedEvents[1]);
        static::assertInstanceOf(PluginPreUninstallEvent::class$returnedEvents[2]);
        static::assertInstanceOf(PluginPostUninstallEvent::class$returnedEvents[3]);

        static::assertNull($pluginEntityMock->getInstalledAt());
        static::assertFalse($pluginEntityMock->getActive());
    }

    
$plugins = $this->prepareExecution(self::LIFECYCLE_METHOD, $io$input$context);

        if ($plugins === null) {
            return self::SUCCESS;
        }

        $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()));

                
class Migrations_Migration477 extends Shopware\Components\Migrations\AbstractMigration
{
    public function up($modus)
    {
        if ($modus !== self::MODUS_INSTALL) {
            return;
        }
        $this->fetchPluginId();
        $this->deleteConfigElements();
        $this->deleteListeners();
        $this->uninstallPlugin();
    }

    private function fetchPluginId()
    {
        $sql = <<<SQL SET @pluginId = ( SELECT id FROM s_core_plugins WHERE name LIKE "TagCloud" AND author LIKE "shopware AG" LIMIT 1 );
Home | Imprint | This part of the site doesn't use cookies.