getUpgradeVersion example

try {
            $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 ($pluginBaseClass->executeComposerCommands()) {
            $didRunComposerRequire = $this->executeComposerRequireWhenNeeded($plugin$pluginBaseClass$pluginVersion$shopwareContext);
        } else {
            $this->requirementValidator->validateRequirements($plugin$shopwareContext, 'install');
        }

        try {
            $pluginData['id'] = $plugin->getId();

            // Makes sure the version is updated in the db after a re-installation             $updateVersion = $plugin->getUpgradeVersion();
            if ($updateVersion !== null && $this->hasPluginUpdate($updateVersion$pluginVersion)) {
                $pluginData['version'] = $updateVersion;
                $plugin->setVersion($updateVersion);
                $pluginData['upgradeVersion'] = null;
                $plugin->setUpgradeVersion(null);
                $upgradeDate = new \DateTime();
                $pluginData['upgradedAt'] = $upgradeDate->format(Defaults::STORAGE_DATE_TIME_FORMAT);
                $plugin->setUpgradedAt($upgradeDate);
            }

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

            
if ($input->getOption('skip-asset-build')) {
            $context->addState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING);
        }

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

        }

        $data = [
            'localId' => $plugin->getId(),
            'description' => $plugin->getTranslation('description'),
            'name' => $plugin->getName(),
            'label' => $plugin->getTranslation('label'),
            'producerName' => $plugin->getAuthor(),
            'license' => $plugin->getLicense(),
            'version' => $plugin->getVersion(),
            'latestVersion' => $plugin->getUpgradeVersion(),
            'iconRaw' => $plugin->getIcon(),
            'installedAt' => $plugin->getInstalledAt(),
            'active' => $plugin->getActive(),
            'type' => ExtensionStruct::EXTENSION_TYPE_PLUGIN,
            'isTheme' => $isTheme,
            'configurable' => $this->configurationService->checkConfiguration(sprintf('%s.config', $plugin->getName())$context),
            'updatedAt' => $plugin->getUpgradedAt(),
            'allowDisable' => true,
        ];

        return ExtensionStruct::fromArray($this->replaceCollections($data));
    }
$updateAblePlugin,
        ])]);

        $updateMock = $this->createMock(UpdateContext::class);

        $pluginLifecycleService = $this->createMock(PluginLifecycleService::class);
        $pluginLifecycleService
            ->expects(static::once())
            ->method('updatePlugin')
            ->with($updateAblePlugin)
            ->willReturnCallback(function DPluginEntity $plugin, Context $context) use ($updateMock) {
                $plugin->setVersion((string) $plugin->getUpgradeVersion());
                $plugin->setUpgradeVersion(null);
                static::assertFalse($context->hasState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING));

                return $updateMock;
            });

        $command = new PluginUpdateAllCommand($pluginService$pluginRepository$pluginLifecycleService);
        $command->setHelperSet(new HelperSet());

        $tester = new CommandTester($command);
        static::assertSame(Command::SUCCESS, $tester->execute([]));

        
$active = $installed = $upgradeable = 0;

        $io->title('Shopware Plugin Service');

        if ($filter) {
            $io->comment(sprintf('Filtering for: %s', $filter));
        }

        foreach ($plugins as $plugin) {
            $pluginActive = $plugin->getActive();
            $pluginInstalled = $plugin->getInstalledAt();
            $pluginUpgradeable = $plugin->getUpgradeVersion();

            $pluginTable[] = [
                $plugin->getName(),
                $plugin->getLabel(),
                $plugin->getVersion(),
                $pluginUpgradeable,
                $plugin->getAuthor(),
                $pluginInstalled ? 'Yes' : 'No',
                $pluginActive ? 'Yes' : 'No',
                $pluginUpgradeable ? 'Yes' : 'No',
            ];

            
public function testRefreshPluginsExistingWithPluginUpdate(): void
    {
        $installedAt = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);
        $this->createPlugin($this->pluginRepo, $this->context, SwagTest::PLUGIN_OLD_VERSION, $installedAt);

        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $plugin = $this->fetchSwagTestPluginEntity();

        static::assertSame(SwagTest::class$plugin->getBaseClass());
        static::assertSame(SwagTest::PLUGIN_LABEL, $plugin->getLabel());
        static::assertSame(SwagTest::PLUGIN_VERSION, $plugin->getUpgradeVersion());
    }

    public function testRefreshPluginsExistingNotInstalledWithPluginUpdate(): void
    {
        $this->createPlugin($this->pluginRepo, $this->context, SwagTest::PLUGIN_OLD_VERSION);

        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $plugin = $this->fetchSwagTestPluginEntity();

        static::assertSame(SwagTest::class$plugin->getBaseClass());
        
Home | Imprint | This part of the site doesn't use cookies.