예제 #1
0
 /**
  * Initialize the database
  *
  * @throws Exception
  */
 protected function init()
 {
     /** @var helper_plugin_sqlite $sqlite */
     $this->sqlite = plugin_load('helper', 'sqlite');
     if (!$this->sqlite) {
         if (defined('DOKU_UNITTEST')) {
             throw new \Exception('Couldn\'t load sqlite.');
         }
         msg('The struct plugin requires the sqlite plugin. Please install it', -1);
         return;
     }
     if ($this->sqlite->getAdapter()->getName() != DOKU_EXT_PDO) {
         if (defined('DOKU_UNITTEST')) {
             throw new \Exception('Couldn\'t load PDO sqlite.');
         }
         msg('The struct plugin requires sqlite3 you\'re still using sqlite2', -1);
         $this->sqlite = null;
         return;
     }
     $this->sqlite->getAdapter()->setUseNativeAlter(true);
     // initialize the database connection
     if (!$this->sqlite->init('struct', DOKU_PLUGIN . 'struct/db/')) {
         if (defined('DOKU_UNITTEST')) {
             throw new \Exception('Couldn\'t init sqlite.');
         }
         return;
     }
     // register our JSON function with variable parameters
     // todo this might be useful to be moved into the sqlite plugin
     $this->sqlite->create_function('STRUCT_JSON', array($this, 'STRUCT_JSON'), -1);
 }
예제 #2
0
 /**
  * initializes the DB connection
  *
  * @return helper_plugin_sqlite|null
  */
 public function getDBHelper()
 {
     if (!is_null($this->sqlite)) {
         return $this->sqlite;
     }
     $this->sqlite = plugin_load('helper', 'sqlite');
     if (!$this->sqlite) {
         msg('The rating plugin requires the sqlite plugin', -1);
         $this->sqlite = null;
         return null;
     }
     $ok = $this->sqlite->init('rating', __DIR__ . '/db');
     if (!$ok) {
         msg('rating plugin sqlite initialization failed', -1);
         $this->sqlite = null;
         return null;
     }
     return $this->sqlite;
 }