forked from cosmocode/dokuwiki-plugin-cleanup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
62 lines (50 loc) · 1.75 KB
/
action.php
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
53
54
55
56
57
58
59
60
61
62
<?php
/**
* DokuWiki Plugin cleanup (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class action_plugin_cleanup extends DokuWiki_Action_Plugin {
/**
* Registers a callback function for a given event
*
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler &$controller) {
$controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'handle_indexer_tasks_run');
}
/**
* [Custom event handler which performs action]
*
* @param Doku_Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
* handler was registered]
* @return void
*/
public function handle_indexer_tasks_run(Doku_Event &$event, $param) {
if(!$this->getConf('runautomatically')) return;
global $conf;
// only run once everyday
$lastrun = $conf['cachedir'].'/cleanup.run';
$ranat = @filemtime($lastrun);
if($ranat && (time() - $ranat) < 60*60*24 ){
echo "cleanup: skipped\n";
return;
}
io_saveFile($lastrun,'');
// our turn!
$event->preventDefault();
$event->stopPropagation();
// and action
echo "cleanup: started\n";
/** @var helper_plugin_cleanup $helper */
$helper = $this->loadHelper('cleanup', false);
$helper->run(true);
echo 'cleanup: finished. found '.count($helper->list)." files\n";
}
}
// vim:ts=4:sw=4:et: