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;
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];
$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;
# 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]);
-
}
}
# 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)
//