]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/config.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 4 Jan 2018 23:18:31 +0000 (23:18 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 4 Jan 2018 23:18:31 +0000 (23:18 +0000)
etc/dbq/000-local.php [deleted file]
etc/dbq/nb.php [new file with mode: 0644]
etc/dbq/sqlite-all.php.disable [new file with mode: 0644]
etc/dbq/sqlite-dir.php [new file with mode: 0644]
etc/dbq/zz-sqlite.php.disable [deleted file]
etc/dbq/zzz-all.php.disable [deleted file]
lib/php/db/config.php

diff --git a/etc/dbq/000-local.php b/etc/dbq/000-local.php
deleted file mode 100644 (file)
index 412871c..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-#
-# !!! MANDATORY !!!
-#
-$DBQ = [
-  'nb' => [
-    '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 (file)
index 0000000..f6c4f6f
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+#
+# !!! MANDATORY !!!
+#
+$DBQ['nb'] = [
+  'type' => '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 (file)
index 0000000..3953de5
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+#
+# ALL - Attach all sqlite databases
+#
+#return;
+#die(count($DBQ)."\n");
+$DBQ['all'] = [
+  'host' => ':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 (file)
index 0000000..f371d00
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+#
+# Search *.db into DBQ_DIR_SQLITE
+#
+if (empty($_SERVER['DBQ_DIR_SQLITE'])) return;
+$host_already_exists = [];
+
+foreach ([
+  $_SERVER['DBQ_DIR_SQLITE'],
+  '', # / !!!
+] as $DIR_SQLITE) {
+  if (!is_readable($DIR_SQLITE)) continue;
+
+  foreach ($DBQ as $id => $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 (file)
index 0fbd1a0..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-#
-# Create *-sqlite databases
-#
-$host_already_exists = [];
-
-foreach ([
-  '/home/nico/ownCloud',
-  '/Users/nico/ownCloud',
-  '/home/nico/Dropbox',
-  '/Users/nico/Dropbox',
-  '', # / !!!
-] as $DIR_SQLITE) {
-  if (!is_readable($DIR_SQLITE.'/var/lib/sqlite')) continue;
-  $DIR_SQLITE .= '/var/lib/sqlite';
-
-  foreach ($DBQ as $id => $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 (file)
index 3953de5..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-
-#
-# ALL - Attach all sqlite databases
-#
-#return;
-#die(count($DBQ)."\n");
-$DBQ['all'] = [
-  'host' => ':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']);
index df5dd19599de1467db173e557360d7e44f0c819d..3ac6562a671e524dd49d53a46c4bd3e60ff46d1d 100644 (file)
@@ -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