From fa3f8a3bf9c0ba23aa5be237cdcdad19347c4eba Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Jun 2013 15:00:07 +0200 Subject: [PATCH] complete cache:clear command --- Thelia | 4 ++-- core/lib/Thelia/Command/ClearCacheCommand.php | 13 +++++++++++-- core/lib/Thelia/Core/Application.php | 3 +++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Thelia b/Thelia index 31eed0c01..2aaa3c3e5 100755 --- a/Thelia +++ b/Thelia @@ -10,8 +10,8 @@ use Thelia\Core\Application; use Symfony\Component\Console\Input\ArgvInput; $input = new ArgvInput(); -$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); -$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; +$env = $input->getParameterOption(array('--env', '-e'), getenv('THELIA_ENV') ?: 'dev'); +$debug = getenv('THELIA_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; $thelia = new Thelia($env, $debug); $application = new Application($thelia); diff --git a/core/lib/Thelia/Command/ClearCacheCommand.php b/core/lib/Thelia/Command/ClearCacheCommand.php index d6d058519..6ce20a32c 100644 --- a/core/lib/Thelia/Command/ClearCacheCommand.php +++ b/core/lib/Thelia/Command/ClearCacheCommand.php @@ -36,7 +36,7 @@ class ClearCacheCommand extends Command protected function configure() { $this - ->setName("clear:cache") + ->setName("cache:clear") ->setDescription("Invalidate all caches"); } @@ -49,7 +49,16 @@ class ClearCacheCommand extends Command throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $cacheDir)); } + $output->writeln(sprintf("Clearing cache in %s directory", $cacheDir)); + $fs = new Filesystem(); - $fs->remove($this->getApplication()->getKernel()->getContainer()->getParameter("kernel.cache_dir")); + try { + $fs->remove($cacheDir); + + $output->writeln("cache clear successfully"); + } catch(IOException $e) { + $output->writeln(sprintf("error during clearing cache : %s", $e->getMessage())); + } + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Application.php b/core/lib/Thelia/Core/Application.php index be2cdb46a..1a47fa263 100644 --- a/core/lib/Thelia/Core/Application.php +++ b/core/lib/Thelia/Core/Application.php @@ -40,6 +40,9 @@ class Application extends BaseApplication $this->kernel = $kernel; parent::__construct("Thelia", Thelia::THELIA_VERSION); + + $this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment())); + $this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')); } public function getKernel()