xref: /plugin/struct/helper/imexport.php (revision 1bd268d2c0b871c626652d7341dd056eb34ca29f)
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        $sql[] = "DELETE FROM schema_assignments WHERE tbl = '$schema'";
40        foreach ($patterns as $pattern) {
41            $pattern = $this->sqlite->escape_string($pattern);
42            $sql[] = "INSERT INTO schema_assignments_patterns (pattern, tbl) VALUES ('$pattern','$schema')";
43        }
44
45        var_dump($sql);
46        var_dump($this->sqlite->getAdapter()->getDbFile());
47        $this->sqlite->doTransaction($sql);
48    }
49
50    public function getSchemaAssignmentPatterns($schema) {
51        /** @var \helper_plugin_struct_db $helper */
52        $helper = plugin_load('helper', 'struct_db', true);
53        $this->sqlite = $helper->getDB();
54
55        $sql = 'SELECT pattern FROM schema_assignments_patterns WHERE tbl = ?';
56        $res = $this->sqlite->query($sql, $schema);
57        $patterns = $this->sqlite->res2arr($res);
58        $this->sqlite->res_close($res);
59        return array_map(function($elem){return $elem['pattern'];},$patterns);
60    }
61
62}
63