1<?php
2if(!defined('DOKU_INC')) die();
3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4if(!defined('DOKU_DATA')) define('DOKU_DATA',DOKU_INC.'data/');
5
6require_once(DOKU_PLUGIN.'action.php');
7require_once(DOKU_PLUGIN.'clearhistory/admin.php');
8
9/**
10 * Cleanup Action Plugin:   Clean up the history once per day
11 *
12 * @author     Dominik Eckelmann <eckelmann@cosmocode.de>
13 */
14class action_plugin_clearhistory extends DokuWiki_Action_Plugin {
15
16	/**
17	 * if true a cleanup process is already running
18	 * or done in the last 24h
19	 */
20    var $run = false;
21
22	/**
23	 * Constructor - get some config details and check if a check runs in the last 24h
24	 */
25    function action_plugin_clearhistory() {
26        global $conf;
27
28		// check if the autocleaner is enabled
29        if ($this->getConf('autoclearenabled') == 0) $this->run = true;
30
31		// check if a runfile exists - if not -> there is no last run
32        if (!is_file($conf['cachedir'].'/lastclean')) return;
33
34		// check last run
35        $get = fileatime($conf['cachedir'].'/lastclean');
36        $get = intval($get);
37        if ($get+(60*60*24) > time()) $this->run = true;
38    }
39
40    /**
41	 * return some in
42	 * @return array
43     */
44    function getInfo(){
45        return confToHash(dirname(__FILE__).'/plugin.info.txt');
46    }
47
48    /**
49     * Register its handlers with the dokuwiki's event controller
50	 *
51	 * we need hook the indexer to trigger the cleanup
52     */
53    function register(Doku_Event_Handler $controller) {
54        $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE',  $this, 'cleanup', array());
55    }
56
57	/**
58	 * start the scan
59	 *
60	 * scans the recent changes
61	 */
62    function cleanup(&$event, $param) {
63        global $conf;
64
65		if ($this->run) return;
66		$this->run = true;
67		echo 'clearhistory: started'.NL;
68
69		$onlySmall     = $this->getConf('autoclearonlysmall');
70        $onlyNoComment = $this->getConf('autoclearonlynocomment');
71
72        //$hdl = plugin_load('admin','clearhistory');
73        $hdl = new admin_plugin_clearhistory();
74
75		$hdl->_scanRecents(30, $onlySmall , $onlyNoComment);
76
77		echo 'clearhistory: ' . $hdl->delcounter . ' deleted'.NL;
78        touch($conf['cachedir'].'/lastclean');
79    }
80
81}
82
83
84
85?>
86