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

Doctrine 2.5: boot() breaks console command(s) #38

Closed
tomasz-janiczek opened this issue Oct 9, 2015 · 5 comments
Closed

Doctrine 2.5: boot() breaks console command(s) #38

tomasz-janiczek opened this issue Oct 9, 2015 · 5 comments

Comments

@tomasz-janiczek
Copy link

If I do the following:

app/console doctrine:database:drop --env=prod --force
app/console doctrine:database:create --env=prod

then

  1. first command runs fine
  2. second command fails with

[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[42000] [1049] Unknown database 'bv_api'

This is because of the following code:

   public function boot()
    {
        parent::boot();

        if($this->container->hasParameter('doctrine.entity_managers')){
            if(!Type::hasType(MoneyType::NAME)) {
                Type::addType(MoneyType::NAME, 'Tbbc\MoneyBundle\Type\MoneyType');
            }

            $entityManagerNameList = $this->container->getParameter('doctrine.entity_managers');
            foreach($entityManagerNameList as $entityManagerName) {
                $em = $this->container->get($entityManagerName);
                if (!$em->getConnection()->getDatabasePlatform()->hasDoctrineTypeMappingFor(MoneyType::NAME)) {
                    $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping(MoneyType::NAME, MoneyType::NAME);
                }
            }
        }
    }

The problem is the getDatabasePlatform() call and this issue with Doctrine/DBAL:
http://www.doctrine-project.org/jira/browse/DBAL-1057

Any workaround/fix for this available?
I know it's not the fault of the bundle, but still - would be nice to have something...

@philippe-levan
Copy link
Member

Hum... right now I don't have any solution. I will ask around me if someone has an idea... If you find a workaround, give me your solution.
Regards,
Philippe

@Richtermeister
Copy link

I just ran into this as well.

Imho the bundle should not register the types automatically. Adding a type to the project's doctrine configuration is a matter of one line http://symfony.com/doc/current/reference/configuration/doctrine.html#full-default-configuration and I see other bundles take that route as well.

@rdohms
Copy link

rdohms commented Feb 11, 2016

Yep had this as well, either it needs to make itself optional or go the configuration route.

@glynnforrest
Copy link
Contributor

See my pull request for a fix: #67

@geekdevs
Copy link
Collaborator

Done in #67

This is good for fixing this issue and prevent BC breaks for this version.
However I agree with @Richtermeister, for future major version I think we should remove auto-adding the type and recommend users to add it themselves.

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

No branches or pull requests

6 participants