Skip to content

Commit

Permalink
[FrameworkBundle] fix cache:clear command
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Dec 16, 2014
1 parent 206ebc7 commit a14153a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
Expand Up @@ -74,6 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
// the warmup cache dir name must have the same length than the real one
// to avoid the many problems in serialized resources files
$realCacheDir = realpath($realCacheDir);
$warmupDir = substr($realCacheDir, 0, -1).'_';

if ($filesystem->exists($warmupDir)) {
Expand Down Expand Up @@ -165,12 +166,14 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
*/
protected function getTempKernel(KernelInterface $parent, $namespace, $parentClass, $warmupDir)
{
$rootDir = $parent->getRootDir();
$cacheDir = var_export($warmupDir, true);
$rootDir = var_export(realpath($parent->getRootDir()), true);
$logDir = var_export(realpath($parent->getLogDir()), true);
// the temp kernel class name must have the same length than the real one
// to avoid the many problems in serialized resources files
$class = substr($parentClass, 0, -1).'_';
// the temp kernel name must be changed too
$name = substr($parent->getName(), 0, -1).'_';
$name = var_export(substr($parent->getName(), 0, -1).'_', true);
$code = <<<EOF
<?php
Expand All @@ -180,17 +183,22 @@ class $class extends $parentClass
{
public function getCacheDir()
{
return '$warmupDir';
return $cacheDir;
}
public function getName()
{
return '$name';
return $name;
}
public function getRootDir()
{
return '$rootDir';
return $rootDir;
}
public function getLogDir()
{
return $logDir;
}
protected function buildContainer()
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -586,12 +586,12 @@ protected function getKernelParameters()

return array_merge(
array(
'kernel.root_dir' => $this->rootDir,
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
'kernel.environment' => $this->environment,
'kernel.debug' => $this->debug,
'kernel.name' => $this->name,
'kernel.cache_dir' => $this->getCacheDir(),
'kernel.logs_dir' => $this->getLogDir(),
'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(),

This comment has been minimized.

Copy link
@inri13666

inri13666 Feb 18, 2019

Following changes make unavailable to use cache/log/root folders as a symlink, for example, to get better performance or other matters.
I have configured the var/cache folder to another drive, for example, it's pointed to the memory drive

mkdir Z:\quick\cache
mklink /J d:\symfony\var\cache Z:\quick\cache

and then I got following result

echo realpath($this->getCacheDir())
echo $this->getCacheDir()

will output following

Z:\quick\cache
D:\symfony\var\cache

This comment has been minimized.

Copy link
@inri13666

inri13666 Feb 18, 2019

Right now this issue can be quickly solved by adding env variables like following

  • SYMFONY__KERNEL__ROOT_DIR
  • SYMFONY__KERNEL__CACHE_DIR
  • SYMFONY__KERNEL__LOGS_DIR
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
'kernel.bundles' => $bundles,
'kernel.charset' => $this->getCharset(),
'kernel.container_class' => $this->getContainerClass(),
Expand Down

0 comments on commit a14153a

Please sign in to comment.