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

DBALConnectionFactory opens db connection, even if its not necessary #521

Merged
merged 2 commits into from
Jan 17, 2017

Conversation

IceShack
Copy link
Contributor

@IceShack IceShack commented Jan 16, 2017

Hi guys,

We sometimes got the issue that our app can't connect to our database.
Right now we just get a "ServiceNotCreatedException", because the DBALConnectionFactory opens a db connection while creating the connection services.

This fix only opens a db connection, if needed.
That way we can catch the ConnectionException in our controller/business logic and return a proper response.

$platform->registerDoctrineTypeMapping($dbType, $doctrineType);
}

foreach ($options->getDoctrineCommentedTypes() as $type) {
Copy link
Member

Choose a reason for hiding this comment

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

This is a hidden addition that isn't tested

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was there all along, i only added the if.

@@ -60,13 +60,16 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$eventManager = $container->get($options->getEventManager());

$connection = DriverManager::getConnection($params, $configuration, $eventManager);
$platform = $connection->getDatabasePlatform();
foreach ($options->getDoctrineTypeMappings() as $dbType => $doctrineType) {
$platform->registerDoctrineTypeMapping($dbType, $doctrineType);
Copy link
Member

Choose a reason for hiding this comment

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

A simpler fix is to simply this change this line to $connection->getDatabasePlatform()->registerDoctrineTypeMapping($dbType, $doctrineType);

@Ocramius Ocramius added the Bug Something isn't working label Jan 16, 2017
@Ocramius
Copy link
Member

LGTM 👍

@TomHAnderson TomHAnderson merged commit 928a657 into doctrine:master Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants