From: Nicolas Boisselier Date: Wed, 21 Sep 2016 22:46:40 +0000 (+0100) Subject: fix bug X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=2f3e09e02031e353537e403510206b168f52b730;p=nb.git fix bug --- diff --git a/lib/php/db.php b/lib/php/db.php index 64cb6d53..2582dc20 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -213,7 +213,7 @@ class Db extends nb { foreach(['name','host','file'] as $p) { if (!empty($this->$p)) $msg .= " $p=".$this->$p; } - $msg .= $e->getMessage(); + $msg .= "\n".$e->getMessage(); throw new Exception($msg, (int)$e->getCode()); self::bye($msg); @@ -560,23 +560,14 @@ class Db extends nb { } unset($yaml,$DBQ); + if (!$dbs) return false; # - # Import database conf with key _import + # First iteration: Import database conf with key _import # foreach ($dbs as $id=>$params) { - $params = (array)$params; - # If _default exists spush it to all dbs's _import - if ($id == '_default') { - continue; - } elseif(!empty($dbs['_default'])) { - if (empty($params['_import'])) $params['_import'] = []; - elseif (is_scalar($params['_import'])) $params['_import'] = (array)$params['_import']; - $params['_import'][] = '_default'; - } - foreach ($params as $k => $v) { if ($k != '_import') continue; @@ -594,18 +585,28 @@ class Db extends nb { } } - # Remove db starting with _ - foreach ($dbs as $db=>$o) { if (preg_match('/^_/',$db)) unset($dbs[$db]); } + $default = isset($dbs['_default']) ? $dbs['_default'] : []; + + # + # Second iteration: Remove db starting with _ + # + foreach ($dbs as $db=>$params) { if (preg_match('/^_/',$db)) unset($dbs[$db]); } if (!$dbs) return false; - # Add missing name - foreach ($dbs as $db=>$o) { - if (empty($o['name'])) $dbs[$db]['name'] = $db; - if (empty($o['id'])) $dbs[$db]['id'] = $db; + # + # Third iteration: Add missing and default + # + foreach ($dbs as $db=>$params) { + if (empty($params['name'])) $dbs[$db]['name'] = $db; + if (empty($params['id'])) $dbs[$db]['id'] = $db; + + foreach ($default as $k=>$v) if (!isset($params[$k])) $dbs[$db][$k] = $v; } + # # Sort by `order`, min first + # uasort($dbs,function($a,$b){ if (empty($a['order']) and empty($b['order'])) return strcmp($a['id'],$b['id']); $a_ = !empty($a['order']) ? $a['order'] : 9999999; @@ -613,6 +614,9 @@ class Db extends nb { return($a_-$b_); }); + # + # Return + # #debug($file); #bye($dbs['nb']); if (!$dbs) return false;