xref: /plugin/struct/helper/db.php (revision 15929be2d8f1b3ae684ef1e73b344ee5c125512e)
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_db extends DokuWiki_Plugin {
13    /** @var helper_plugin_sqlite */
14    protected $sqlite;
15
16    public function __construct() {
17        /** @var helper_plugin_sqlite $sqlite */
18        $this->sqlite = plugin_load('helper', 'sqlite');
19        if(!$this->sqlite) {
20            if(defined('DOKU_UNITTEST')) throw new \Exception('Couldn\'t load sqlite.');
21
22            msg('The struct plugin requires the sqlite plugin. Please install it', -1);
23            return;
24        }
25
26        if($this->sqlite->getAdapter()->getName() != DOKU_EXT_PDO) {
27            if(defined('DOKU_UNITTEST')) throw new \Exception('Couldn\'t load PDO sqlite.');
28
29            msg('The struct plugin requires sqlite3 you\'re still using sqlite2',-1);
30            $this->sqlite = null;
31            return;
32        }
33        $this->sqlite->getAdapter()->setUseNativeAlter(true);
34
35        // initialize the database connection
36        if(!$this->sqlite->init('struct', DOKU_PLUGIN . 'struct/db/')) {
37            if(defined('DOKU_UNITTEST')) throw new \Exception('Couldn\'t init sqlite.');
38
39            return;
40        }
41    }
42
43    /**
44     * @return helper_plugin_sqlite|null
45     */
46    public function getDB() {
47        return $this->sqlite;
48    }
49
50}
51
52// vim:ts=4:sw=4:et:
53