2 // vim: foldmethod=marker
6 * @author ICHII Takashi <ichii386@schweetheart.jp>
7 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12 require_once ETHNA_BASE . '/class/Ethna_PearWrapper.php';
14 // {{{ Ethna_Plugin_Handle_ClearCache
18 * @author ICHII Takashi <ichii386@schweetheart.jp>
22 class Ethna_Plugin_Handle_ClearCache extends Ethna_Plugin_Handle
28 * @todo implement Ethna_Renderer::clear_cache();
29 * @todo implement Ethna_Plugin_Cachemanager::clear_cache();
30 * @todo avoid echo, printf
34 $r =& $this->_getopt(array('basedir=',
35 'any-tmp-files', 'smarty', 'pear', 'cachemanager'));
36 if (Ethna::isError($r)) {
41 $basedir = isset($args['basedir']) ? realpath(end($args['basedir'])) : getcwd();
42 $controller =& Ethna_Handle::getAppController($basedir);
43 if (Ethna::isError($controller)) {
46 $tmp_dir = $controller->getDirectory('tmp');
48 if (isset($args['smarty']) || isset($args['any-tmp-files'])) {
49 echo "cleaning smarty caches, compiled templates...";
50 $renderer =& $controller->getRenderer();
51 if (strtolower(get_class($renderer)) == "ethna_renderer_smarty") {
52 $renderer->engine->clear_all_cache();
53 $renderer->engine->clear_compiled_tpl();
58 if (isset($args['cachemanager']) || isset($args['any-tmp-files'])) {
59 echo "cleaning Ethna_Plugin_Cachemanager caches...";
60 $cache_dir = sprintf("%s/cache", $tmp_dir);
61 Ethna_Util::purgeDir($cache_dir);
65 if (isset($args['pear']) || isset($args['any-tmp-files'])) {
66 echo "cleaning pear caches...";
68 $pear =& new Ethna_PearWrapper();
69 $r =& $pear->init('local', $basedir);
70 if (Ethna::isError($r)) {
74 $r =& $pear->doClearCache();
75 if (Ethna::isError($r)) {
83 if (isset($args['any-tmp-files'])) {
84 echo "cleaning tmp dirs...";
85 // purge only entries in tmp.
86 if ($dh = opendir($tmp_dir)) {
87 while (($entry = readdir($dh)) !== false) {
88 if ($entry === '.' || $entry === '..') {
91 Ethna_Util::purgeDir("{$tmp_dir}/{$entry}");
101 // {{{ getDescription()
105 function getDescription()
108 clear project's cache files:
109 {$this->id} [-b|--basedir=dir] [-a|--any-tmp-files] [-s|--smarty] [-p|--pear] [-c|--cachemanager]
122 ethna {$this->id} [-b|--basedir=dir] [-a|--any-tmp-files] [-s|--smarty] [-p|--pear] [-c|--cachemanager]