From a79e3f123b9b525ce153bb0e4b37a6283a6b057f Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 26 Mar 2016 17:42:10 +0000 Subject: [PATCH] db::init accept conf when not files --- lib/php/db.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 837b8be8..04b491e1 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -580,10 +580,12 @@ EOF; */ static function conf_dbs($files=array(),&$first=false) { if (empty($files)) return array(); - if (is_scalar($files)) $files = array($files); - # Load all files into a hash + # Load all files into a $h if #files is not a hash + $h = array(); + if (is_scalar($files)) $files = array($files); + foreach ($files as $file) { if (is_readable($file) and ($yaml = yaml_parse_file($file))) { #foreach ($yaml as $k=>$v) { $yaml[$k]['_conf_dbs'] = $file; } @@ -626,6 +628,9 @@ EOF; # Add missing name foreach ($h as $db=>$o) { if (empty($o['name'])) $h[$db]['name'] = $db; } + # Sort + + self::hksort($h,'order'); if (!$h) return false; #self::bye($h['puppetdb']); #if ($first !== false) debug ( self::ar_first($h) ); @@ -647,13 +652,11 @@ EOF; if (isset($Db)) self::bye("Db.init(): GLOBALS['Db'] already exists !"); $Db = new self(); - #bye($_SERVER["PHP_SELF"]); bye($_SERVER); -# NB 19.03.16 if (!in_array(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml'; -# NB 19.03.16 if (!in_array('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml'; # Load databases - if (! ($dbs = $Db->conf_dbs($conf)) ) return false; - $Db->hksort($dbs,'order'); + $dbs = self::is_hash($conf) ? $conf : $Db->conf_dbs($conf); + if (!$dbs) return false; + #if (! ($dbs = $Db->conf_dbs($conf)) ) return false; #bye($dbs['nb']); #die (nb::p('db')); -- 2.47.3