From 137d472838bd299a6a4cd898565ed06d7e67f4c7 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 8 Feb 2013 00:29:03 +0400 Subject: [PATCH] console command to flush cache --- framework/console/Application.php | 1 + framework/console/controllers/CacheController.php | 49 +++++++++++++++++++++++ todo.md | 3 +- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 framework/console/controllers/CacheController.php diff --git a/framework/console/Application.php b/framework/console/Application.php index 5b7d190..fb579e2 100644 --- a/framework/console/Application.php +++ b/framework/console/Application.php @@ -127,6 +127,7 @@ class Application extends \yii\base\Application 'help' => 'yii\console\controllers\HelpController', 'migrate' => 'yii\console\controllers\MigrateController', 'app' => 'yii\console\controllers\CreateController', + 'cache' => 'yii\console\controllers\CacheController', ); } diff --git a/framework/console/controllers/CacheController.php b/framework/console/controllers/CacheController.php new file mode 100644 index 0000000..866db12 --- /dev/null +++ b/framework/console/controllers/CacheController.php @@ -0,0 +1,49 @@ + + * @since 2.0 + */ +class CacheController extends Controller +{ + public function actionIndex() + { + $this->forward('help/index', array('-args' => array('cache/flush'))); + } + + /** + * Flushes cache. + * @param string $component Name of the cache application component to use. + * + * @throws \yii\console\Exception + */ + public function actionFlush($component = 'cache') + { + /** @var $cache Cache */ + $cache = \Yii::$app->getComponent($component); + if(!$cache || !$cache instanceof Cache) { + throw new Exception('Application component "'.$component.'" is not defined or not a cache.'); + } + + if(!$cache->flush()) { + throw new Exception('Unable to flush cache.'); + } + + echo "\nDone.\n"; + } +} diff --git a/todo.md b/todo.md index 60e37c5..7249235 100644 --- a/todo.md +++ b/todo.md @@ -13,8 +13,7 @@ * ProfileTarget (TBD after web is in place): should consider using javascript and make it into a toolbar * unit tests - caching - * a console command to clear cached data - * unit tests + * backend-specific unit tests - validators * FileValidator: depends on CUploadedFile * CaptchaValidator: depends on CaptchaAction