1<?php
2
3/**
4 * DokuWiki Plugin sql2wiki (Action Component)
5 *
6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
7 * @author  Szymon Olewniczak <it@rid.pl>
8 */
9
10class action_plugin_sql2wiki_indexer extends \dokuwiki\Extension\ActionPlugin
11{
12
13    /** @inheritDoc */
14    public function register(Doku_Event_Handler $controller)
15    {
16        $controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, 'handle_indexer_version_get');
17        $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handle_indexer_page_add');
18
19    }
20
21    public function handle_indexer_version_get(Doku_Event $event, $param)
22    {
23        $event->data['plugin_sql2wiki'] = '0.1';
24    }
25
26    public function handle_indexer_page_add(Doku_Event $event, $param)
27    {
28        $sql2wiki_data = p_get_metadata($event->data['page'], 'plugin_sql2wiki');
29        if (!$sql2wiki_data) return;
30        $event->data['metadata']['sql2wiki_db'] = array_column($sql2wiki_data, 'db');
31        $event->data['metadata']['sql2wiki_query_name'] = array_map(function($data) {
32            return $data['db'] . '.' . $data['query_name'];
33        }, $sql2wiki_data);
34    }
35
36}
37
38