Added function to 'lazyload' the repository #580
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Yesterday while running automated test after merging our FOSOAuthServerBundle branch in our project we ran into a problem; unable to execute any command when there was no database available yet.
Our test environment script delete the database and creates is again with settings from the parameters.yml. ( plain doctrine command app/console doctrine:database:create etc.)
All commands would fail because the database would not exist. Even just a app/console.
After debugging narrowed it down to the ClientManager.php and the TokenManager.php which get a repositoryClass from doctrine. Doctrine tries to generate some meta data for the requested class.
Solution:
Moved the constructing of the repository from the constructor to a separate function. And altered some lines that used the property to use the function instead.
Stack trace:
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'ris_testing'
Exception trace:
() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
PDO->__construct() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
Doctrine\DBAL\Driver\PDOConnection->__construct() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:44
Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
Doctrine\DBAL\Connection->connect() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
Doctrine\DBAL\Connection->detectDatabasePlatform() at /Users/winus/Sites/vtr/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
Doctrine\DBAL\Connection->getDatabasePlatform() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763
Doctrine\ORM\Mapping\ClassMetadataFactory->getTargetPlatform() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616
Doctrine\ORM\Mapping\ClassMetadataFactory->completeIdGeneratorMapping() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /Users/winus/Sites/vtr/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /Users/winus/Sites/vtr/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:281
Doctrine\ORM\EntityManager->getClassMetadata() at /Users/winus/Sites/vtr/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php:44
Doctrine\Bundle\DoctrineBundle\Repository\ContainerRepositoryFactory->getRepository() at /Users/winus/Sites/vtr/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:698
Doctrine\ORM\EntityManager->getRepository() at /Users/winus/Sites/vtr/app/cache/test/appTestDebugProjectContainer.php:5571
DoctrineORMEntityManager_000000002ee75b2c00000000050415f90305fe7feaaef79014396928be2670a6->getRepository() at /Users/winus/Sites/vtr/vendor/friendsofsymfony/oauth-server-bundle/Entity/ClientManager.php:40
FOS\OAuthServerBundle\Entity\ClientManager->__construct() at /Users/winus/Sites/vtr/app/cache/test/appTestDebugProjectContainer.php:1910
appTestDebugProjectContainer->getFosOauthServer_ClientManager_DefaultService() at /Users/winus/Sites/vtr/app/bootstrap.php.cache:2261
Symfony\Component\DependencyInjection\Container->get() at /Users/winus/Sites/vtr/app/cache/test/appTestDebugProjectContainer.php:1930
appTestDebugProjectContainer->getFosOauthServer_CreateClientCommandService() at /Users/winus/Sites/vtr/app/bootstrap.php.cache:2261
Symfony\Component\DependencyInjection\Container->get() at /Users/winus/Sites/vtr/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:147
Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /Users/winus/Sites/vtr/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:112
Symfony\Bundle\FrameworkBundle\Console\Application->all() at /Users/winus/Sites/vtr/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:66
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/winus/Sites/vtr/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
Symfony\Component\Console\Application->run() at /Users/winus/Sites/vtr/app/console:27