UpdateContext example

/** * @throws Exception * * @return UpdateContext */
    public function updatePlugin(Plugin $plugin)
    {
        $pluginBootstrap = $this->getPluginByName($plugin->getName());
        $this->requirementValidator->validate($pluginBootstrap->getPath() . '/plugin.xml', $this->release->getVersion());

        $context = new UpdateContext(
            $plugin,
            $this->release->getVersion(),
            $plugin->getVersion(),
            $plugin->getUpdateVersion()
        );

        $this->events->notify(PluginEvent::PRE_UPDATE, new PrePluginUpdateEvent($context$pluginBootstrap));

        $this->installResources($pluginBootstrap$plugin);

        $this->applyMigrations($pluginBootstrap, AbstractPluginMigration::MODUS_UPDATE);

        
$rulePlugin = new RulePlugin(false, '');

        $collection = new MigrationCollection(
            new MigrationSource('asd', []),
            new MigrationRuntime(new NullConnection()new NullLogger()),
            new NullConnection()
        );

        return [
            [new PluginPostInstallEvent($pluginnew InstallContext($rulePlugin$context, '', '', $collection))],
            [new PluginPostActivateEvent($pluginnew ActivateContext($rulePlugin$context, '', '', $collection))],
            [new PluginPostUpdateEvent($pluginnew UpdateContext($rulePlugin$context, '', '', $collection, ''))],
            [new PluginPostDeactivateEvent($pluginnew DeactivateContext($rulePlugin$context, '', '', $collection))],
            [new PluginPostUninstallEvent($pluginnew UninstallContext($rulePlugin$context, '', '', $collection, true))],
        ];
    }
}

/** * @internal */
#[Package('business-ops')] class RulePlugin extends Plugin
{

    public function updatePlugin(PluginEntity $plugin, Context $shopwareContext): UpdateContext
    {
        if ($plugin->getInstalledAt() === null) {
            throw new PluginNotInstalledException($plugin->getName());
        }

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

        $updateContext = new UpdateContext(
            $pluginBaseClass,
            $shopwareContext,
            $this->shopwareVersion,
            $plugin->getVersion(),
            $this->createMigrationCollection($pluginBaseClass),
            $plugin->getUpgradeVersion() ?? $plugin->getVersion()
        );

        if ($pluginBaseClass->executeComposerCommands()) {
            $this->executeComposerRequireWhenNeeded($plugin$pluginBaseClass$updateContext->getUpdatePluginVersion()$shopwareContext);
        } else {
            


        $subscriber->pluginPostActivate($event);
    }

    public function testThemeLifecycleIsNotCalledWhenDeactivatedUsingContextOnUpdate(): void
    {
        $context = Context::createDefaultContext();
        $context->addState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING);
        $event = new PluginPreUpdateEvent(
            $this->getPlugin(),
            new UpdateContext(
                $this->createMock(Plugin::class),
                $context,
                '6.1.0',
                '1.0.0',
                $this->createMock(MigrationCollection::class),
                '1.0.1'
            )
        );

        $handler = $this->createMock(ThemeLifecycleHandler::class);
        $handler->expects(static::never())->method('handleThemeInstallOrUpdate');

        
return $context;
    }

    /** * @throws Exception * * @return UpdateContext */
    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);

        
Home | Imprint | This part of the site doesn't use cookies.