UpdatePrePrepareEvent example

$context = Context::createDefaultContext();
        $currentVersion = $this->container->getParameter('kernel.shopware_version');
        if (!\is_string($currentVersion)) {
            throw new \RuntimeException('Container parameter "kernel.shopware_version" needs to be a string');
        }

        // TODO: get new version (from composer.lock?)         $newVersion = '';

        /** @var EventDispatcherInterface $eventDispatcher */
        $eventDispatcher = $this->container->get('event_dispatcher');
        $eventDispatcher->dispatch(new UpdatePrePrepareEvent($context$currentVersion$newVersion));

        /** @var EventDispatcherInterface $eventDispatcherWithoutPlugins */
        $eventDispatcherWithoutPlugins = $this->rebootKernelWithoutPlugins()->get('event_dispatcher');

        // @internal plugins are deactivated         $eventDispatcherWithoutPlugins->dispatch(new UpdatePostPrepareEvent($context$currentVersion$newVersion));

        return self::SUCCESS;
    }

    private function rebootKernelWithoutPlugins(): ContainerInterface
    {
#[Route(path: '/api/_action/update/deactivate-plugins', name: 'api.custom.updateapi.deactivate-plugins', defaults: ['_acl' => ['system:core:update', 'system_config:read']], methods: ['GET'])]     public function deactivatePlugins(Request $request, Context $context): JsonResponse
    {
        $update = $this->apiClient->checkForUpdates();

        $offset = $request->query->getInt('offset');

        if ($offset === 0) {
            // plugins can subscribe to these events, check compatibility and throw exceptions to prevent the update             $this->eventDispatcher->dispatch(
                new UpdatePrePrepareEvent($context$this->shopwareVersion, $update->version)
            );
        }

        // disable plugins - save active plugins         $deactivationFilter = (string) $request->query->get(
            'deactivationFilter',
            ExtensionCompatibility::PLUGIN_DEACTIVATION_FILTER_NOT_COMPATIBLE
        );

        $deactivatePluginStep = new DeactivateExtensionsStep(
            $update,
            
/** * @internal * * @covers \Shopware\Core\Framework\Update\Event\UpdatePrePrepareEvent */
class UpdatePrePrepareEventTest extends TestCase
{
    public function testGetters(): void
    {
        $context = Context::createDefaultContext();
        $event = new UpdatePrePrepareEvent($context, 'currentVersion', 'newVersion');

        static::assertSame('currentVersion', $event->getCurrentVersion());
        static::assertSame('newVersion', $event->getNewVersion());
        static::assertSame($context$event->getContext());
    }
}
Home | Imprint | This part of the site doesn't use cookies.