Skip to content

Commit

Permalink
moving delete method into a model (preparing to make croogo plugin)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricog committed May 24, 2011
1 parent 05f2d3b commit 721d080
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
25 changes: 25 additions & 0 deletions models/clear_cache_clear_cache.php
@@ -0,0 +1,25 @@
<?php
class ClearCacheClearCache extends ClearCacheAppModel {
var $name = 'ClearCacheClearCache';
var $useTable = false;

public function delete($path = null) {
if (!$path) {
$path = TMP . 'cache' . DS;
}
$dirItems = scandir($path);
$ignore = array('.', '..');
foreach ($dirItems AS $dirItem) {
if (in_array($dirItem, $ignore)) {
continue;
}

if (is_dir($path . $dirItem)) {
$this->delete($path . $dirItem . DS);
} elseif (substr($dirItem, 0, 5) == 'cake_') {
unlink($path . $dirItem);
}
}
}
}

25 changes: 3 additions & 22 deletions vendors/shells/clear_cache.php
Expand Up @@ -15,34 +15,15 @@
* @link http://fahad19.com/blog/clear-cache-plugin-for-cakephp
*/
class ClearCacheShell extends Shell {
var $uses = array('ClearCache.ClearCacheClearCache');
/**
* Delete all cache files starting with 'cake_'
*
* Usage: ./cake clear_cache all
*/
public function all() {
$this->__delete();
$this->ClearCacheClearCache->delete();
$this->out('Cleared!');
}

private function __delete($path = null) {
if (!$path) {
$path = TMP . 'cache' . DS;
}
$dirItems = scandir($path);
$ignore = array('.', '..');
foreach ($dirItems AS $dirItem) {
if (in_array($dirItem, $ignore)) {
continue;
}

if (is_dir($path . $dirItem)) {
$this->__delete($path . $dirItem . DS);
} elseif (substr($dirItem, 0, 5) == 'cake_') {
unlink($path . $dirItem);
}
}
}

}
?>

0 comments on commit 721d080

Please sign in to comment.