OSDN Git Service

- deleted pear cache file delete routine.
[ethna/ethna.git] / class / Plugin / Handle / ClearCache.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  ClearCache.php
5  *
6  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
7  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
8  *  @package    Ethna
9  *  @version    $Id$
10  */
11
12 require_once ETHNA_BASE . '/class/Ethna_PearWrapper.php';
13
14 // {{{ Ethna_Plugin_Handle_ClearCache
15 /**
16  *  clear-cache handler
17  *
18  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
19  *  @access     public
20  *  @package    Ethna
21  */
22 class Ethna_Plugin_Handle_ClearCache extends Ethna_Plugin_Handle
23 {
24     /**
25      *  clear cache files.
26      *
27      *  @access public
28      *  @todo   implement Ethna_Renderer::clear_cache();
29      *  @todo   implement Ethna_Plugin_Cachemanager::clear_cache();
30      *  @todo   avoid echo, printf
31      */
32     function perform()
33     {
34         $r =& $this->_getopt(array('basedir=', 
35                                    'any-tmp-files', 'smarty', 'pear', 'cachemanager'));
36         if (Ethna::isError($r)) {
37             return $r;
38         }
39         list($args,) = $r;
40
41         $basedir = isset($args['basedir']) ? realpath(end($args['basedir'])) : getcwd();
42         $controller =& Ethna_Handle::getAppController($basedir);
43         if (Ethna::isError($controller)) {
44             return $controller;
45         }
46         $tmp_dir = $controller->getDirectory('tmp');
47
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();
54             }
55             echo " done\n";
56         }
57
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);
62             echo " done\n";
63         }
64
65         if (isset($args['any-tmp-files'])) {
66             echo "cleaning tmp dirs...";
67             // purge only entries in tmp.
68             if ($dh = opendir($tmp_dir)) {
69                 while (($entry = readdir($dh)) !== false) {
70                     if ($entry === '.' || $entry === '..') {
71                         continue;
72                     }
73                     Ethna_Util::purgeDir("{$tmp_dir}/{$entry}");
74                 }
75                 closedir($dh);
76             }
77             echo " done\n";
78         }
79
80         return true;
81     }
82
83     // {{{ getDescription()
84     /**
85      *  @access public
86      */
87     function getDescription()
88     {
89         return <<<EOS
90 clear project's cache files:
91     {$this->id} [-b|--basedir=dir] [-a|--any-tmp-files] [-s|--smarty] [-p|--pear] [-c|--cachemanager]
92
93 EOS;
94     }
95     // }}}
96
97     // {{{ getUsage()
98     /**
99      *  @access public
100      */
101     function getUsage()
102     {
103         return <<<EOS
104 ethna {$this->id} [-b|--basedir=dir] [-a|--any-tmp-files] [-s|--smarty] [-p|--pear] [-c|--cachemanager]
105 EOS;
106     }
107     // }}}
108 }
109 // }}}
110 ?>