Failed Conditions
Push — psr2-config ( c6639e )
by Andreas
06:39 queued 03:33
created

lib/plugins/popularity/action.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Popularity Feedback Plugin
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 */
7
8
class action_plugin_popularity extends DokuWiki_Action_Plugin
9
{
10
11
    /**
12
     * @var helper_plugin_popularity
13
     */
14
    protected $helper;
15
16
    public function __construct()
17
    {
18
        $this->helper = $this->loadHelper('popularity', false);
19
    }
20
21
    /** @inheritdoc */
22
    public function register(Doku_Event_Handler $controller)
23
    {
24
        $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, 'autosubmit', array());
25
    }
26
27
    /**
28
     * Event handler
29
     *
30
     * @param Doku_Event $event
31
     * @param $param
32
     */
33
    public function autosubmit(Doku_Event &$event, $param)
0 ignored issues
show
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        //Do we have to send the data now
36
        if (!$this->helper->isAutosubmitEnabled() || $this->isTooEarlyToSubmit()) {
37
            return;
38
        }
39
40
        //Actually send it
41
        $status = $this->helper->sendData($this->helper->gatherAsString());
42
43
        if ($status !== '') {
44
            //If an error occured, log it
45
            io_saveFile($this->helper->autosubmitErrorFile, $status);
46
        } else {
47
            //If the data has been sent successfully, previous log of errors are useless
48
            @unlink($this->helper->autosubmitErrorFile);
49
            //Update the last time we sent data
50
            touch($this->helper->autosubmitFile);
51
        }
52
53
        $event->stopPropagation();
54
        $event->preventDefault();
55
    }
56
57
    /**
58
     * Check if it's time to send autosubmit data
59
     * (we should have check if autosubmit is enabled first)
60
     */
61
    protected function isTooEarlyToSubmit()
62
    {
63
        $lastSubmit = $this->helper->lastSentTime();
64
        return $lastSubmit + 24*60*60*30 > time();
65
    }
66
}
67