installPlugin example

'HttpCache:admin' => $this->readConfig('HttpCache:admin'),
            'HttpCache:proxy' => $this->readConfig('HttpCache:proxy'),
        ];
    }

    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;
        }
// +++++ InstallPlugin method ++++
    public function testInstallPlugin(): void
    {
        $pluginEntityMock = $this->getPluginEntityMock();
        $context = Context::createDefaultContext();

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

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

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

        static::assertInstanceOf(PluginPreInstallEvent::class$returnedEvents[0]);
        static::assertInstanceOf(PluginPostInstallEvent::class$returnedEvents[1]);
        static::assertNotNull($pluginEntityMock->getInstalledAt());
    }

    public function testInstallThrowsErrorAndResetsComposer(): void
    {
        $pluginEntityMock = $this->getPluginEntityMock();
        
public function testCmsAwareAndAdminUiForApp(): void
    {
        $appEntity = $this->installAndActivateApp();
        $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,
            
 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 {
            $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);

        
$this->pluginService->refreshPlugins($this->context, new NullIO());
        $this->connection->executeStatement('DELETE FROM plugin WHERE `name` = "SwagTest"');
    }

    public function testInstall(): MigrationCollection
    {
        static::assertSame(0, $this->connection->getTransactionNestingLevel());

        $migrationPlugin = $this->getMigrationTestPlugin();
        static::assertNull($migrationPlugin->getInstalledAt());

        $this->pluginLifecycleService->installPlugin($migrationPlugin$this->context);
        $migrationCollection = $this->getMigrationCollection('SwagManualMigrationTest');
        $this->assertMigrationState($migrationCollection, 4, 1);

        return $migrationCollection;
    }

    /** * @depends testInstall */
    public function testActivate(MigrationCollection $migrationCollection): MigrationCollection
    {
        

    public function installPlugin(Plugin $plugin)
    {
        $bootstrap = $this->getPluginBootstrap($plugin);

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

        try {
            $result = $namespace->installPlugin($bootstrap);
        } catch (Exception $e) {
            throw new Exception(sprintf("Unable to install '%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 install '%s', got message:\n'%s'\n", $plugin->getName()$result['message']));
            }
            throw new Exception(sprintf('Unable to install "%s", an unknown error occured.', $plugin->getName()));
        }
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') {
            $plugin = $this->pluginService->getPluginByName($technicalName$context);
            
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;
    }
}
if (!$plugin instanceof Plugin) {
            $this->View()->assign([
                'success' => false,
                'message' => sprintf('Plugin not found %s', $this->Request()->getParam('technicalName')),
            ]);

            return;
        }

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

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

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

        
$this->container->get(CustomEntityLifecycleService::class),
            $this->container->get(PluginService::class),
            $this->container->get(VersionSanitizer::class),
        );

        $context = Context::createDefaultContext();
        $context->addState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING);

        $this->createPlugin($this->pluginRepo, $context, SwagTest::PLUGIN_OLD_VERSION);

        $plugin = $this->getPlugin($context);
        $service->installPlugin($plugin$context);
        $service->activatePlugin($plugin$context);
        $service->uninstallPlugin($plugin$context);

        $context->removeState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING);

        $service->installPlugin($plugin$context);
        $service->activatePlugin($plugin$context);
    }

    public function testUpdateDeactivatedPluginWithExceptionWithNonStandardLanguage(): void
    {
        


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

                continue;
            }

            $activationSuffix = '';
            $message = 'Plugin "%s" has been installed%s successfully.';

            $this->pluginLifecycleService->installPlugin($plugin$context);
            ++$installedPluginCount;

            if ($activatePlugins) {
                if ($input->getOption('refresh')) {
                    $io->note('Can not refresh and activate in same request.');
                } else {
                    $this->pluginLifecycleService->activatePlugin($plugin$context);
                    $activationSuffix = ' and activated';
                }
            }

            

    public function installPlugin(Plugin $plugin)
    {
        $context = new InstallContext($plugin$this->release->getVersion()$plugin->getVersion());
        if ($plugin->getInstalled()) {
            return $context;
        }

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

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

        return $context;
    }

    /** * @param bool $removeData * * @throws Exception * * @return UninstallContext */
Home | Imprint | This part of the site doesn't use cookies.