xref: /plugin/struct/helper/db.php (revision 15929be2d8f1b3ae684ef1e73b344ee5c125512e)
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*15929be2SAndreas Gohr            if(defined('DOKU_UNITTEST')) throw new \Exception('Couldn\'t load sqlite.');
21*15929be2SAndreas Gohr
221c502704SAndreas Gohr            msg('The struct plugin requires the sqlite plugin. Please install it', -1);
23083afc55SAndreas Gohr            return;
24083afc55SAndreas Gohr        }
25083afc55SAndreas Gohr
261c502704SAndreas Gohr        if($this->sqlite->getAdapter()->getName() != DOKU_EXT_PDO) {
27*15929be2SAndreas Gohr            if(defined('DOKU_UNITTEST')) throw new \Exception('Couldn\'t load PDO sqlite.');
28*15929be2SAndreas Gohr
29*15929be2SAndreas Gohr            msg('The struct plugin requires sqlite3 you\'re still using sqlite2',-1);
301c502704SAndreas Gohr            $this->sqlite = null;
311c502704SAndreas Gohr            return;
321c502704SAndreas Gohr        }
331c502704SAndreas Gohr        $this->sqlite->getAdapter()->setUseNativeAlter(true);
341c502704SAndreas Gohr
35083afc55SAndreas Gohr        // initialize the database connection
36083afc55SAndreas Gohr        if(!$this->sqlite->init('struct', DOKU_PLUGIN . 'struct/db/')) {
37*15929be2SAndreas Gohr            if(defined('DOKU_UNITTEST')) throw new \Exception('Couldn\'t init sqlite.');
38*15929be2SAndreas Gohr
39083afc55SAndreas Gohr            return;
40083afc55SAndreas Gohr        }
41083afc55SAndreas Gohr    }
42549a0837SAndreas Gohr
43549a0837SAndreas Gohr    /**
44083afc55SAndreas Gohr     * @return helper_plugin_sqlite|null
45549a0837SAndreas Gohr     */
46083afc55SAndreas Gohr    public function getDB() {
47083afc55SAndreas Gohr        return $this->sqlite;
48549a0837SAndreas Gohr    }
49549a0837SAndreas Gohr
50549a0837SAndreas Gohr}
51549a0837SAndreas Gohr
52549a0837SAndreas Gohr// vim:ts=4:sw=4:et:
53