Skip to content

Instantly share code, notes, and snippets.

@junichi11
Created October 18, 2011 12:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junichi11/1295294 to your computer and use it in GitHub Desktop.
Save junichi11/1295294 to your computer and use it in GitHub Desktop.
Clear Cache Shell for CakePHP2.0
<?php
/**
* CakePHP ClearCacheShell for 2.0
* @author junichi11
*/
class ClearCacheShell extends AppShell {
public $uses = array();
public $task = array();
private $clearDir = array('models', 'persistent', 'views');
public function main() {
$clearCache = null;
if(!empty($this->params['type'])){
$clearCache = clearCache(null, $this->args[0], null);
$this->_viewResult($clearCache, $this->args[0]);
return;
}
foreach($this->clearDir as $dir){
$clearCache = clearCache(null, $dir);
$this->_viewResult($clearCache, $dir);
}
}
protected function _viewResult($clearCache, $type) {
if ($clearCache) {
$this->out(__("%s : Success!", $type));
} else {
$this->out(__("%s : Failure!", $type));
}
}
public function getOptionParser(){
$parser = parent::getOptionParser();
return $parser->description(__('Clear files in the app/tmp/cache.'))
->addOption('type', array(
'help' => __('File type (directory name).'),
'boolean' => true
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment