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..
41 $f = DB_DataObject::Factory('reader_article');
43 DELETE FROM Events where
44 event_when < NOW() - INTERVAL 6 MONTH
46 action IN ('RELOAD', 'LOGIN')
51 $this->prune((int)$opts['months']);
56 // 40 seconds ? to delete 100K records..
57 DB_DataObject::debugLevel(1);
58 $f = DB_DataObject::Factory('reader_article');
60 DELETE FROM Events where
61 event_when < NOW() - INTERVAL {$inM} MONTH
64 // pruning is for our press project - so we do not clean up dependant tables at present..
66 if (function_exists('posix_getpwuid')) {
67 $uinfo = posix_getpwuid( posix_getuid () );
69 $user = $uinfo['name'];
71 $user = getenv('USERNAME'); // windows.
74 $ff = HTML_Flexyframework::get()->Pman;
78 $rootDir = $ff['storedir'].'/_events_/'.$user;
80 $dirs = array_filter(glob($rootDir."/*"), 'is_dir');
82 $mdirs = array_filter(glob($d."/*"), 'is_dir');
83 foreach($mdirs as $md){
84 $dirDate = str_replace($rootDir."/", '', $md);
85 if(strtotime($dirDate."/01") < strtotime("now - {$inM} months")){
86 //echo "remove $md\n";
88 // echo $md . " is removed. \n";
97 function delTree($dir)
99 $files = array_diff(scandir($dir), array('.','..'));
100 echo "$dir : Removing " . count($files) . " files\n";
102 foreach ($files as $file){
103 if (!file_exists("$dir/$file")) {
106 if (is_dir("$dir/$file")) {
107 $this->delTree("$dir/$file");
110 unlink("$dir/$file");