updatePlugin example


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

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

        try {
            $result = $namespace->updatePlugin($bootstrap);
        } catch (Exception $e) {
            throw new Exception(sprintf("Unable to update '%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 update '%s', got message:\n%s\n", $plugin->getName()$result['message']));
            }
            throw new Exception(sprintf('Unable to update "%s", an unknown error occured.', $plugin->getName()));
        }

    public function updatePlugin(Plugin $plugin)
    {
        $context = new UpdateContext($plugin$this->release->getVersion()$plugin->getVersion()$plugin->getUpdateVersion());
        if (!$plugin->getUpdateVersion()) {
            return $context;
        }

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

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

        return $context;
    }

    /** * @throws Exception * * @return ActivateContext */
$customEntityLifecycleService = new CustomEntityLifecycleService(
            $customEntityPersister,
            $customEntitySchemaUpdater,
            $customEntityEnrichmentService,
            $customEntityXmlSchemaValidator,
            '',
            $this->createAppLoader(),
        );

        static::assertNull(
            $customEntityLifecycleService->updatePlugin(Uuid::randomHex(), 'not/given')
        );
        static::assertNull(
            $customEntityLifecycleService->updateApp(Uuid::randomHex(), 'not/given')
        );
    }

    public function testUpdatePluginOnlyCustomEntities(): void
    {
        $customEntityPersister = $this->createMock(CustomEntityPersister::class);
        $customEntityPersister->expects(static::once())->method('update');

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

        $plugin = $this->getPluginModel($technicalName);

        // disable plugin and save state         $active = $plugin->getActive();
        $plugin->setActive(false);
        $this->get(ModelManager::class)->flush();

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

            return;
        }

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

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

                continue;
            }
            $this->pluginLifecycleService->updatePlugin($plugin$context);
            ++$updatedPluginCount;

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

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

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

        

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

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

    public function testUpdatePlugin(): void
    {
        $this->updatePlugin($this->context);
    }

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

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

    
$this->pluginService->refreshPlugins($contextnew ConsoleIO($composerInput$output$helperSet));

        /** @var EntityCollection<PluginEntity> $plugins */
        $plugins = $this->pluginRepository->search(new Criteria()$context)->getEntities();

        foreach ($plugins as $plugin) {
            if ($plugin->getUpgradeVersion() === null || $plugin->getActive() === false) {
                continue;
            }

            $currentVersion = $plugin->getVersion();
            $this->pluginLifecycleService->updatePlugin($plugin$context);
            $output->writeln(sprintf('Updated plugin %s from version %s to version %s', $plugin->getName()$currentVersion$plugin->getVersion()));
        }

        return self::SUCCESS;
    }
}
public function testUpdatePlugin(): void
    {
        $pluginEntityMock = $this->getPluginEntityMock();
        $context = Context::createDefaultContext();

        $pluginEntityMock->setInstalledAt(new \DateTime());
        $pluginEntityMock->setActive(true);

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

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

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

        static::assertInstanceOf(PluginPreUpdateEvent::class$returnedEvents[0]);
        static::assertInstanceOf(PluginPostUpdateEvent::class$returnedEvents[1]);
    }

    public function testUpdatePluginMajor(): void
    {
        $pluginEntityMock = $this->getPluginEntityMock();
        $pluginEntityMock->setActive(false);

        
$data = $this->storeClient->getDownloadDataForPlugin($pluginName$context);
        } catch (ClientException $exception) {
            throw new StoreApiException($exception);
        }

        $this->pluginManagementService->downloadStorePlugin($data$context);

        try {
            $plugin = $this->getPluginFromInput($pluginName$context);

            if ($plugin->getUpgradeVersion()) {
                $this->pluginLifecycleService->updatePlugin($plugin$context);
            }
        } catch (PluginNotFoundException) {
            // don't update plugins that are not installed         }

        return self::SUCCESS;
    }

    private function getUserContextFromInput(?string $userName, Context $context): Context
    {
        if (!$userName) {
            
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);
            $this->pluginLifecycleService->updatePlugin($plugin$context);

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


        $pluginNames = $input->getArgument('plugin');

        $batchUpdate = $input->getOption('batch');
        if (!empty($batchUpdate)) {
            return $this->batchUpdate($pluginManager$batchUpdate$output);
        }

        if (!empty($pluginNames)) {
            foreach ($pluginNames as $pluginName) {
                $this->updatePlugin($pluginManager$pluginName$input$output);
            }

            return 0;
        }

        $output->writeln(sprintf('Specify either a plugin name or use the --batch option to update several plugins at once'));

        return 1;
    }

    /** * @param string $batchUpdate * * @return int 0 if everything went fine, or an error code */
$upgradeDate = new \DateTime();
                $pluginData['upgradedAt'] = $upgradeDate->format(Defaults::STORAGE_DATE_TIME_FORMAT);
                $plugin->setUpgradedAt($upgradeDate);
            }

            $this->eventDispatcher->dispatch(new PluginPreInstallEvent($plugin$installContext));

            $this->systemConfigService->savePluginConfiguration($pluginBaseClass, true);

            $pluginBaseClass->install($installContext);

            $this->customEntityLifecycleService->updatePlugin($plugin->getId()$plugin->getPath() ?? '');

            $this->runMigrations($installContext);

            $installDate = new \DateTime();
            $pluginData['installedAt'] = $installDate->format(Defaults::STORAGE_DATE_TIME_FORMAT);
            $plugin->setInstalledAt($installDate);

            $this->updatePluginData($pluginData$shopwareContext);

            $pluginBaseClass->postInstall($installContext);

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

        return $migrationCollection;
    }

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

        return $migrationCollection;
    }

    /** * @depends testUpdate */
    public function testDeactivate(MigrationCollection $migrationCollection): MigrationCollection
    {
        $migrationPlugin = $this->getMigrationTestPlugin();
        
Home | Imprint | This part of the site doesn't use cookies.