* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage install */ /** * make tool flush cache * * remove all cache files * * @version 1.0.0 * @package wombatSite * @subpackage install */ class wbMaker_ClearCache extends wbMaker { /** * information * * @access private * @var array $_info */ var $_info = array( 'maker' => 'ClearCache', 'state' => 'new', 'brief' => 'Remove all cache files', 'msg' => '' ); /** * location of var dir * * relative to baseDir * * @access private * @var string $_varDir */ var $_varDir = 'var'; /** * base dir of this instance * * @access private * @var string $_baseDir */ var $_baseDir; /** * location of cache files * * @access private * @var string $_cacheDir */ var $_cacheDir = 'cache'; /** * list unlinked files * * @access private * @var string $_removed */ var $_removed = array(); /** * bring birth! * * @access public * @return boolean $result true on success */ function __construct() { $this->_baseDir = wbFactory::getParam( 'baseDir' ); $this->_varDir = wbFactory::getParam( 'varDir' ); } /** * php4 constructor wrapper * * @access public * @see __construct() */ function wbMaker_ClearCache() { $this->__construct(); } /** * run... * * @access public * @return boolean true on success, false if any target has failed (or patError object on error!) */ function make() { $base = $this->_baseDir . '/' . $this->_varDir . '/' . $this->_cacheDir; // create base folder if( !is_dir( $base ) ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Cache directory "'. $base .'" not found!'; } $this->_removeFiles( $base ); $this->_info['msg'] = 'Removed '. count( $this->_removed ) .' cache files.'; return true; } /** * remove files recursively * * @access private * @param string $base start directory * @return boolean $result true on success */ function _removeFiles( $base ) { wbDebugger::addMsg( 'Make', 'Clear cachefiles in "'. $base .'"', 'ClearCache' ); $dir = dir( $base ); if( !$dir ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Could not open directory "'. $base .'" for reading!'; return false; } while( false !== ( $entry = $dir->read() ) ) { // skip hidden files and directories if( $entry[0] == '.' ) { continue; } // remove files recursively if( is_dir( $base . '/' . $entry ) ) { if( !$this->_removeFiles( $base . '/' . $entry ) ) { return false; } continue; } // remove normal file if( !unlink( $base . '/' . $entry ) ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Could not remove file "'. $base . '/' . $entry .'" for reading!'; return false; } array_push( $this->_removed, $base . '/' . $entry ); } return true; } } ?>