1<?php
2
3use dokuwiki\Extension\ActionPlugin;
4use dokuwiki\Extension\EventHandler;
5use dokuwiki\Extension\Event;
6
7class action_plugin_approve_migration extends ActionPlugin
8{
9    /**
10     * @inheritDoc
11     */
12    public function register(EventHandler $controller)
13    {
14        $controller->register_hook('PLUGIN_SQLITE_DATABASE_UPGRADE', 'AFTER', $this, 'handle_migrations');
15    }
16
17    /**
18     * Call our custom migrations when defined.
19     *
20     * @param Event $event
21     * @param mixed $param
22     */
23    public function handle_migrations(Event $event, $param)
24    {
25        if ($event->data['sqlite']->getAdapter()->getDbname() !== 'approve') {
26            return;
27        }
28        $to = $event->data['to'];
29        if (is_callable([$this, "migration$to"])) {
30            $event->preventDefault();
31            $event->result = call_user_func([$this, "migration$to"], $event->data['adapter']);
32        }
33    }
34}
35