Skip to content

Commit

Permalink
bug symfony#50253 [FrameworkBundle] Generate caches consistently on s…
Browse files Browse the repository at this point in the history
…uccessive run of `cache:clear` command
  • Loading branch information
Okhoshi committed May 14, 2023
1 parent 8c637a5 commit 1f0e7cd
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
Expand Up @@ -129,14 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($output->isVerbose()) {
$io->comment('Warming up optional cache...');
}
$warmer = $kernel->getContainer()->get('cache_warmer');
// non optional warmers already ran during container compilation
$warmer->enableOnlyOptionalWarmers();
$preload = (array) $warmer->warmUp($realCacheDir, $io);

if ($preload && file_exists($preloadFile = $realCacheDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
Preloader::append($preloadFile, $preload);
}
$this->warmupOptionals($io, $realCacheDir);
}
} else {
$fs->mkdir($warmupDir);
Expand All @@ -145,7 +138,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($output->isVerbose()) {
$io->comment('Warming up cache...');
}
$this->warmup($io, $warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
$this->warmup($warmupDir, $realBuildDir);

if (!$input->getOption('no-optional-warmers')) {
if ($output->isVerbose()) {
$io->comment('Warming up optional cache...');
}
$this->warmupOptionals($io, $realCacheDir);
}
}

if (!$fs->exists($warmupDir.'/'.$containerDir)) {
Expand Down Expand Up @@ -219,7 +219,7 @@ private function isNfs(string $dir): bool
return false;
}

private function warmup(SymfonyStyle $io, string $warmupDir, string $realBuildDir, bool $enableOptionalWarmers = true): void
private function warmup(string $warmupDir, string $realBuildDir): void
{
// create a temporary kernel
$kernel = $this->getApplication()->getKernel();
Expand All @@ -228,18 +228,6 @@ private function warmup(SymfonyStyle $io, string $warmupDir, string $realBuildDi
}
$kernel->reboot($warmupDir);

// warmup temporary dir
if ($enableOptionalWarmers) {
$warmer = $kernel->getContainer()->get('cache_warmer');
// non optional warmers already ran during container compilation
$warmer->enableOnlyOptionalWarmers();
$preload = (array) $warmer->warmUp($warmupDir, $io);

if ($preload && file_exists($preloadFile = $warmupDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
Preloader::append($preloadFile, $preload);
}
}

// fix references to cached files with the real cache directory name
$search = [$warmupDir, str_replace('\\', '\\\\', $warmupDir)];
$replace = str_replace('\\', '/', $realBuildDir);
Expand All @@ -250,4 +238,17 @@ private function warmup(SymfonyStyle $io, string $warmupDir, string $realBuildDi
}
}
}

private function warmupOptionals(SymfonyStyle $io, string $realCacheDir): void
{
$kernel = $this->getApplication()->getKernel();
$warmer = $kernel->getContainer()->get('cache_warmer');
// non optional warmers already ran during container compilation
$warmer->enableOnlyOptionalWarmers();
$preload = (array) $warmer->warmUp($realCacheDir, $io);

if ($preload && file_exists($preloadFile = $realCacheDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
Preloader::append($preloadFile, $preload);
}
}
}

0 comments on commit 1f0e7cd

Please sign in to comment.