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 // prune irrelivant stuff..
44 $this->prune((int)$opts['months']);
49 // 40 seconds ? to delete 100K records..
50 // DB_DataObject::debugLevel(1);
51 $f = DB_DataObject::Factory('reader_article');
53 DELETE FROM Events where
54 event_when < NOW() - INTERVAL {$inM} MONTH
58 // notificication events occur alot - so we should trash them more frequently..
59 $f = DB_DataObject::Factory('reader_article');
61 DELETE FROM Events where
62 event_when < NOW() - INTERVAL 1 MONTH
68 // rather than deleting them all, it's probably best to just delete notify events that occured to often.
69 // eg. when we tried to deliver multiple times without success...
73 // pruning is for our press project - so we do not clean up dependant tables at present..
75 if (function_exists('posix_getpwuid')) {
76 $uinfo = posix_getpwuid( posix_getuid () );
78 $user = $uinfo['name'];
80 $user = getenv('USERNAME'); // windows.
83 $ff = HTML_Flexyframework::get()->Pman;
87 $rootDir = $ff['storedir'].'/_events_/'.$user;
89 $dirs = array_filter(glob($rootDir."/*"), 'is_dir');
91 $mdirs = array_filter(glob($d."/*"), 'is_dir');
92 foreach($mdirs as $md){
93 $dirDate = str_replace($rootDir."/", '', $md);
94 if(strtotime($dirDate."/01") < strtotime("now - {$inM} months")){
95 //echo "remove $md\n";
97 // echo $md . " is removed. \n";
106 function delTree($dir)
108 $files = array_diff(scandir($dir), array('.','..'));
109 echo "$dir : Removing " . count($files) . " files\n";
111 foreach ($files as $file){
112 if (!file_exists("$dir/$file")) {
115 if (is_dir("$dir/$file")) {
116 $this->delTree("$dir/$file");
119 unlink("$dir/$file");