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

Clear the dev cache in the script handler #1369

Merged
merged 2 commits into from
Feb 26, 2020
Merged

Clear the dev cache in the script handler #1369

merged 2 commits into from
Feb 26, 2020

Conversation

Toflar
Copy link
Member

@Toflar Toflar commented Feb 20, 2020

Fixes #1361

@Toflar Toflar self-assigned this Feb 20, 2020
@Toflar Toflar changed the base branch from master to 4.9 February 20, 2020 15:41
@leofeyer leofeyer added this to the 4.9 milestone Feb 20, 2020
@leofeyer leofeyer added the bug label Feb 20, 2020
@fritzmg
Copy link
Contributor

fritzmg commented Feb 20, 2020

Aren't these commands executed in the current environment anyway? Thus, if you do

static::executeCommand('cache:clear --no-warmup', $event);
static::executeCommand('cache:clear --no-warmup --env=dev', $event);

and you configured the APP_ENV to be dev currently, the production cache will not actually get deleted, since it clears the dev cache both times.

@Toflar
Copy link
Member Author

Toflar commented Feb 20, 2020

Correct. That's your mistake then, isn't it?

@fritzmg
Copy link
Contributor

fritzmg commented Feb 20, 2020

Not sure what you mean. This change is supposed to fix an issue that occurs, if you switch the environment, after a composer update/install for example. I am just showing, that this would only fix it, if you go from prod to dev, but not from dev to prod.

@leofeyer leofeyer added the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Feb 21, 2020
@fritzmg fritzmg mentioned this pull request Feb 21, 2020
@ausi
Copy link
Member

ausi commented Feb 23, 2020

@fritzmg you mean we should use something like this?

static::executeCommand('cache:clear --no-warmup --env=prod', $event);
static::executeCommand('cache:clear --no-warmup --env=dev', $event);

@fritzmg
Copy link
Contributor

fritzmg commented Feb 23, 2020

Possibly. @Tastaturberuf mentioned in #1357, that apparently the Script Handler will always use prod. Haven't confirmed this myself yet.

Copy link
Member

@aschempp aschempp left a comment

Choose a reason for hiding this comment

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

if we wanna clear both environments, then adding --env=prod to the first call would certainly be correct.

@Toflar
Copy link
Member Author

Toflar commented Feb 24, 2020

I actually found the issue. We were using getenv('APP_ENV') which only works with real environment variables because at the time the script handler is executed, no .env file is handled.
We have to be explicit about our environments, I think it's correct now.

@leofeyer leofeyer removed the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Feb 24, 2020
@fritzmg
Copy link
Contributor

fritzmg commented Feb 24, 2020

Shouldn't this be changed in Contao 4.4 as well?

@leofeyer leofeyer merged commit ea86972 into 4.9 Feb 26, 2020
@leofeyer leofeyer deleted the clear-dev-cache branch February 26, 2020 17:00
@leofeyer leofeyer changed the title Clear dev cache Clear the dev cache in the script handler Feb 26, 2020
@leofeyer
Copy link
Member

Thank you @Toflar.

@fritzmg
Copy link
Contributor

fritzmg commented Feb 28, 2020

For some reason this is not working:

Contents of var/cache/dev after a request to the back end for example has been made, with APP_ENV=dev:

annotations.map
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.php
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.php.meta
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.preload.php
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.xml
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.xml.meta
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainerCompiler.log
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainerDeprecations.log
ContainerDBMJOYw
ContainerYxAQez3
ContainerYxAQez3.legacy
doctrine
pools
profiler
twig
UrlGenerator.php
UrlGenerator.php.meta
UrlMatcher.php
UrlMatcher.php.meta

composer install output (excerpt):

> Contao\ManagerBundle\Composer\ScriptHandler::initializeApplication
Added the web/app.php file.
Added the web/index.php file.
Added the web/preview.php file.

 // Clearing the cache for the prod environment with debug false


 [OK] Cache for the "prod" environment (debug=false) was successfully cleared.



 // Clearing the cache for the dev environment with debug true


 [OK] Cache for the "dev" environment (debug=true) was successfully cleared.



 // Warming up the cache for the prod environment with debug false


 [OK] Cache for the "prod" environment (debug=false) was successfully warmed.



 Trying to install assets as relative symbolic links.

Contents of var/cache/dev after composer install:

annotations.map
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.php
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.php.meta
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.preload.php
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.xml
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainer.xml.meta
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainerCompiler.log
appContao_ManagerBundle_HttpKernel_ContaoKernelDevDebugContainerDeprecations.log
ContainerDBMJOYw
ContainerYxAQez3
ContainerYxAQez3.legacy
doctrine
pools
profiler
twig
UrlGenerator.php
UrlGenerator.php.meta
UrlMatcher.php
UrlMatcher.php.meta

Contents of var/cache/dev after cache:clear --no-warmup --env=dev:

ContainerDBMJOYw
ContainerDBMJOYw.legacy

I noticed this after installing an extension, while having APP_ENV=dev in my .env. Once installed, no services, routes or templates of that package where available. I had to manually clear the dev cache, even though it was supposed to be cleared during the composer process.

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

Successfully merging this pull request may close these issues.

Dev-Cache wird nicht automatisch erneuert
5 participants