Created
April 5, 2013 15:32
-
-
Save althaus/5320231 to your computer and use it in GitHub Desktop.
Extend the base cache clear command adding a little sleep to prevent issus on Windows with "Access denied" on the cache directories.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Althaus\ExtrasBundle\Command; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand as BaseCommand; | |
class CacheClearCommand extends BaseCommand | |
{ | |
/** | |
* @see Command | |
*/ | |
protected function configure() | |
{ | |
parent::configure(); | |
$this->setDescription('Clears the cache (incl. Windows workaround)'); | |
//$this->setName('cache:clr'); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir'); | |
$oldCacheDir = $realCacheDir.'_old'; | |
if (!is_writable($realCacheDir)) { | |
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir)); | |
} | |
$kernel = $this->getContainer()->get('kernel'); | |
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); | |
if ($input->getOption('no-warmup')) { | |
rename($realCacheDir, $oldCacheDir); | |
} else { | |
$warmupDir = $realCacheDir.'_new'; | |
$this->warmup($warmupDir); | |
rename($realCacheDir, $oldCacheDir); | |
sleep(1); | |
rename($warmupDir, $realCacheDir); | |
} | |
$this->getContainer()->get('filesystem')->remove($oldCacheDir); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment