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