deprecated-packages / symplify

[DISCONTINUED] Check split packages in their own repositories :)
MIT License
619 stars 189 forks source link

[config-transformer] Unable to migrate XML #3502

Closed jazithedev closed 3 years ago

jazithedev commented 3 years ago

Hello all,

I've got a Symfony 5.3 and this particular Doctrine configuration written in XML:

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
           xsi:schemaLocation="http://symfony.com/schema/dic/services
        https://symfony.com/schema/dic/services/services-1.0.xsd
        http://symfony.com/schema/dic/doctrine
        https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
    <doctrine:config>
        <doctrine:dbal
            url="%env(resolve:DATABASE_URL)%"
        />
        <doctrine:orm
            auto-generate-proxy-classes="true"
            naming-strategy="doctrine.orm.naming_strategy.underscore_number_aware"
            auto-mapping="true"
        >
            <doctrine:mapping
                name="App"
                alias="App"
                prefix="App\Entity"
                is-bundle="false"
                type="xml"
                dir="%kernel.project_dir%/config/doctrine"
            />
        </doctrine:orm>
    </doctrine:config>
</container>

After executing this command:

vendor/bin/config-transformer switch-format -s 5.3 ./config/packages/prod

I'm receiving an error:

There is no extension able to load the configuration for "doctrine:config" (in "/myProject/config/packages/prod/doctrine.xml"). Looked for namespace "http://symfony.com/schema/dic/doctrine", found "none".

Thank you in advance for any help :).

TomasVotruba commented 3 years ago

Hi, thanks for reporting.

I have no idea where the error could be. Looks like you're missing some dependencies of your project. The project should work with current configuration. If Symfony throws errors, the config converter will not work either.

Do you have Doctrine present in your app?

jazithedev commented 3 years ago

Yes. The project works alongside with EasyAdminBundle which requires Doctrine to work :). Everything in the app is working - no errors about missing Doctrine or something. I've even added Doctrine dependencies to my composer.json. Unfortunately, the issue still exists.

Edit: Also, what is worth to mention, is that this app is very fresh. Built it yesterday from scratch with the newest stable Symfony version.

TomasVotruba commented 3 years ago

I see. The symplify/config-transformer shoud be installed as a dev dependency there. Could you share composer.json?

jazithedev commented 3 years ago

Here it is:

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": "~8.0.0",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "doctrine/doctrine-migrations-bundle": "^3.1",
        "easycorp/easyadmin-bundle": "^3.5",
        "knpuniversity/oauth2-client-bundle": "^2.8",
        "league/oauth2-google": "^4.0",
        "symfony/console": "5.3.*",
        "symfony/dotenv": "5.3.*",
        "symfony/flex": "^1.3.1",
        "symfony/framework-bundle": "5.3.*",
        "symfony/runtime": "5.3.*",
        "symfony/validator": "5.3.*",
        "symfony/yaml": "5.3.*"
    },
    "require-dev": {
        "friendsofphp/php-cs-fixer": "^3.0",
        "phpstan/phpstan": "^0.12.94",
        "phpstan/phpstan-doctrine": "^0.12.42",
        "phpstan/phpstan-symfony": "^0.12.41",
        "phpunit/phpunit": "^9.5",
        "roave/security-advisories": "dev-latest",
        "symfony/stopwatch": "^5.3",
        "symfony/twig-bundle": "^5.3",
        "symfony/web-profiler-bundle": "^5.3",
        "symplify/config-transformer": "^9.4"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*"
    },
    "scripts": {
        "phpstan": "./vendor/bin/phpstan analyse --memory-limit 8G -c phpstan.neon",
        "phpunit": "vendor/bin/phpunit --configuration ./phpunit.xml.dist",
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "5.3.*"
        }
    }
}
TomasVotruba commented 3 years ago

Looks ok. We'll need a reproducible repository to figure it out then. Could you create one on Github?

jazithedev commented 3 years ago

I'll try to set something up :).

jazithedev commented 3 years ago

Sorry @TomasVotruba that it took me longer time, but finally have it: https://github.com/ktrzos/test_project

TomasVotruba commented 3 years ago

Thank you for the demo. I tried to prepare hot fix: https://github.com/symplify/symplify/pull/3527

Should be published in dev-main in ~ 3 mins.

I'm going out now, to enjoy some :sun_with_face: till the dark comes... could you verify it helped? Thanks :)

jazithedev commented 3 years ago

Unfortunately, I'm getting this error while transforming 🙁:

[ERROR] Class "ConfigTransformer202108241\Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension" not
found

I've upgraded dependency version in Composer:

    "require-dev": {
        "symplify/config-transformer": "dev-main"
    },

and

composer update symplify/config-transformer

Tried also with clearing the cache (rm -rf ./var/cache/dev/*), but the same result 🙁.

TomasVotruba commented 3 years ago

Ah, I see :) let me check again

TomasVotruba commented 3 years ago

Attempt number 2: https://github.com/symplify/symplify/pull/3530 :)

jazithedev commented 3 years ago

I confirm, it is working 😀! 🎉

TomasVotruba commented 3 years ago

That's good news :laughing: :partying_face: Thanks :+1:

Maybe in the future we'll need to add more custom extensions with namespaces.

In here like this: https://github.com/symplify/symplify/blob/c1d756c120bbb766f470a72d32f58da01f79874b/packages/config-transformer/src/DependencyInjection/Loader/IdAwareXmlFileLoader.php#L82-L87