ActivateContext example


    public function activatePlugin(PluginEntity $plugin, Context $shopwareContext, bool $reactivate = false): ActivateContext
    {
        if ($plugin->getInstalledAt() === null) {
            throw new PluginNotInstalledException($plugin->getName());
        }

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

        $activateContext = new ActivateContext(
            $pluginBaseClass,
            $shopwareContext,
            $this->shopwareVersion,
            $plugin->getVersion(),
            $this->createMigrationCollection($pluginBaseClass)
        );

        if ($reactivate === false && $plugin->getActive()) {
            return $activateContext;
        }

        
/** * @throws Exception * @throws \Doctrine\ORM\OptimisticLockException * * @return ActivateContext */
    public function activatePlugin(Plugin $plugin)
    {
        $bootstrap = $this->getPluginByName($plugin->getName());
        $this->requirementValidator->validate($bootstrap->getPath() . '/plugin.xml', $this->release->getVersion());
        $context = new ActivateContext($plugin$this->release->getVersion()$plugin->getVersion());

        $this->events->notify(PluginEvent::PRE_ACTIVATE, new PrePluginActivateEvent($context$bootstrap));

        $bootstrap->activate($context);

        $this->events->notify(PluginEvent::POST_ACTIVATE, new PostPluginActivateEvent($context$bootstrap));

        $plugin->setActive(true);
        $plugin->setInSafeMode(false);
        $this->em->flush($plugin);

        
$this->addTestPluginToKernel(
            __DIR__ . '/../../../../Core/Framework/Test/Plugin/_fixture/plugins/SwagTest',
            'SwagTest'
        );
    }

    public function testDoesNotAddPluginStorefrontConfigurationToConfigurationCollectionIfItIsAddedAlready(): void
    {
        $context = Context::createDefaultContext();
        $event = new PluginPostActivateEvent(
            $this->getPlugin(),
            new ActivateContext(
                $this->createMock(Plugin::class),
                $context,
                '6.1.0',
                '1.0.0',
                $this->createMock(MigrationCollection::class)
            )
        );
        $storefrontPluginConfigMock = new StorefrontPluginConfiguration('SwagTest');
        // Plugin storefront config is already added here         $storefrontPluginConfigCollection = new StorefrontPluginConfigurationCollection([$storefrontPluginConfigMock]);

        
$context = Context::createDefaultContext();
        $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')]
return $context;
    }

    /** * @throws Exception * * @return ActivateContext */
    public function activatePlugin(Plugin $plugin)
    {
        $context = new ActivateContext($plugin$this->release->getVersion()$plugin->getVersion());
        if ($plugin->getActive()) {
            return $context;
        }

        if (!$plugin->getInstalled()) {
            throw new Exception(sprintf('Plugin "%s" has to be installed first before it can be activated.', $plugin->getName()));
        }

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

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