xref: /plugin/statdisplay/action.php (revision 7923e724b32d35d5b157dcd8aa63059a7a508b8e)
1<?php
2
3use dokuwiki\Extension\ActionPlugin;
4use dokuwiki\Extension\EventHandler;
5use dokuwiki\Extension\Event;
6
7/**
8 * statdisplay plugin action component
9 *
10 * @author Andreas Gohr <gohr@cosmocode.de>
11 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
12 */
13class action_plugin_statdisplay extends ActionPlugin
14{
15    /** @inheritDoc */
16    public function register(EventHandler $controller)
17    {
18        $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'handleRun');
19    }
20
21    /**
22     * Analyze the next chunk of data
23     *
24     * @param Event $event
25     * @param $param
26     */
27    public function handleRun(&$event, $param)
28    {
29        echo "logfile analysis started.\n";
30
31        /** @var $log helper_plugin_statdisplay_log */
32        $log = plugin_load('helper', 'statdisplay_log');
33        if ($log === null) {
34            echo "logfile analysis aborted: helper could not be loaded.\n";
35            return;
36        }
37        $lines = $log->parseLogData($this->getConf('lines'));
38
39        // did we do any work?
40        if ($lines) {
41            $event->preventDefault();
42            $event->stopPropagation();
43        }
44        echo "logfile analysis finished analyzing $lines lines.\n";
45    }
46}
47