. */ /* */ /*************************************************************************************/ namespace Thelia\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Exception\IOException; use Thelia\Command\ContainerAwareCommand; /** * clear the cache * * Class CacheClear * @package Thelia\Command * @author Manuel Raynaud * */ class CacheClear extends ContainerAwareCommand { protected function configure() { $this ->setName("cache:clear") ->setDescription("Invalidate all caches") ->addOption( "without-assets", null, InputOption::VALUE_NONE, "remove cache assets" ) ; } protected function execute(InputInterface $input, OutputInterface $output) { $cacheDir = $this->getContainer()->getParameter("kernel.cache_dir"); $this->clearCache($cacheDir, $output); if (!$input->getOption("without-assets")) { $this->clearCache(THELIA_WEB_DIR . "/assets", $output); } } protected function clearCache($dir, OutputInterface $output) { if (!is_writable($dir)) { throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $dir)); } $output->writeln(sprintf("Clearing cache in %s directory", $dir)); $fs = new Filesystem(); try { $fs->remove($dir); $output->writeln(sprintf("%s cache dir cleared successfully", $dir)); } catch (IOException $e) { $output->writeln(sprintf("error during clearing cache : %s", $e->getMessage())); } } }