*/
use dokuwiki\Extension\Plugin;
class helper_plugin_botmon extends Plugin {
/**
* Constructor
*/
public function __construct() {
echo "
Processing logfiles …\n";
}
/**
* Cleanup function
*/
public function cleanup() {
// exclude the following two dates:
$today = gmdate('Y-m-d');
$yesterday = gmdate('Y-m-d', time() - 86400);
// scan the log directory and delete all files except for today and yesterday:
$dir = scandir(DOKU_PLUGIN . 'botmon/logs');
foreach($dir as $file) {
$fName = pathinfo($file, PATHINFO_BASENAME);
$bName = strtok($fName, '.');
if ($bName == '' || $bName == 'logfiles' || $bName == 'empty' || $fName == '.htaccess') {
// echo "File “{$fName}” ignored.\n";
} else if ($bName == $today || $bName == $yesterday) {
echo "File “{$fName}” skipped.\n";
} else {
if (unlink(DOKU_PLUGIN . 'botmon/logs/' . $file)) {
echo "File “{$fName}” deleted.\n";
} else {
echo "File “{$fName}” could not be deleted!\n";
}
}
}
echo "Done.\n";
}
}