1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
<?php
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
/**
* DokuWiki Plugin logviewer (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <andi@splitbrain.org>
*/
class action_plugin_logviewer extends ActionPlugin
{
/** @inheritDoc */
public function register(EventHandler $controller)
{
$controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'pruneLogs');
}
/**
* Event handler for INDEXER_TASKS_RUN
*
* @see https://www.dokuwiki.org/devel:events:INDEXER_TASKS_RUN
* @param Event $event Event object
* @param mixed $param optional parameter passed when event was registered
* @return void
*/
public function pruneLogs(Event $event, $param)
{
global $conf;
$prune = $conf['logdir'] . '/pruned';
if (@filemtime($prune) > time() - 24 * 60 * 60) {
return; // already pruned today
}
$logdirs = glob($conf['logdir'] . '/*', GLOB_ONLYDIR | GLOB_NOSORT);
foreach ($logdirs as $dir) {
$dates = glob($dir . '/*.log'); // glob returns sorted results
if (count($dates) > $conf['logretain']) {
$dates = array_slice($dates, 0, -1 * $conf['logretain']);
foreach ($dates as $date) {
io_rmdir($date, true);
}
}
}
io_saveFile($prune, '');
}
}
|