Skip to content

Commit 7d0142f

Browse files
committed
reintroduce init method
Some plugins (structpublish) overwrite it in their own class.
1 parent 47576df commit 7d0142f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

helper/db.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ class helper_plugin_struct_db extends DokuWiki_Plugin
1616
/** @var SQLiteDB */
1717
protected $sqlite;
1818

19+
/**
20+
* Initialize the database
21+
*
22+
* @throws Exception
23+
*/
24+
protected function init()
25+
{
26+
$this->sqlite = new SQLiteDB('struct', DOKU_PLUGIN . 'struct/db/');
27+
28+
// register our JSON function with variable parameters
29+
$this->sqlite->getPdo()->sqliteCreateFunction('STRUCT_JSON', [$this, 'STRUCT_JSON'], -1);
30+
31+
// this function is meant to be overwritten by plugins
32+
$this->sqlite->getPdo()->sqliteCreateFunction('IS_PUBLISHER', [$this, 'IS_PUBLISHER'], -1);
33+
}
34+
1935
/**
2036
* @param bool $throw throw an Exception when sqlite not available
2137
* @return SQLiteDB|null
@@ -24,19 +40,13 @@ public function getDB($throw = true)
2440
{
2541
if ($this->sqlite === null) {
2642
try {
27-
$this->sqlite = new SQLiteDB('struct', DOKU_PLUGIN . 'struct/db/');
43+
$this->init();
2844
} catch (\Exception $exception) {
2945
if (defined('DOKU_UNITTEST')) throw new \RuntimeException('Could not load SQLite', 0, $exception);
3046
ErrorHandler::logException($exception);
3147
if ($throw) throw new StructException('no sqlite');
3248
return null;
3349
}
34-
35-
// register our JSON function with variable parameters
36-
$this->sqlite->getPdo()->sqliteCreateFunction('STRUCT_JSON', [$this, 'STRUCT_JSON'], -1);
37-
38-
// this function is meant to be overwritten by plugins
39-
$this->sqlite->getPdo()->sqliteCreateFunction('IS_PUBLISHER', [$this, 'IS_PUBLISHER'], -1);
4050
}
4151
return $this->sqlite;
4252
}

0 commit comments

Comments
 (0)