doctrine/DoctrineMongoDBBundle

Fatal error on fresh install due to outdated recipe

mklewitz opened this issue · 1 comments

The recipe still refers to Symfony\Component\Cache\DoctrineProvider which isn't available in Symfony 6 anymore.

So setting up a minimal test case results in a fatal error in prod env (dev is working fine):

composer create-project symfony/skeleton mongodb-odm-bundle_test
cd mongodb-odm-bundle_test
composer config extra.symfony.allow-contrib true
composer require doctrine/mongodb-odm-bundle --with-all-dependencies
bin/console cache:clear --env=prod --no-debug

results in :

PHP Fatal error:  Uncaught Error: Class "Symfony\Component\Cache\DoctrineProvider" not found in /Users/mklewitz/dev/mongodb-odm-bundle_test/var/cache/prod/ContainerE7S12bi/getDoctrineMongodb_Odm_DefaultDocumentManagerService.php:26
Stack trace:
#0 /Users/mklewitz/dev/mongodb-odm-bundle_test/var/cache/prod/ContainerE7S12bi/App_KernelProdContainer.php(97): ContainerE7S12bi\getDoctrineMongodb_Odm_DefaultDocumentManagerService::do(Object(ContainerE7S12bi\App_KernelProdContainer), true)
#1 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/dependency-injection/Container.php(215): ContainerE7S12bi\App_KernelProdContainer->load('getDoctrineMong...')
#2 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/dependency-injection/Container.php(197): Symfony\Component\DependencyInjection\Container->make('doctrine_mongod...', 1)
#3 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/doctrine-bridge/ManagerRegistry.php(36): Symfony\Component\DependencyInjection\Container->get('doctrine_mongod...')
#4 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/doctrine/persistence/lib/Doctrine/Persistence/AbstractManagerRegistry.php(206): Symfony\Bridge\Doctrine\ManagerRegistry->getService('doctrine_mongod...')
#5 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/doctrine/mongodb-odm-bundle/CacheWarmer/HydratorCacheWarmer.php(74): Doctrine\Persistence\AbstractManagerRegistry->getManagers()
#6 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php(99): Doctrine\Bundle\MongoDBBundle\CacheWarmer\HydratorCacheWarmer->warmUp('/Users/mklewitz...')
#7 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/http-kernel/Kernel.php(579): Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp('/Users/mklewitz...')
#8 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/http-kernel/Kernel.php(769): Symfony\Component\HttpKernel\Kernel->initializeContainer()
#9 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/http-kernel/Kernel.php(128): Symfony\Component\HttpKernel\Kernel->preBoot()
#10 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/framework-bundle/Console/Application.php(166): Symfony\Component\HttpKernel\Kernel->boot()
#11 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/framework-bundle/Console/Application.php(72): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()
#12 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/console/Application.php(171): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php(54): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /Users/mklewitz/dev/mongodb-odm-bundle_test/vendor/autoload_runtime.php(29): Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run()
#15 /Users/mklewitz/dev/mongodb-odm-bundle_test/bin/console(11): require_once('/Users/mklewitz...')
#16 {main}
  thrown in /Users/mklewitz/dev/mongodb-odm-bundle_test/var/cache/prod/ContainerE7S12bi/getDoctrineMongodb_Odm_DefaultDocumentManagerService.php on line 26

The solution is to use another recipe for Symfony >= 5.4 and change the services section in config/packages/prod/doctrine_mongodb.yaml.

Before:

services:
    doctrine_mongodb.system_cache_provider:
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine_mongodb.system_cache_pool'

After:

services:
    doctrine_mongodb.system_cache_provider:
        factory: [ 'Doctrine\Common\Cache\Psr6\DoctrineProvider', 'wrap' ]
        class: Doctrine\Common\Cache\Psr6\DoctrineProvider
        public: false
        arguments:
            - '@doctrine_mongodb.system_cache_pool'

I'd say if this works then let's use it :) Although recipes are not provided by this repository, please open an issue in https://github.com/symfony/recipes, feel free to link to this one. I'm not that familiar with recipes to know how to differ them basing on Symfony's version so I won't be making that change myself.