refreshPlugins example

$this->pluginRepo,
            $this->container->get('language.repository'),
            $this->container->get(PluginFinder::class)
        );

        $this->addTestPluginToKernel(
            __DIR__ . '/_fixture/plugins/SwagManualMigrationTest',
            'SwagManualMigrationTest'
        );
        $this->requireMigrationFiles();

        $this->pluginService->refreshPlugins($this->context, new NullIO());
        $this->connection->executeStatement('DELETE FROM plugin WHERE `name` = "SwagTest"');
    }

    public function testInstall(): MigrationCollection
    {
        static::assertSame(0, $this->connection->getTransactionNestingLevel());

        $migrationPlugin = $this->getMigrationTestPlugin();
        static::assertNull($migrationPlugin->getInstalledAt());

        $this->pluginLifecycleService->installPlugin($migrationPlugin$this->context);
        
$this->getContainer()->getParameter('kernel.project_dir'),
            $this->pluginRepository,
            $this->languageRepository,
            $this->pluginFinder
        );

        $this->addTestPluginToKernel(
            __DIR__ . '/_fixtures/plugins/' . self::PLUGIN_NAME,
            self::PLUGIN_NAME
        );

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

        $this->pluginLifecycleService->installPlugin(
            $this->pluginService->getPluginByName(
                self::PLUGIN_NAME,
                $this->context
            ),
            $this->context
        );

        $installedPlugin = $this->pluginService->getPluginByName(self::PLUGIN_NAME, $this->context);
        static::assertNotNull($installedPlugin->getInstalledAt());

        
