]> git.nbdom.net Git - nb.git/commitdiff
a=db.dbs
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Wed, 25 May 2016 16:04:48 +0000 (17:04 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Wed, 25 May 2016 16:04:48 +0000 (17:04 +0100)
lib/php/db.php

index 4fbaf61ea84394904950581bb9ca9c5edfb138ec..a5c9803acb370654086b23bd004ffd51fa06f8da 100644 (file)
@@ -82,10 +82,8 @@ class Db extends nb {
        function connect_init() {
     if (empty($this->pdo) and $this->type) $this->pdo = $this->type.':';
     if (empty($this->type)) $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$this->pdo));
-
-    # User
-    #preg_match_all('/[:;](user|username|password)=([^;]*)/',$this->pdo,$m); bye($m);
     if( !$this->type ) return false;
+
     if ($this->type('use_path')) {
       $this->file = preg_replace('/^\w+:/','',$this->pdo);
       if ($p = $this->p('db.host')) $this->file = $p;
@@ -97,7 +95,7 @@ class Db extends nb {
       if (preg_match_all("/[:;](\w+)=([^;]+)/",$this->pdo,$m,PREG_SET_ORDER)) {
         #array_shift($m);
         foreach ($m as $param) {
-          $k = $param[1]; 
+          $k = $param[1];
           if ($k == 'dbname') $k = 'name';
           if (!empty($this->$k)) continue;
           $this->$k = $param[2];
@@ -411,8 +409,22 @@ class Db extends nb {
           $return = $this->out(array_values($this->conf));
 
         } elseif ($action == 'db.dbs' or $action == 'dbs') {
-          if (self::p('hash')) $return = $this->out($this->conf);
-          else $return = $this->out($this->dbs,"name");
+          if (self::p('hash') or self::p('all')) {
+            $fields = ['id','name','host','type'];
+            $dbs = [];
+            foreach ($this->conf as $id => $attr) {
+              $d = new Db();
+              foreach ($attr as $k=>$v) $d->$k = $v;
+              $d->connect_init();
+              $db = []; $d->id = $id;
+              foreach ($fields as $k) {
+                if (!isset($d->$k)) continue; $db[$k] = $d->$k;
+              }
+              $dbs[] = $db;
+            }
+            $return = $this->out($dbs,$fields);
+          }
+          else $return = $this->out($this->dbs,"id");
 
         } elseif ($r=self::class_action_out($this,$action)) {
           return $r;
@@ -457,23 +469,20 @@ class Db extends nb {
 
     # Emulate hash pointer _import
     foreach ($h as $db=>$o) {
+
       foreach ($o as $k => $v) {
-        if ($k != '_conf_dbs_copy'
-          and $k != '_import'
-        ) continue;
+        if ($k != '_import') continue;
 
         $import = is_array($v) ? $v : explode(',',$v);
-        #debug($import);
         foreach ($import as $v) {
           if (empty($h[$v])) continue;
+
           foreach ($h[$v] as $kk => $vv) {
             if (!isset($o[$kk])) $h[$db][$kk] = $vv;
           }
         }
 
         unset($h[$db][$k]);
-        #bye($h[$db]);
-
       }
     }
 
@@ -485,19 +494,12 @@ class Db extends nb {
 
     # Sort
 
-    #self::hksort($h,'order');
     uasort($h,create_function('$a,$b','$a_=isset($a["order"])?$a["order"]:-1;$b_=isset($b["order"])?$b["order"]:-1; return($b_-$a_);'));
     if (!$h) return false;
-    #self::bye($h['puppetdb']);
-    #if ($first !== false) debug ( self::ar_first($h) );
     if ($first !== false) $first = self::ar_first($h);
     return $h;
   }
 
-  function Z__destruct() {
-    echo "__destruct\n";
-  }
-
   //
   // Create globals from $conf=array(yaml_fileds)
   //