-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
Fixes for compatibility with DBAL 3 #1263
Conversation
Looks good so far, ask me to review after it's no longer draft please. |
I need to revert the The alternative to that would be to merge and release doctrine/dbal#4386 |
740f645
to
3171edc
Compare
@@ -23,11 +23,7 @@ | |||
<service id="Doctrine\DBAL\Driver\Connection" alias="database_connection" public="false" /> | |||
<service id="Doctrine\DBAL\Connection" alias="database_connection" public="false" /> | |||
|
|||
<service id="doctrine.dbal.logger.chain" class="%doctrine.dbal.logger.chain.class%" public="false" abstract="true"> | |||
<call method="addLogger"> | |||
<argument type="service" id="doctrine.dbal.logger" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't this call needed ? I don't see its replacement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The replacement is in PHP, it's the very first lines of this PR
3171edc
to
9ee90f7
Compare
$chainLogger->addMethodCall('addLogger', [$profilingLogger]); | ||
} else { | ||
$chainLogger->addArgument([$profilingLogger]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof here is the replacement you asked for in https://github.com/doctrine/DoctrineBundle/pull/1263/files#r524450538 (I think it's equivalent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not equivalent. As you need to pass an array of loggers to the constructor rather than multiple calls to addLogger
, you need to build an array containing them all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there is only one logger before this PR, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you suggesting exactly? This?
$chainLogger->replaceArgument(
0,
array_merge($chainLogger->getArgument(0), [$logger])
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. Cases where the chain logger are used are precisely cases where we have 2 loggers:
doctrine.dbal.logger
logging to your app PSR-3 logger (generally Monolog)- the profiling logger which logs query executions for the profiler
Your suggestion won't work if the reference to doctrine.dbal.logger
is added to the constructor of the doctrine.dbal.logger.chain
abstract definition, because the child definition won't have anything yet for the argument. Instead, you should just use [$logger, $profilingLogger]
as the value of the argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof none of the calls to addLogger
in this codebase are performed on the same service. I don't get your point.
UPD: didn't see your answer, I will try that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the existing code, the call done in XML is done on the abstract service definition which is extended by the definitions in each of the DBAL connections.
so after resolving the definition inheritance, each chain logger will have 2 addLogger
calls:
- the one inherited from the abstract definition for
doctrine.dbal.logger
- the one set on themselves for the connection-specific profiling logger.
@@ -85,6 +87,14 @@ protected function dbalLoad(array $config, ContainerBuilder $container) | |||
{ | |||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | |||
$loader->load('dbal.xml'); | |||
$chainLogger = $container->getDefinition('doctrine.dbal.logger.chain'); | |||
$profilingLogger = new Reference('doctrine.dbal.logger'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable name is really confusing, as doctrine.dbal.logger
is not the profiling logger, but the logger logging your queries in the Symfony logs through PSR-3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
9ee90f7
to
e41eca2
Compare
e41eca2
to
a34fb11
Compare
$container = $this->createDbalOnlyTestContainer(); | ||
$this->assertInstanceOf( | ||
LoggerChain::class, | ||
$container->get('doctrine.dbal.logger.chain.default') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have messed up somewhere because although the service definition has 2 loggers, that object has only one when I dump
it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh but when I remove the first else
branch in this PR, it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment on the broken code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed, does it look correct or do I still misunderstand? Sorry, I'm quite tired today 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// doctrine/dbal < 2.10.0 | ||
$chainLogger->addMethodCall('addLogger', [$logger]); | ||
} else { | ||
$chainLogger->addArgument([$logger]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this must be removed. You are adding an argument here with an array with 1 element, and then later adding a second argument with an array with 2 elements. But the ChainLogger expects the list of loggers as its first argument so that's why things don't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an alternative would be to use replaceArgument
in the ChildDefinition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be better 🤔 in case people are using the abstract service definition to build their custom service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed again, this time with replaceArgument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if they use it to build their own custom service, they will need to change their code for the DBAL 3 way anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I'm switching to the constructor as soon as possible (2.10.0), not as late as possible (3.0.0), because a deprecation layer might be added later on the DBAL. This means people using DBAL >=2.10 and building their own custom service should need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed again, this time with
replaceArgument
We could even go a cleaner way to prepare for the day we will require DBAL 2.10+ in the bundle (hopefully soon, if the PR adding back PHP 7.1 support in 2.12 is accepted):
- stop using
ChildDefinition
inloadDbalConnection
but a normalDefinition
using the chainlogger class (this requires adding theaddLogger
call for$logger
in the branch dealing with DBAL 2.9, but that's fine) - mark the
doctrine.dbal.logger.chain
abstract service as deprecated (in case someone was using it for their own service)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does seem more straightforward, let me try 👍
$container = $this->createDbalOnlyTestContainer(); | ||
$this->assertInstanceOf( | ||
LoggerChain::class, | ||
$container->get('doctrine.dbal.logger.chain.default') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment on the broken code.
a0268d8
to
065a36c
Compare
<argument type="service" id="doctrine.dbal.logger" /> | ||
</call> | ||
<service id="doctrine.dbal.logger.chain" class="%doctrine.dbal.logger.chain.class%" public="false" abstract="true" > | ||
<!-- TODO: deprecate this service in 2.3.0 --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof introducing a new deprecation is minor, so I should do it in a subsequent PR to master I think.
1597913
to
b9d53b7
Compare
Passing them through addLogger() is deprecated and no longer works with DBAL 3 which we support.
That command is built from Doctrine\DBAL\Tools\Console\Command\ImportCommand, which no longer exists in DBAL 3 (it is removed in favor of using a client application).
b9d53b7
to
b79661a
Compare
@stof can you please give this another review? |
I suppose the 2 existing reviews are enough already :) |
@greg0ire I think we need some of those changes also on 1.12.x, or? As it also allows installing dbal 3: https://github.com/doctrine/DoctrineBundle/blob/1.12.x/composer.json#L29 |
@dmaicher you're right, I had no idea dbal 3 was supported on 1.12.x (or why, it sounds weird, since that version of the bundle is supposed to be left unmaintained soon). |
Yeah I also just found out while debugging some travis CI failures while working on dmaicher/doctrine-test-bundle#136 😕 |
with symfony 3.4 out of maintenance, 1.12.x is pretty much dead now, all that is left is just officially mark it as unmaintained on website config |
I tested this on a real project, it allows to install the project without errors.
Fixes #1262 , fixes #1264
How can I test this?
composer config repositories.greg0ire vcs https://github.com/greg0ire/DoctrineBundle composer require doctrine/doctrine-bundle "dev-dbal-3-compat as 2.2.1"