reintroduce init method

Some plugins (structpublish) overwrite it in their own class.
This commit is contained in:
Andreas Gohr
2023-07-19 11:00:05 +02:00
parent 47576dff51
commit 7d0142f50f

View File

@ -16,6 +16,22 @@ class helper_plugin_struct_db extends DokuWiki_Plugin
/** @var SQLiteDB */ /** @var SQLiteDB */
protected $sqlite; protected $sqlite;
/**
* Initialize the database
*
* @throws Exception
*/
protected function init()
{
$this->sqlite = new SQLiteDB('struct', DOKU_PLUGIN . 'struct/db/');
// register our JSON function with variable parameters
$this->sqlite->getPdo()->sqliteCreateFunction('STRUCT_JSON', [$this, 'STRUCT_JSON'], -1);
// this function is meant to be overwritten by plugins
$this->sqlite->getPdo()->sqliteCreateFunction('IS_PUBLISHER', [$this, 'IS_PUBLISHER'], -1);
}
/** /**
* @param bool $throw throw an Exception when sqlite not available * @param bool $throw throw an Exception when sqlite not available
* @return SQLiteDB|null * @return SQLiteDB|null
@ -24,19 +40,13 @@ class helper_plugin_struct_db extends DokuWiki_Plugin
{ {
if ($this->sqlite === null) { if ($this->sqlite === null) {
try { try {
$this->sqlite = new SQLiteDB('struct', DOKU_PLUGIN . 'struct/db/'); $this->init();
} catch (\Exception $exception) { } catch (\Exception $exception) {
if (defined('DOKU_UNITTEST')) throw new \RuntimeException('Could not load SQLite', 0, $exception); if (defined('DOKU_UNITTEST')) throw new \RuntimeException('Could not load SQLite', 0, $exception);
ErrorHandler::logException($exception); ErrorHandler::logException($exception);
if ($throw) throw new StructException('no sqlite'); if ($throw) throw new StructException('no sqlite');
return null; return null;
} }
// register our JSON function with variable parameters
$this->sqlite->getPdo()->sqliteCreateFunction('STRUCT_JSON', [$this, 'STRUCT_JSON'], -1);
// this function is meant to be overwritten by plugins
$this->sqlite->getPdo()->sqliteCreateFunction('IS_PUBLISHER', [$this, 'IS_PUBLISHER'], -1);
} }
return $this->sqlite; return $this->sqlite;
} }