Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Sylius repositories instead of Doctrine in RouteProvider #2148

Merged
merged 1 commit into from
Nov 19, 2014
Merged

Use Sylius repositories instead of Doctrine in RouteProvider #2148

merged 1 commit into from
Nov 19, 2014

Conversation

gonzalovilaseca
Copy link
Contributor

This PR refers to this RFC: #2147

Basically the RouteProvider looks for entities in repository classes instantiated by doctrine, this PR injects the Sylius repositories.

@@ -51,7 +62,7 @@ public function getRouteByName($name, $parameters = array())
}
}

$repositories = $this->getRepositories();
$repositories = $this->classRepositories;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to assign internal class variable to another variable as it's not being modified etc.

@stloyd
Copy link
Contributor

stloyd commented Nov 19, 2014

👍

pjedrzejewski pushed a commit that referenced this pull request Nov 19, 2014
…itory-service

Use Sylius repositories instead of Doctrine in RouteProvider
@pjedrzejewski pjedrzejewski merged commit 0707ea8 into Sylius:master Nov 19, 2014
@pjedrzejewski
Copy link
Member

Nice, thank you Gonzalo! 👍

@gonzalovilaseca
Copy link
Contributor Author

NP! I needed it for the translations PR :-)

@koemeet
Copy link
Contributor

koemeet commented Nov 19, 2014

@gonzalovilaseca Isn't this PR triggering a DB connection even when you clear the cache? Because I just updated Sylius and my CI server can't build it anymore since one of the last 10 commits forces a DB connection when you run $ php app/console cache:clear (same for assets etc.). This should ofcourse, not happen.

I can confirm that this PR is the cause of the issue I have. Just tested it out.

@gonzalovilaseca
Copy link
Contributor Author

@steffenbrem Not that I'm aware of, I just injected repositories. Will have a look tomorrow just in case.

@koemeet
Copy link
Contributor

koemeet commented Nov 19, 2014

@gonzalovilaseca I just uncommented the code that your PR provided. I can confirm that it is indeed triggering a DB connection when you clear your cache or you install your assets. This is ofcourse not a problem if you do manual deployments etc. But when you use a CI server there won't be a valid parameters.yml file to make the DB connection. It should just install the dependencies, assets (the whole post-update-cmd script from composer), nothing more.

@gonzalovilaseca
Copy link
Contributor Author

@steffenbrem Can you please provide instructions on how can I reproduce the problem without a CI server?

@koemeet
Copy link
Contributor

koemeet commented Nov 20, 2014

@gonzalovilaseca Just make an invalid DB connection in your parameters.yml and then run clear cache command or run assets:install. This would throw an error that it could not connect to the database (which is obvious). Of course, running these kind of commands should not trigger a DB connection.

@gonzalovilaseca
Copy link
Contributor Author

@steffenbrem I believe the problem is not caused by my commit: I created a branch (git checkout -b test 0d6917c) without my commit and I'm getting the error you mention.

@koemeet
Copy link
Contributor

koemeet commented Nov 20, 2014

@gonzalovilaseca Hmm. I did not create a branch based of a commit previous to your PR, but I just commented your lines and the issue was gone. Sylius is kind of broken right now. Because you cannot run php app/console doctrine:database:create either! You will get the error message saying the database doesn't exist ;) So yeah, I think we need to fix this ASAP.

@pjedrzejewski Whats your opinion in this?

@koemeet
Copy link
Contributor

koemeet commented Nov 21, 2014

@gonzalovilaseca I see, I did a clean install of Sylius and it runs fine. Strange, looks like your commit only causes a problem in my own project.

This is the stacktrace I got when running php app/console --verbose:

Exception trace:
 () at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
 PDO->__construct() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
 Doctrine\DBAL\Driver\PDOConnection->__construct() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:45
 Doctrine\DBAL\Driver\PDOMySql\Driver->connect() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360
 Doctrine\DBAL\Connection->connect() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429
 Doctrine\DBAL\Connection->getDatabasePlatformVersion() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389
 Doctrine\DBAL\Connection->detectDatabasePlatform() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328
 Doctrine\DBAL\Connection->getDatabasePlatform() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:81
 Doctrine\ORM\Mapping\ClassMetadataFactory->initialize() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:292
 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:211
 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /Users/Steffen/Development/mangogroup/mango/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:295
 Doctrine\ORM\EntityManager->getClassMetadata() at /Users/Steffen/Development/mangogroup/mango/app/cache/dev/appDevDebugProjectContainer.php:15581
 appDevDebugProjectContainer->getSylius_Repository_ProductService() at /Users/Steffen/Development/mangogroup/mango/app/bootstrap.php.cache:2076
 Symfony\Component\DependencyInjection\Container->get() at /Users/Steffen/Development/mangogroup/mango/app/cache/dev/appDevDebugProjectContainer.php:16108
 appDevDebugProjectContainer->getSylius_RouteProviderService() at /Users/Steffen/Development/mangogroup/mango/app/bootstrap.php.cache:2076
 Symfony\Component\DependencyInjection\Container->get() at /Users/Steffen/Development/mangogroup/mango/app/cache/dev/appDevDebugProjectContainer.php:14734
 appDevDebugProjectContainer->getSylius_NestedMatcherService() at /Users/Steffen/Development/mangogroup/mango/app/bootstrap.php.cache:2076
 Symfony\Component\DependencyInjection\Container->get() at /Users/Steffen/Development/mangogroup/mango/app/cache/dev/appDevDebugProjectContainer.php:12693

You can see here that the following line in appDevDebugProjectContainer is triggering a DBAL connection because it is going to initialize the class metadata factory, which in turn will call initialize on the ORM\ClassMetadataFactory and it will get the database platform (and there, you need a connection for that).

return $this->services['sylius.repository.product'] = new \Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository($this->get('doctrine.orm.default_entity_manager'), $this->get('doctrine.orm.default_entity_manager')->getClassMetadata('Mango\\Component\\Core\\Model\\Product'));

Any idea why this could trigger an error in my project (that has a composer dependency on this sylius repo) and it is not triggered in latest Sylius?

For some reason, the database platform is already known by Sylius. But with my project it is unkown and trying to fetch it over the connection. I guess that is what happening. Now I only need to try and find why Sylius does not make a DB connection when it calls Doctrine\DBAL\Connection->getDatabasePlatform() and why my project does.

So I have found the culprit. I was using the dev-master for doctrine dbal. And in the latest revision they modified the getDatabasePlatform method. So this means that when this stays the same, Sylius will break when trying to upgrade to newer Doctrine versions. Should we leave it like this? Or try to make it work with the later Doctrine DBAL? @pjedrzejewski

I have used Symfony 2.6.x-dev and ~2.3, still same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants