1<?php
2/**
3 * DokuWiki Plugin watchcycle (Helper Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 */
7
8class helper_plugin_notification_cron extends DokuWiki_Plugin
9{
10    /** @var helper_plugin_sqlite */
11    protected $sqlite;
12
13    public function __construct()
14    {
15        /** @var \helper_plugin_notification_db $db_helper */
16        $db_helper = plugin_load('helper', 'notification_db');
17        $this->sqlite = $db_helper->getDB();
18    }
19
20    public function addUsersToCron()
21    {
22        /** @var DokuWiki_Auth_Plugin $auth */
23        global $auth;
24
25        $res = $this->sqlite->query('SELECT user from cron_check');
26        $ourUsers = $this->sqlite->res2arr($res);
27
28        $ourUsers = array_map(function ($item) {
29            return $item['user'];
30        }, $ourUsers);
31
32        $allUsers = array_keys($auth->retrieveUsers());
33
34        $newUsers = array_diff($allUsers, $ourUsers);
35
36        if (!is_array($newUsers) || empty($newUsers)) return;
37
38        foreach ($newUsers as $user) {
39            $this->sqlite->storeEntry('cron_check',
40                ['user' => $user, 'timestamp' => date('c', 0)]);
41        }
42    }
43}
44