1<?php
2
3/**
4 * Cleanup Action Plugin:   Clean up the history once per day
5 *
6 * @author     Dominik Eckelmann <eckelmann@cosmocode.de>
7 */
8class action_plugin_clearhistory extends DokuWiki_Action_Plugin
9{
10
11    /**
12     * if true a cleanup process is already running
13     * or done in the last 24h
14     */
15    protected $run = false;
16
17    /**
18     * Constructor - get some config details and check if a check runs in the last 24h
19     */
20    public function __construct()
21    {
22        global $conf;
23
24        // check if the autocleaner is enabled
25        if ($this->getConf('autoclearenabled') == 0) $this->run = true;
26
27        // check if a runfile exists - if not -> there is no last run
28        if (!is_file($conf['cachedir'] . '/lastclean')) return;
29
30        // check last run
31        $get = fileatime($conf['cachedir'] . '/lastclean');
32        $get = intval($get);
33        if ($get + (60 * 60 * 24) > time()) $this->run = true;
34    }
35
36    /** @inheritdoc */
37    public function register(Doku_Event_Handler $controller)
38    {
39        $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'cleanup', array());
40    }
41
42    /**
43     * start the scan
44     *
45     * scans the recent changes
46     */
47    public function cleanup($event, $param)
48    {
49        global $conf;
50
51        if ($this->run) return;
52        $this->run = true;
53        echo 'clearhistory: started' . NL;
54
55        $onlySmall = $this->getConf('autoclearonlysmall');
56        $onlyNoComment = $this->getConf('autoclearonlynocomment');
57
58        //$hdl = plugin_load('admin','clearhistory');
59        $hdl = new admin_plugin_clearhistory();
60
61        $hdl->_scanRecents(30, $onlySmall, $onlyNoComment);
62
63        echo 'clearhistory: ' . $hdl->delcounter . ' deleted' . NL;
64        touch($conf['cachedir'] . '/lastclean');
65    }
66
67}
68