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_telleveryone_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() !== 'telleveryone') {
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        global $conf;
47
48        /** @var helper_plugin_sqlite $sqlite */
49        $sqlite = $data['sqlite'];
50
51        $token = bin2hex(openssl_random_pseudo_bytes(16));
52        $sqlite->storeEntry('config', [
53            'key' => 'token',
54            'value' => $token
55        ]);
56    }
57}
58