From 17757a2bc1d8df1d445a1d5cc80bf0e94e1e11cd Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Thu, 6 Nov 2014 09:23:45 -0500 Subject: [PATCH] Minor - code style --- main/cron/cleanup.php | 47 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/main/cron/cleanup.php b/main/cron/cleanup.php index b96de31c18..ffafcbc776 100755 --- a/main/cron/cleanup.php +++ b/main/cron/cleanup.php @@ -1,40 +1,47 @@ */ /** * Initialization */ -if (php_sapi_name() != 'cli') { exit; } //do not run from browser +if (php_sapi_name() != 'cli') { + exit; //do not run from browser +} $dir = dirname(__FILE__); $a_dir = realpath($dir.'/../../archive/'); $list = scandir($a_dir); +// calculate 7 days $t = time()-(86400*7); -foreach($list as $item) { - if (substr($item,0,1) == '.') { continue; } - $stat = @stat($a_dir.'/'.$item); - if ($stat === false) { error_log('Cron task cannot stat '.$a_dir.'/'.$item); continue; } - if ($stat['mtime'] > $t) { //if the file is older than one week, delete - recursive_delete($a_dir.'/'.$item); - } +foreach ($list as $item) { + if (substr($item,0,1) == '.') { + continue; + } + $stat = @stat($a_dir.'/'.$item); + if ($stat === false) { + error_log('Cron task cannot stat '.$a_dir.'/'.$item); + continue; + } + if ($stat['mtime'] > $t) { //if the file is older than one week, delete + recursive_delete($a_dir.'/'.$item); + } } /** * Delete a file or recursively delete a directory - * * @param string $str Path to file or directory */ function recursive_delete($str){ - if(is_file($str)){ - return @unlink($str); - } - elseif(is_dir($str)){ - $scan = glob(rtrim($str,'/').'/*'); - foreach($scan as $index=>$path){ - recursive_delete($path); - } - return @rmdir($str); - } + if (is_file($str)) { + return @unlink($str); + } elseif (is_dir($str)) { + $scan = glob(rtrim($str,'/').'/*'); + foreach ($scan as $index=>$path) { + recursive_delete($path); + } + return @rmdir($str); + } }