1<?php 2 3/** 4 * DokuWiki Plugin notification (Helper Component) 5 * 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author Szymon Olewniczak <dokuwiki@cosmocode.de> 8 */ 9 10class helper_plugin_notification_db extends DokuWiki_Plugin 11{ 12 /** @var helper_plugin_sqlite */ 13 protected $sqlite; 14 15 /** 16 * helper_plugin_struct_db constructor. 17 */ 18 public function __construct() 19 { 20 $this->init(); 21 } 22 23 /** 24 * Initialize the database 25 * 26 * @throws Exception 27 */ 28 protected function init() 29 { 30 /** @var helper_plugin_sqlite $sqlite */ 31 $this->sqlite = plugin_load('helper', 'sqlite'); 32 if (!$this->sqlite) { 33 if (defined('DOKU_UNITTEST')) { 34 throw new \Exception('Couldn\'t load sqlite.'); 35 } 36 return; 37 } 38 39 if ($this->sqlite->getAdapter()->getName() != DOKU_EXT_PDO) { 40 if (defined('DOKU_UNITTEST')) { 41 throw new \Exception('Couldn\'t load PDO sqlite.'); 42 } 43 $this->sqlite = null; 44 return; 45 } 46 $this->sqlite->getAdapter()->setUseNativeAlter(true); 47 48 // initialize the database connection 49 if (!$this->sqlite->init('notification', DOKU_PLUGIN . 'notification/db/')) { 50 if (defined('DOKU_UNITTEST')) { 51 throw new \Exception('Couldn\'t init sqlite.'); 52 } 53 $this->sqlite = null; 54 return; 55 } 56 } 57 58 /** 59 * @return helper_plugin_sqlite|null 60 */ 61 public function getDB() 62 { 63 global $conf; 64 $len = strlen($conf['metadir']); 65 if ($this->sqlite && $conf['metadir'] != substr($this->sqlite->getAdapter()->getDbFile(), 0, $len)) { 66 $this->init(); 67 } 68 if (!$this->sqlite) { 69 msg($this->getLang('error sqlite missing'), -1); 70 return false; 71 } 72 return $this->sqlite; 73 } 74} 75