symfony-cmf / routing-bundle

Symfony bundle to provide the CMF chain router to handle multiple routers, and the dynamic router to load routes from a database or other sources.
160 stars 78 forks source link

Cmf Routing Bundle does not work with `doctrine/persistence` 3.x #485

Closed emodric closed 1 year ago

emodric commented 1 year ago

Environment

Symfony packages

All Symfony packages are at 6.3.0.

Symfony CMF packages

3.0.1 versions of routingand routing-bundle

Subject

Cmf Routing Bundle does not work with doctrine/persistence 3.x

Steps to reproduce

symfony new test composer require symfony/orm-pack composer require symfony-cmf/routing-bundle

Configure the CMF Routing bundle in config/packages/cmf_routing.yaml with

cmf_routing:
    chain:
        routers_by_id:
            router.default: 200
            cmf_routing.dynamic_router: 100
    dynamic:
        persistence:
            orm:
                enabled: true

Run php bin/console doctrine:schema:update --dump-sql -vvv

Expected results

I expect the command to run successfuly.

Actual results

An exception is thrown:

eddie@abyss ~/www/sf630 (●●)$ php bin/console doctrine:schema:update --dump-sql -vvv

In NotSupported.php line 31:

  [Doctrine\ORM\Exception\NotSupported]                                                                                   
  Context: Using short namespace alias "CmfRoutingBundle" by calling Doctrine\ORM\Configuration::addEntityNamespace       
  Problem: Feature was deprecated in doctrine/persistence 2.x and is not supported by installed doctrine/persistence:3.x  
  Solution: See the doctrine/deprecations logs for new alternative approaches.                                            

Exception trace:
  at /var/www/html/sf630/vendor/doctrine/orm/lib/Doctrine/ORM/Exception/NotSupported.php:31
 Doctrine\ORM\Exception\NotSupported::createForPersistence3() at /var/www/html/sf630/vendor/doctrine/orm/lib/Doctrine/ORM/Configuration.php:234
 Doctrine\ORM\Configuration->addEntityNamespace() at /var/www/html/sf630/var/cache/dev/ContainerG6N3a0m/getDoctrine_Orm_DefaultEntityManagerService.php:94
 ContainerG6N3a0m\getDoctrine_Orm_DefaultEntityManagerService::do() at /var/www/html/sf630/var/cache/dev/ContainerG6N3a0m/getDoctrine_Orm_DefaultEntityManagerService.php:21
 ContainerG6N3a0m\getDoctrine_Orm_DefaultEntityManagerService::ContainerG6N3a0m\{closure}() at /var/www/html/sf630/vendor/symfony/var-exporter/Internal/LazyObjectState.php:97
 Symfony\Component\VarExporter\Internal\LazyObjectState->initialize() at /var/www/html/sf630/vendor/symfony/var-exporter/LazyGhostTrait.php:176
 ContainerG6N3a0m\EntityManagerGhostEbeb667->__get() at /var/www/html/sf630/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:207
 Doctrine\ORM\EntityManager->getMetadataFactory() at /var/www/html/sf630/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:38
 Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() at /var/www/html/sf630/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /var/www/html/sf630/vendor/symfony/console/Application.php:1081
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/sf630/vendor/symfony/framework-bundle/Console/Application.php:91
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/html/sf630/vendor/symfony/console/Application.php:320
 Symfony\Component\Console\Application->doRun() at /var/www/html/sf630/vendor/symfony/framework-bundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/sf630/vendor/symfony/console/Application.php:174
 Symfony\Component\Console\Application->run() at /var/www/html/sf630/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54
 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /var/www/html/sf630/vendor/autoload_runtime.php:29
 require_once() at /var/www/html/sf630/bin/console:11
dbu commented 1 year ago

is this coming from https://github.com/symfony-cmf/routing-bundle/blob/19b4dc9f279f9721ece585dcb66217a1db7b5f9d/src/CmfRoutingBundle.php#L92 ? do you know what the correct thing to pass would be to work with persistence 3?

and could anything be using the alias and stumble if we change it?

emodric commented 1 year ago

It's coming from that line, yes. (there are actually two of them, one for orm, one for phpcr)

In my tests in netgen/layouts-contentful, just removing the line completely worked fine. No issues with reading and writing the routes to the database.

dbu commented 1 year ago

its been a long time, maybe this is registering the alias so that other systems can use the alias, and people normally don't use the alias anymore.

does this solve the problem? https://github.com/symfony-cmf/routing-bundle/pull/486

emodric commented 1 year ago

@dbu Indeed it does!

dbu commented 1 year ago

https://github.com/symfony-cmf/routing-bundle/releases/tag/3.0.2

emodric commented 1 year ago

Thanks David! :tada: