/** * execute command * * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $subfolder = $input->getOption('subfolder'); if ($subfolder == null) { $output->writeln('<error>Sorry, you did not enter cache sub folder name.</error>'); unset($subfolder); return false; } if ($subfolder != null) { $Cache = new \System\Libraries\Cache(); $cache_config = $Cache->getCacheConfig(); $style = new \Symfony\Component\Console\Formatter\OutputFormatterStyle('white', 'green'); $output->getFormatter()->setStyle('success', $style); unset($style); if ($subfolder == '*') { // entered command to delete all cache. $Cache->deleteAllFile(); $output->writeln('<success>All cache was deleted successfully.</success>'); } else { if (is_array($cache_config) && array_key_exists('driver', $cache_config) && $cache_config['driver'] == 'Filesystem' && array_key_exists('cache_path', $cache_config)) { $adapter = new \League\Flysystem\Adapter\Local($cache_config['cache_path']); $Filesystem = new \League\Flysystem\Filesystem($adapter); $Filesystem->addPlugin(new \League\Flysystem\Plugin\ListPaths()); try { $Filesystem->getMetadata($subfolder); // selected sub folder exists. $Cache->setSubFolder($subfolder); $Cache->deleteAllFile(); unset($Filesystem); $output->writeln('<success>The cache inside "' . $subfolder . '" folder was deleted successfully.</success>'); } catch (\Exception $e) { $output->writeln('<error>The "' . $subfolder . '" cache folder is not found.</error>'); } unset($adapter, $Filesystem); } } unset($Cache, $cache_config); } unset($subfolder); }
/** * due to Doctrine cache deleteAll() cannot really delete file/folder for FilesystemCache, it just left old cache file and create new cache folder.<br> * this method is for really delete all cache and all file (in specified sub folder if it was set). * * @return boolean */ public function deleteAllFile() { $result = $this->deleteAll(); if (isset($this->cache_config['driver']) && $this->cache_config['driver'] == 'Filesystem' && isset($this->cache_config['cache_path'])) { $adapter = new \League\Flysystem\Adapter\Local($this->cache_config['cache_path']); $Filesystem = new \League\Flysystem\Filesystem($adapter); $Filesystem->addPlugin(new \League\Flysystem\Plugin\ListPaths()); if ($this->cache_config['cache_path'] . $this->subFolder == STORAGE_PATH . DS . 'cms' . DS . 'cache') { // sub folder may not set and cache path is match main cache folder. $files = $Filesystem->listPaths($this->subFolder); if (is_array($files)) { foreach ($files as $file) { if ($file != '.gitignore' && is_dir($this->cache_config['cache_path'] . $this->subFolder . '/' . $file)) { $Filesystem->deleteDir($file); } elseif ($file != '.gitignore' && is_file($this->cache_config['cache_path'] . $this->subFolder . '/' . $file)) { $Filesystem->delete($file); } } unset($file); } unset($files); } else { // sub folder is set. $files = $Filesystem->listPaths(''); if (is_array($files)) { foreach ($files as $file) { if (is_dir($this->cache_config['cache_path'] . '/' . $file)) { $Filesystem->deleteDir($file); } elseif (is_file($this->cache_config['cache_path'] . '/' . $file)) { $Filesystem->delete($file); } } unset($file); } unset($files); } } return $result; }