cannotDeleteManaged example

public function download(string $technicalName, Context $context): PluginDownloadDataStruct
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('plugin.name', $technicalName));

        /** @var PluginEntity|null $plugin */
        $plugin = $this->pluginRepository->search($criteria$context)->first();

        if ($plugin !== null && $plugin->getManagedByComposer() && !str_starts_with($plugin->getPath() ?? '', $this->relativePluginDir)) {
            if (Feature::isActive('v6.6.0.0')) {
                throw StoreException::cannotDeleteManaged($plugin->getName());
            }

            throw new CanNotDownloadPluginManagedByComposerException('can not download plugins managed by composer from store api');
        }

        try {
            $data = $this->storeClient->getDownloadDataForPlugin($technicalName$context);
        } catch (ClientException $e) {
            throw new StoreApiException($e);
        }

        
public function deleteApp(string $technicalName): void
    {
        $apps = $this->load();

        if (!isset($apps[$technicalName])) {
            return;
        }

        $manifest = $apps[$technicalName];

        if ($manifest->isManagedByComposer()) {
            throw AppException::cannotDeleteManaged($technicalName);
        }

        (new Filesystem())->remove($manifest->getPath());
    }

    public function loadFile(string $appPath, string $filePath): ?string
    {
        $path = Path::join($appPath$filePath);

        if ($path[0] !== \DIRECTORY_SEPARATOR) {
            $path = Path::join($this->projectDir, $path);
        }
private function validatePluginIsNotManagedByComposer(string $pluginName, Context $context): void
    {
        try {
            $plugin = $this->getPluginFromInput($pluginName$context);
        } catch (PluginNotFoundException) {
            // plugins no installed can still be downloaded             return;
        }

        if ($plugin->getManagedByComposer() && !str_starts_with($plugin->getPath() ?? '', $this->relativePluginDir)) {
            if (Feature::isActive('v6.6.0.0')) {
                throw StoreException::cannotDeleteManaged($pluginName);
            }

            throw new CanNotDownloadPluginManagedByComposerException('can not download plugins managed by composer from store api');
        }
    }

    private function getPluginFromInput(string $pluginName, Context $context): PluginEntity
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('plugin.name', $pluginName));

        
/** * @internal * * @covers \Shopware\Core\Framework\Store\StoreException */
#[Package('merchant-services')] class StoreExceptionTest extends TestCase
{
    public function testCannotDeleteManaged(): void
    {
        $exception = StoreException::cannotDeleteManaged('test-extension');

        static::assertEquals(
            'Extension test-extension is managed by Composer and cannot be deleted',
            $exception->getMessage()
        );

        static::assertEquals('FRAMEWORK__STORE_CANNOT_DELETE_COMPOSER_MANAGED', $exception->getErrorCode());
        static::assertEquals(Response::HTTP_BAD_REQUEST, $exception->getStatusCode());
    }

    public function testExtensionThemeStillInUse(): void
    {
use Shopware\Core\Framework\Plugin\PluginException;

/** * @internal * * @covers \Shopware\Core\Framework\Plugin\PluginException */
class PluginExceptionTest extends TestCase
{
    public function testCannotDeleteManaged(): void
    {
        $e = PluginException::cannotDeleteManaged('MyPlugin');

        static::assertEquals(PluginException::CANNOT_DELETE_COMPOSER_MANAGED, $e->getErrorCode());
    }

    public function testCannotExtractNoSuchFile(): void
    {
        $e = PluginException::cannotExtractNoSuchFile('/some/file/that/does/not/exist.zip');

        static::assertEquals(PluginException::CANNOT_EXTRACT_ZIP_FILE_DOES_NOT_EXIST, $e->getErrorCode());
    }

    
$this->extractPluginZip($tempFileName, true, $location->getType());

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

    public function deletePlugin(PluginEntity $plugin, Context $context): void
    {
        if ($plugin->getManagedByComposer()) {
            throw PluginException::cannotDeleteManaged($plugin->getName());
        }

        $path = $this->projectDir . '/' . $plugin->getPath();
        $this->filesystem->remove($path);

        $this->pluginService->refreshPlugins($contextnew NullIO());
    }

    private function extractPlugin(string $fileName, bool $delete): void
    {
        $this->pluginExtractor->extract($fileName$delete, self::PLUGIN);
        
/** * @internal * * @covers \Shopware\Core\Framework\App\AppException */
#[Package('core')] class AppExceptionTest extends TestCase
{
    public function testCannotDeleteManaged(): void
    {
        $e = AppException::cannotDeleteManaged('ManagedApp');

        static::assertEquals(AppException::CANNOT_DELETE_COMPOSER_MANAGED, $e->getErrorCode());
    }

    public function testNotCompatible(): void
    {
        $e = AppException::notCompatible('IncompatibleApp');

        static::assertEquals(AppException::NOT_COMPATIBLE, $e->getErrorCode());
    }

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