You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

53 lines
1.5 KiB

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