Skip to content

[FrameworkBundle] Fix patching refs to the tmp warmup dir in files generated by optional cache warmers #59579

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

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@
}
$this->warmupOptionals($useBuildDir ? $realCacheDir : $warmupDir, $warmupDir, $io);
}

// fix references to cached files with the real cache directory name
$search = [$warmupDir, str_replace('/', '\\/', $warmupDir), str_replace('\\', '\\\\', $warmupDir)];
$replace = str_replace('\\', '/', $realBuildDir);
foreach (Finder::create()->files()->in($warmupDir) as $file) {
$content = str_replace($search, $replace, file_get_contents($file), $count);
if ($count) {
file_put_contents($file, $content);
}
}
}

if (!$fs->exists($warmupDir.'/'.$containerDir)) {
Expand Down Expand Up @@ -227,21 +237,11 @@
throw new \LogicException('Calling "cache:clear" with a kernel that does not implement "Symfony\Component\HttpKernel\RebootableInterface" is not supported.');
}
$kernel->reboot($warmupDir);

// fix references to cached files with the real cache directory name
$search = [$warmupDir, str_replace('\\', '\\\\', $warmupDir)];
$replace = str_replace('\\', '/', $realBuildDir);
foreach (Finder::create()->files()->in($warmupDir) as $file) {
$content = str_replace($search, $replace, file_get_contents($file), $count);
if ($count) {
file_put_contents($file, $content);
}
}
}

private function warmupOptionals(string $cacheDir, string $warmupDir, SymfonyStyle $io): void
{
$kernel = $this->getApplication()->getKernel();

Check failure on line 244 in src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedMethod

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:244:44: UndefinedMethod: Method Symfony\Component\Console\Application::getKernel does not exist (see https://psalm.dev/022)

Check failure on line 244 in src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedMethod

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:244:44: UndefinedMethod: Method Symfony\Component\Console\Application::getKernel does not exist (see https://psalm.dev/022)
$warmer = $kernel->getContainer()->get('cache_warmer');
// non optional warmers already ran during container compilation
$warmer->enableOnlyOptionalWarmers();
Expand Down
Loading