@@ -16,6 +16,22 @@ class helper_plugin_struct_db extends DokuWiki_Plugin
16
16
/** @var SQLiteDB */
17
17
protected $ sqlite ;
18
18
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
+
19
35
/**
20
36
* @param bool $throw throw an Exception when sqlite not available
21
37
* @return SQLiteDB|null
@@ -24,19 +40,13 @@ public function getDB($throw = true)
24
40
{
25
41
if ($ this ->sqlite === null ) {
26
42
try {
27
- $ this ->sqlite = new SQLiteDB ( ' struct ' , DOKU_PLUGIN . ' struct/db/ ' );
43
+ $ this ->init ( );
28
44
} catch (\Exception $ exception ) {
29
45
if (defined ('DOKU_UNITTEST ' )) throw new \RuntimeException ('Could not load SQLite ' , 0 , $ exception );
30
46
ErrorHandler::logException ($ exception );
31
47
if ($ throw ) throw new StructException ('no sqlite ' );
32
48
return null ;
33
49
}
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 );
40
50
}
41
51
return $ this ->sqlite ;
42
52
}
0 commit comments