10 require_once 'Pman.php';
11 class Pman_Core_Prune extends Pman
14 static $cli_desc = "Core Prune -- remove old event data (6 months is normally a good idea).";
15 static $cli_opts = array(
17 'desc' => 'How many months',
28 $ff = HTML_FlexyFramework::get();
29 if (!empty($ff->cli)) {
33 // return true;// for test only
37 function get($m="", $opts)
40 $this->prune((int)$opts['months']);
45 // 40 seconds ? to delete 100K records..
46 //DB_DataObject::debugLevel(1);
47 $f = DB_DataObject::Factory('reader_article');
49 DELETE FROM Events where
50 event_when < NOW() - INTERVAL {$inM} MONTH
53 // pruning is for our press project - so we do not clean up dependant tables at present..
55 if (function_exists('posix_getpwuid')) {
56 $uinfo = posix_getpwuid( posix_getuid () );
58 $user = $uinfo['name'];
60 $user = getenv('USERNAME'); // windows.
63 $ff = HTML_Flexyframework::get()->Pman;
67 $rootDir = $ff['storedir'].'/_events_/'.$user;
69 $dirs = array_filter(glob($rootDir."/*"), 'is_dir');
71 $mdirs = array_filter(glob($d."/*"), 'is_dir');
72 foreach($mdirs as $md){
73 $dirDate = str_replace($rootDir."/", '', $md);
74 if(strtotime($dirDate."/01") < strtotime("now - {$inM} months")){
75 //echo "remove $md\n";
77 // echo $md . " is removed. \n";
86 function delTree($dir)
88 $files = array_diff(scandir($dir), array('.','..'));
89 echo "$dir : Removing " . count($files) . " files\n";
91 foreach ($files as $file){
92 if (!file_exists("$dir/$file")) {
95 if (is_dir("$dir/$file")) {
96 $this->delTree("$dir/$file");