-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
CacheWarmerAggregate handle deprecations logs #27421
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
CacheWarmerAggregate handle deprecations logs #27421
Conversation
@@ -32,6 +32,8 @@ | |||
|
|||
<service id="cache_warmer" class="Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate" public="true"> | |||
<argument type="tagged" tag="kernel.cache_warmer" /> | |||
<argument>%kernel.debug%</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.
CacheWarmerAggregate
is annoted as final, so it shouldn't be BCBreak
61eb2e1
to
ed92377
Compare
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.
thanks for working on this, it's been missing a lot!
{ | ||
$this->warmers = $warmers; | ||
$this->debug = $debug; | ||
$this->containerPathPrefix = $containerPathPrefix; |
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'd suggest to pass the path of the deprecation file instead, not only the prefix
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.
$containerPathPrefix
became $deprecationLogsFilepath
with the right argument.
|
||
$warmer->warmUp($cacheDir); | ||
file_put_contents($this->containerPathPrefix.'Deprecations.log', serialize(array_values($collectedLogs))); | ||
restore_error_handler(); |
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 call should be the 1st in the "if" so that we're sure it's always restored correctly
ed92377
to
1da0b71
Compare
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.
LGTM, with one minor comment.
|
||
$warmer->warmUp($cacheDir); | ||
if (file_exists($file = $this->deprecationLogsFilepath)) { |
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 need for the $file tmp var now
1da0b71
to
3e473ee
Compare
} | ||
} finally { | ||
if ($this->debug && true !== $previousHandler) { |
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've also prepare a test scenario with a cacheWarmer who throw deprecations but here I'm directly in conflict with #25413 (fixing #24767). It can't pass in this condition during the test and it's right.
Here was my test code (CacheWarmerAggregateTest):
public function testWarmupWithDeprecationLogs()
{
$cacheDir = self::$cacheDir;
$warmer = $this->getCacheWarmerMock();
$warmer
->expects($this->once())
->method('warmUp')
->with($cacheDir)
->will($this->returnValue($this->throwDeprecation()));
;
$deprecationLogsFilepath = self::$cacheDir.'/Deprecations.log';
$aggregate = new CacheWarmerAggregate(array($warmer), true, $deprecationLogsFilepath);
$aggregate->warmUp($cacheDir);
$this->assertTrue(file_exists($deprecationLogsFilepath));
$this->assertCount(1, unserialize(file_get_contents($deprecationLogsFilepath)));
}
protected function throwDeprecation()
{
@trigger_error('Deprecation Message', E_USER_DEPRECATED);
}
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.
Unsetting the env var temporarily should be doable?
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've try many solution, and even temporarily removing the defined constant (runkit_constant_remove), deprecations have a different behavior during phpunit test. Still looking to find a solution and test 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.
ok, let's forget about it :):
4d499a7
to
1cbe807
Compare
1cbe807
to
f6c3851
Compare
continue; | ||
if ($this->debug) { | ||
$collectedLogs = array(); | ||
$previousHandler = defined('PHPUNIT_COMPOSER_INSTALL'); |
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.
Why do we 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.
If you're talking about the definition of PHPUNIT_COMPOSER_INSTALL
it's related to #25413
f6c3851
to
f03b8bb
Compare
Thank you @ScullWM. |
This PR was merged into the 4.2-dev branch. Discussion ---------- CacheWarmerAggregate handle deprecations logs | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #27387 | License | MIT Actually the Web Debug Toolbar warning you about the deprecation messages thrown during the container built (#21502). Cache warmup can throw deprecated message without any persistance, it may cause issue like #27387 This PR reproduce the same job for the cache warmer, and so on, handle deprecated messages during the warmup of Twig, Translator, Validator, Security and all `kernel.cache_warmer` services. Here are the point that may be improvable in this PR: 1. Actually I've "duplicate" the callable used in the `set_error_handler` of the Kernel. IMHO I think that Kernel and CacheWarmerAggregate have differents jobs and a trait may be a good solution to share this error handler setter without duplicating the code, but I'm a little bit lost about the repercussion of adding a Trait in the Kernel. 2. I've think about extending the `CacheWarmerAggregate` into a `DeprecatedLogHandlingCacheWarmerAggregate` to add the debug and containerClass argument, and declare it as the `cache_warmer` service only in debug mode (by declaring it in the DebugBundle/Resources/config/services.xml). Commits ------- f03b8bb CacheWarmerAggregate handle deprecations logs
What about having separate files for the warmer deprecations and the container deprecations ? It would avoid having to read the existing file to merge deprecations with the existing ones (which might cause issues if you run |
Actually the Web Debug Toolbar warning you about the deprecation messages thrown during the container built (#21502).
Cache warmup can throw deprecated message without any persistance, it may cause issue like #27387
This PR reproduce the same job for the cache warmer, and so on, handle deprecated messages during the warmup of Twig, Translator, Validator, Security and all
kernel.cache_warmer
services.Here are the point that may be improvable in this PR:
Actually I've "duplicate" the callable used in the
set_error_handler
of the Kernel.IMHO I think that Kernel and CacheWarmerAggregate have differents jobs and a trait may be a good solution to share this error handler setter without duplicating the code, but I'm a little bit lost about the repercussion of adding a Trait in the Kernel.
I've think about extending the
CacheWarmerAggregate
into aDeprecatedLogHandlingCacheWarmerAggregate
to add the debug and containerClass argument, and declare it as thecache_warmer
service only in debug mode (by declaring it in the DebugBundle/Resources/config/services.xml).