From: Nicolas Boisselier Date: Thu, 4 Jan 2018 23:18:31 +0000 (+0000) Subject: lib/php/db/config.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=4f4920234729fdadc318f780f3659587a69d4360;p=nb.git lib/php/db/config.php --- diff --git a/etc/dbq/000-local.php b/etc/dbq/000-local.php deleted file mode 100644 index 412871ca..00000000 --- a/etc/dbq/000-local.php +++ /dev/null @@ -1,14 +0,0 @@ - [ - 'type' => 'sqlite', - 'name' => 'Nb', - 'default_table' => 'mime', - 'host' => nb::ROOT_DIR.'/share/db/nb.db', - ], - -]; -?> diff --git a/etc/dbq/nb.php b/etc/dbq/nb.php new file mode 100644 index 00000000..f6c4f6fc --- /dev/null +++ b/etc/dbq/nb.php @@ -0,0 +1,11 @@ + 'sqlite', + 'name' => 'Nb', + 'default_table' => 'mime', + 'host' => nb::ROOT_DIR.'/share/db/nb.db', +]; +?> diff --git a/etc/dbq/sqlite-all.php.disable b/etc/dbq/sqlite-all.php.disable new file mode 100644 index 00000000..3953de56 --- /dev/null +++ b/etc/dbq/sqlite-all.php.disable @@ -0,0 +1,50 @@ + ':memory:', + 'type' => 'sqlite', + 'name' => 'all', + 'pdo' => '', + 'default_table' => '', +# NB 20.01.17 '_import' => ['nb'], + 'order' => '10', + 'options' => [ + PDO::ATTR_PERSISTENT => true, + ], + 'tables' => [], + 'types' => [ + 'sql_pre' => [], + ], + 'sql_pre' => [ + #'PRAGMA synchronous = NORMAL', + 'PRAGMA busy_timeout = 10000', + 'PRAGMA journal_mode = MEMORY', + ], +]; + +foreach ($DBQ as $id => $db) { + if (0 + + or empty($db['type'] ) + or $db['type']!='sqlite' + + or empty($db['host'] ) + or !is_readable($db['host']) + or !strpos($db['host'],'.db') + + ) continue; + + $fname = basename($db['host'],'.db'); + $fname = preg_replace('/\..*$/','',basename($db['host'])); + + $DBQ['all']['attach'][$fname] = $db['host']; + $DBQ['all']['_import'] = empty($DBQ['all']['_import']) ? [] : (array)$DBQ['all']['_import']; + $DBQ['all']['_import'][] = $id; + +} +if (!isset($DBQ['all']['_import']) or count($DBQ['all']['_import'])<2) unset($DBQ['all']); diff --git a/etc/dbq/sqlite-dir.php b/etc/dbq/sqlite-dir.php new file mode 100644 index 00000000..f371d00a --- /dev/null +++ b/etc/dbq/sqlite-dir.php @@ -0,0 +1,42 @@ + $db) { + if (1 + and !empty($db['type']) and $db['type'] == 'sqlite' + and !empty($db['host']) + ) $host_already_exists[$db['host']] = $id; + } + + foreach (nb::ls_dir($DIR_SQLITE,'\.db$') as $file) { + + if (strpos($file,'_conflict-')) continue; + + if (isset($host_already_exists["$DIR_SQLITE/$file"])) { + $DBQ[$host_already_exists["$DIR_SQLITE/$file"]]['sql_pre'][] = 'PRAGMA journal_mode=OFF'; + continue; + } + + $name = basename($file,'.db'); + $id = "${name}-sqlite"; + + if (!isset($DBQ[$id])) $DBQ[$id] = [ + 'host' => "$DIR_SQLITE/$file", + 'type' => 'sqlite', + 'title' => Db::prettyText($name), + '_import' => $name + ]; + } + +} +?> diff --git a/etc/dbq/zz-sqlite.php.disable b/etc/dbq/zz-sqlite.php.disable deleted file mode 100644 index 0fbd1a06..00000000 --- a/etc/dbq/zz-sqlite.php.disable +++ /dev/null @@ -1,47 +0,0 @@ - $db) { - if (1 - and !empty($db['type']) and $db['type'] == 'sqlite' - and !empty($db['host']) - ) $host_already_exists[$db['host']] = $id; - } - - foreach (nb::ls_dir($DIR_SQLITE,'\.db$') as $file) { - - if (strpos($file,'_conflict-')) continue; - - if (isset($host_already_exists["$DIR_SQLITE/$file"])) { - $DBQ[$host_already_exists["$DIR_SQLITE/$file"]]['sql_pre'][] = 'PRAGMA journal_mode=OFF'; - continue; - } - - $name = basename($file,'.db'); - $id = "${name}-sqlite"; - - if (!isset($DBQ[$id])) $DBQ[$id] = [ - 'host' => "$DIR_SQLITE/$file", - 'type' => 'sqlite', - 'title' => Db::prettyText($name), - '_import' => $name - ]; - } - -} - -unset($DIR_SQLITE,$host_already_exists); -?> diff --git a/etc/dbq/zzz-all.php.disable b/etc/dbq/zzz-all.php.disable deleted file mode 100644 index 3953de56..00000000 --- a/etc/dbq/zzz-all.php.disable +++ /dev/null @@ -1,50 +0,0 @@ - ':memory:', - 'type' => 'sqlite', - 'name' => 'all', - 'pdo' => '', - 'default_table' => '', -# NB 20.01.17 '_import' => ['nb'], - 'order' => '10', - 'options' => [ - PDO::ATTR_PERSISTENT => true, - ], - 'tables' => [], - 'types' => [ - 'sql_pre' => [], - ], - 'sql_pre' => [ - #'PRAGMA synchronous = NORMAL', - 'PRAGMA busy_timeout = 10000', - 'PRAGMA journal_mode = MEMORY', - ], -]; - -foreach ($DBQ as $id => $db) { - if (0 - - or empty($db['type'] ) - or $db['type']!='sqlite' - - or empty($db['host'] ) - or !is_readable($db['host']) - or !strpos($db['host'],'.db') - - ) continue; - - $fname = basename($db['host'],'.db'); - $fname = preg_replace('/\..*$/','',basename($db['host'])); - - $DBQ['all']['attach'][$fname] = $db['host']; - $DBQ['all']['_import'] = empty($DBQ['all']['_import']) ? [] : (array)$DBQ['all']['_import']; - $DBQ['all']['_import'][] = $id; - -} -if (!isset($DBQ['all']['_import']) or count($DBQ['all']['_import'])<2) unset($DBQ['all']); diff --git a/lib/php/db/config.php b/lib/php/db/config.php index df5dd195..3ac6562a 100644 --- a/lib/php/db/config.php +++ b/lib/php/db/config.php @@ -2,6 +2,7 @@ require_once(realpath(dirname(__FILE__).'/../config.php')); require_once(NB_ROOT.'/lib/php/db.php'); if (empty($_SERVER['HOME'])) $_SERVER['HOME'] = ''; +if (empty($DBQ)) $DBQ = []; $DB_CONFS = array_merge([], # ::ROOT_DIR