1<?php
2
3use dokuwiki\Extension\ActionPlugin;
4use dokuwiki\Extension\EventHandler;
5use dokuwiki\Extension\Event;
6
7/**
8 * Class action_plugin_notification_migration
9 *
10 * Handle migrations that need more than just SQL
11 */
12class action_plugin_notification_migration extends ActionPlugin
13{
14    /**
15     * @inheritDoc
16     */
17    public function register(EventHandler $controller)
18    {
19        $controller->register_hook('PLUGIN_SQLITE_DATABASE_UPGRADE', 'AFTER', $this, 'handleMigrations');
20    }
21
22    /**
23     * Call our custom migrations when defined
24     *
25     * @param Event $event
26     * @param $param
27     */
28    public function handleMigrations(Event $event, $param)
29    {
30        if ($event->data['sqlite']->getAdapter()->getDbname() !== 'notification') {
31            return;
32        }
33        $to = $event->data['to'];
34
35        if (is_callable([$this, "migration$to"])) {
36            $event->result = call_user_func([$this, "migration$to"], $event->data);
37        }
38    }
39
40    protected function migration1($data)
41    {
42        /** @var DokuWiki_Auth_Plugin $auth */
43        global $auth;
44        /** @var \helper_plugin_notification_db $db_helper */
45        $db_helper = plugin_load('helper', 'notification_db');
46        $sqlite = $db_helper->getDB();
47
48        foreach (array_keys($auth->retrieveUsers()) as $user) {
49            $sqlite->storeEntry(
50                'cron_check',
51                ['user' => $user, 'timestamp' => date('c', 0)]
52            );
53        }
54    }
55}
56