xref: /plugin/struct/helper/imexport.php (revision 7c5fd8d6756c15818709cf52cb599c5f987bbb7b)
1<?php
2/**
3 * DokuWiki Plugin struct (Helper Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class helper_plugin_struct_imexport extends DokuWiki_Plugin {
13
14    private $sqlite;
15
16    public function getAllSchemasList() {
17        /** @var \helper_plugin_struct_db $helper */
18        $helper = plugin_load('helper', 'struct_db');
19        $this->sqlite = $helper->getDB();
20
21        $sql = 'SELECT DISTINCT(tbl) FROM schemas';
22        $res = $this->sqlite->query($sql);
23        $schemas = $this->sqlite->res2arr($res);
24        $this->sqlite->res_close($res);
25        return $schemas;
26    }
27
28    /**
29     * @param string   $schema
30     * @param string[] $assignments
31     */
32    public function replaceSchemaAssignmentPatterns($schema, $patterns) {
33        /** @var \helper_plugin_struct_db $helper */
34        $helper = plugin_load('helper', 'struct_db', true);
35        $this->sqlite = $helper->getDB();
36        $schema = $this->sqlite->escape_string($schema);
37        $sql = array();
38        $sql[] = 'DELETE FROM schema_assignments_patterns WHERE tbl = \'' . $schema . '\'';
39        foreach ($patterns as $pattern) {
40            $sql[] = 'INSERT INTO schema_assignments_patterns (pattern, tbl) VALUES (\''.$this->sqlite->escape_string($pattern) .'\',\''.$schema.'\')';
41        }
42
43        var_dump($sql);
44        var_dump($this->sqlite->getAdapter()->getDbFile());
45        $this->sqlite->doTransaction($sql);
46    }
47
48    public function getSchemaAssignmentPatterns($schema) {
49        /** @var \helper_plugin_struct_db $helper */
50        $helper = plugin_load('helper', 'struct_db', true);
51        $this->sqlite = $helper->getDB();
52
53        $sql = 'SELECT pattern FROM schema_assignments_patterns WHERE tbl = ?';
54        $res = $this->sqlite->query($sql, $schema);
55        $patterns = $this->sqlite->res2arr($res);
56        $this->sqlite->res_close($res);
57        return array_map(function($elem){return $elem['pattern'];},$patterns);
58    }
59
60}
61