protected function prepareExecution(
        string $lifecycleMethod,
        SymfonyStyle $io,
        InputInterface $input,
        Context $context
    ): ?PluginCollection {
        $io->title('Shopware Plugin Lifecycle Service');

        if ($input->getOption('refresh')) {
            $io->note('Refreshing plugin list');
            $this->refreshPlugins();
        }

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

        $plugins = $this->parsePluginArgument($input->getArgument('plugins')$lifecycleMethod$io$context);

        if ($plugins === null) {
            return null;
        }

        
public function __construct(
        private readonly AbstractExtensionLifecycle $extensionLifecycleService,
        private readonly ExtensionDownloader $extensionDownloader,
        private readonly PluginService $pluginService,
        private readonly PluginManagementService $pluginManagementService
    ) {
    }

    #[Route(path: '/api/_action/extension/refresh', name: 'api.extension.refresh', methods: ['POST'])]     public function refreshExtensions(Context $context): Response
    {
        $this->pluginService->refreshPlugins($contextnew NullIO());

        return new Response('', Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/extension/upload', name: 'api.extension.upload', methods: ['POST'], defaults: ['_acl' => ['system.plugin_upload']])]     public function uploadExtensions(Request $request, Context $context): Response
    {
        /** @var UploadedFile|null $file */
        $file = $request->files->get('file');

        if (!$file) {
            
$pluginRepo = new StaticEntityRepository([new PluginCollection()]);
        $pluginService = new PluginService(
            __DIR__,
            __DIR__,
            $pluginRepo,
            $this->getLanguageRepository(),
            $pluginFinder,
            new VersionSanitizer()
        );

        $pluginService->refreshPlugins(Context::createDefaultContext()$this->createMock(IOInterface::class));

        $upserts = $pluginRepo->upserts;
        static::assertCount(1, $upserts, 'There should be one plugin upserted');
        static::assertArrayHasKey('0', $upserts);

        static::assertCount(1, $upserts['0']);

        $pluginWrite = $upserts['0']['0'];

        static::assertSame('foo', $pluginWrite['name']);
        static::assertSame('foo', $pluginWrite['baseClass']);
        

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new ShopwareStyle($input$output);
        $io->title('Shopware Plugin Service');
        $context = Context::createDefaultContext();

        $composerInput = clone $input;
        $composerInput->setInteractive(false);
        $helperSet = $this->getHelperSet();
        \assert($helperSet instanceof HelperSet);
        $errors = $this->pluginService->refreshPlugins($contextnew ConsoleIO($composerInput$output$helperSet));
        $io->success('Plugin list refreshed');

        if (\count($errors) !== 0) {
            $io->writeln('Errors occurred while refreshing plugin list');
            foreach ($errors as $key => $error) {
                if (\is_int($key)) {
                    $io->error($error->getMessage());
                } else {
                    $io->error($key . ': ' . $error->getMessage());
                }
            }
        }
$extensions = $this->extensionLoader->loadFromListingArray(
            Context::createDefaultContext(),
            $listingResponse
        );

        static::assertInstanceOf(ExtensionCollection::class$extensions);
        static::assertCount(2, $extensions);
    }

    public function testItLoadsExtensionsFromPlugins(): void
    {
        $this->getContainer()->get(PluginService::class)->refreshPlugins(Context::createDefaultContext()new NullIO());

        /** @var PluginCollection $plugins */
        $plugins = $this->getContainer()->get('plugin.repository')->search(new Criteria(), Context::createDefaultContext())->getEntities();

        $extensions = $this->extensionLoader->loadFromPluginCollection(Context::createDefaultContext()$plugins);

        /** @var ExtensionStruct $extension */
        $extension = $extensions->get('AppStoreTestPlugin');

        static::assertNotNull($extension);
        static::assertEquals('AppStoreTestPlugin', $extension->getName());
    }
$composerInput = clone $input;
        $composerInput->setInteractive(false);
        $helperSet = $this->getHelperSet();
        \assert($helperSet instanceof HelperSet);

        $context = Context::createDefaultContext();

        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);
            
if ($pluginBaseClass->executeComposerCommands()) {
            $pluginComposerName = $plugin->getComposerName();
            if ($pluginComposerName === null) {
                throw new PluginComposerJsonInvalidException(
                    $pluginBaseClass->getPath() . '/composer.json',
                    ['No name defined in composer.json']
                );
            }
            $this->executor->remove($pluginComposerName$plugin->getName());

            // running composer require may have consequences for other plugins, when they are required by the plugin being uninstalled             $this->pluginService->refreshPlugins($shopwareContextnew NullIO());
        }

        $this->eventDispatcher->dispatch(new PluginPostUninstallEvent($plugin$uninstallContext));

        return $uninstallContext;
    }

    /** * @throws RequirementStackException */
    public function updatePlugin(PluginEntity $plugin, Context $shopwareContext): UpdateContext
    {
__DIR__ . '/_fixture/plugins',
            $this->getContainer()->getParameter('kernel.project_dir'),
            $this->pluginRepo,
            $this->getContainer()->get('language.repository'),
            $this->getContainer()->get(PluginFinder::class)
        );
        $this->context = Context::createDefaultContext();
    }

    public function testRefreshPlugins(): void
    {
        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $plugin = $this->fetchSwagTestPluginEntity();

        $this->assertDefaultPlugin($plugin);
        $this->assertPluginMetaInformation($plugin);
        static::assertSame('English description', $plugin->getDescription());
        static::assertSame('https://www.test.com/', $plugin->getManufacturerLink());
        static::assertSame('https://www.test.com/support', $plugin->getSupportLink());
    }

    public function testRefreshPluginWithoutExtraLabelProperty(): void
    {
$this->cacheClearer->clearContainerCache();
        }

        $io->success('Successfully import zip file ' . basename((string) $zipFile));

        if (!$input->getOption('no-refresh')) {
            $composerInput = clone $input;
            $composerInput->setInteractive(false);
            $helperSet = $this->getHelperSet();
            \assert($helperSet instanceof HelperSet);

            $this->pluginService->refreshPlugins(
                Context::createDefaultContext(),
                new ConsoleIO($composerInput$output$helperSet)
            );
            $io->success('Plugin list refreshed');
        }

        return self::SUCCESS;
    }
}
$plugin = $this->getTestPlugin($context);
        static::assertFalse($plugin->getActive());
    }

    public function testDeactivatePluginWithDependencies(): void
    {
        $this->addTestPluginToKernel(
            __DIR__ . '/_fixture/plugins/' . self::DEPENDENT_PLUGIN_NAME,
            self::DEPENDENT_PLUGIN_NAME
        );
        $this->pluginService->refreshPlugins($this->context, new NullIO());

        $basePlugin = $this->pluginService->getPluginByName(self::PLUGIN_NAME, $this->context);
        $this->pluginLifecycleService->installPlugin($basePlugin$this->context);
        $this->pluginLifecycleService->activatePlugin($basePlugin$this->context);

        $dependentPlugin = $this->pluginService->getPluginByName(self::DEPENDENT_PLUGIN_NAME, $this->context);
        $this->pluginLifecycleService->installPlugin($dependentPlugin$this->context);
        $this->pluginLifecycleService->activatePlugin($dependentPlugin$this->context);

        $this->expectException(PluginHasActiveDependantsException::class);

        
/** @var string $tempFileName */
        $tempFileName = tempnam(sys_get_temp_dir()$file->getClientOriginalName());
        $tempRealPath = realpath($tempFileName);
        \assert(\is_string($tempRealPath));
        $tempDirectory = \dirname($tempRealPath);

        $tempFile = $file->move($tempDirectory$tempFileName);

        $type = $this->extractPluginZip($tempFile->getPathname());

        if ($type === self::PLUGIN) {
            $this->pluginService->refreshPlugins($contextnew NullIO());
        }
    }

    public function downloadStorePlugin(PluginDownloadDataStruct $location, Context $context): void
    {
        /** @var string $tempFileName */
        $tempFileName = tempnam(sys_get_temp_dir(), 'store-plugin');

        try {
            $response = $this->client->request('GET', $location->getLocation()['sink' => $tempFileName]);
        } catch (\Exception) {
            
Home | Imprint | This part of the site doesn't use cookies.