xref: /plugin/struct/helper/db.php (revision 1c502704592431c9b605eb91ad8b3f133892d618)
1549a0837SAndreas Gohr<?php
2549a0837SAndreas Gohr/**
3549a0837SAndreas Gohr * DokuWiki Plugin struct (Helper Component)
4549a0837SAndreas Gohr *
5549a0837SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6549a0837SAndreas Gohr * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
7549a0837SAndreas Gohr */
8549a0837SAndreas Gohr
9549a0837SAndreas Gohr// must be run within Dokuwiki
10549a0837SAndreas Gohrif(!defined('DOKU_INC')) die();
11549a0837SAndreas Gohr
12549a0837SAndreas Gohrclass helper_plugin_struct_db extends DokuWiki_Plugin {
13083afc55SAndreas Gohr    /** @var helper_plugin_sqlite */
14083afc55SAndreas Gohr    protected $sqlite;
15083afc55SAndreas Gohr
16083afc55SAndreas Gohr    public function __construct() {
17083afc55SAndreas Gohr        /** @var helper_plugin_sqlite $sqlite */
18083afc55SAndreas Gohr        $this->sqlite = plugin_load('helper', 'sqlite');
19083afc55SAndreas Gohr        if(!$this->sqlite) {
20*1c502704SAndreas Gohr            msg('The struct plugin requires the sqlite plugin. Please install it', -1);
21083afc55SAndreas Gohr            return;
22083afc55SAndreas Gohr        }
23083afc55SAndreas Gohr
24*1c502704SAndreas Gohr        if($this->sqlite->getAdapter()->getName() != DOKU_EXT_PDO) {
25*1c502704SAndreas Gohr            msg('The struct plugin requires sqlite3 you\'re still using sqlite2');
26*1c502704SAndreas Gohr            $this->sqlite = null;
27*1c502704SAndreas Gohr            return;
28*1c502704SAndreas Gohr        }
29*1c502704SAndreas Gohr        $this->sqlite->getAdapter()->setUseNativeAlter(true);
30*1c502704SAndreas Gohr
31083afc55SAndreas Gohr        // initialize the database connection
32083afc55SAndreas Gohr        if(!$this->sqlite->init('struct', DOKU_PLUGIN . 'struct/db/')) {
33083afc55SAndreas Gohr            return;
34083afc55SAndreas Gohr        }
35083afc55SAndreas Gohr    }
36549a0837SAndreas Gohr
37549a0837SAndreas Gohr    /**
38083afc55SAndreas Gohr     * @return helper_plugin_sqlite|null
39549a0837SAndreas Gohr     */
40083afc55SAndreas Gohr    public function getDB() {
41083afc55SAndreas Gohr        return $this->sqlite;
42549a0837SAndreas Gohr    }
43549a0837SAndreas Gohr
44549a0837SAndreas Gohr}
45549a0837SAndreas Gohr
46549a0837SAndreas Gohr// vim:ts=4:sw=4:et:
47