]> git.nbdom.net Git - nb.git/commitdiff
fix bug on actions tables
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 16 Sep 2016 14:41:02 +0000 (16:41 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 16 Sep 2016 14:41:02 +0000 (16:41 +0200)
etc/dbs.php
etc/dbs/nb.php
etc/dbs/owncloud.php
lib/php/db.php
lib/php/db/table.php
lib/php/nb.php

index 7f6460b325b456d5e026c0f242eae6f11ded60bf..a9e352f6d4b4d7747e9f1979657f84250f81982d 100644 (file)
@@ -58,6 +58,7 @@ if ($DIR_SQLITE) {
       'title' => 'created by dbs.php',
       '_import' => $name
     ];
+    #if (!empty($CONF[$name])) $CONF[$id] = array_merge_recursive($CONF[$name],$CONF[$id]);
   }
 }
 
@@ -83,9 +84,7 @@ $CONF['all'] = [
   ],
 ];
 
-#debug($CONF['postfix']);
 foreach ($CONF as $id => $db) {
-  #debug($db);
   if (0
     or empty($db['type'] )
     or $db['type']!='sqlite'
@@ -94,26 +93,28 @@ foreach ($CONF as $id => $db) {
     #or !is_readable($fname)
     or !is_readable($db['host'])
   ) continue;
-  #debug(basename($db['host'],'.db'));
   $fname = basename($db['host'],'.db');
   $CONF['all']['types']['exec'][] = "ATTACH DATABASE '".$db['host']."' as ".$fname."";
   conf_merge($CONF[$id],$CONF['all']);
 
 }
 
-conf_merge($CONF['_nb'],$CONF['all']);
 conf_merge($CONF['nb'],$CONF['all']);
+return 1;
+
 function conf_merge(&$c1,&$c2) {
 
-  if (!empty($c1['tables']))
+  if (!empty($c1['tables'])) {
   #debug('zaza');
     #$c2['tables'] = array_merge($c2['tables'],$c1['tables']);
     #$c2['tables']
     #$c1['tables']
+    if (empty($c1['tables'])) $c1['tables'] = [];
     foreach ($c1['tables'] as $k=>$v) {
+      #debug($k);
       $c2['tables'][$k] = $v;
     }
-  ;
+  }
 
   foreach ([
     'default_table',
index 4a27e85228bf2f48c5fd5a53f9190ab01c53e005..c2de8764d665d117053dec6eaf5b8872e233c0c4 100644 (file)
@@ -4,23 +4,8 @@ $CONF['nb'] = array(
   'host' => 'admin.izideal.vpn',
   'type' => 'mysql',
   'name' => 'nb',
-  #'order' => ($LOCAL_DB ? null : 1),
-  #'order' => 1,
-  '_import' => ['_nb','_nico'],
-);
-if (strpos(php_uname("n"),'ovh.net')!==false) $CONF['nb']['order'] = 1;
+  '_import' => ['_nico'],
 
-/*****************************************************************************
-if ($LOCAL_DB and !empty($CONF['nb-sqlite']) and isset($CONF['nb']['order'])) {
-  $CONF['nb-sqlite']['order'] = isset($CONF['nb']['order']) ? $CONF['nb']['order'] : 1;
-  unset($CONF['nb']['order']);
-}
-*****************************************************************************/
-#die(print_r(posix_getpwnam('nico'),true));
-#die(print_r(posix_getpwuid(posix_getuid()),true));
-#die(print_r(pathinfo('~/.gitconfig'),true));
-#die(file_exists(realpath('~/.gitconfig')) ? 'yes' : 'no');
-$CONF['_nb'] = array(
   'title' => 'Nb',
   'notice' => 'Micro foncier 4BE',
   'default_table' => 'rent',
@@ -79,6 +64,7 @@ $CONF['_nb'] = array(
   ),
 );
 
+if (strpos(php_uname("n"),'ovh.net')!==false) $CONF['nb']['order'] = 1;
 return 1;
 
 function tenant_doc(&$r) { return rent_doc('tenant',$r); }
index 2d4a7fab8078a78ac4d2260037d11332ced9ed9f..70abbaa7c638dee9990e1ef457b8ebaa83a2d8ae 100644 (file)
@@ -5,9 +5,9 @@ $CONF['owncloud'] = [
   'type' => 'mysql',
   'host' => 'admin.izideal.vpn',
   #'default_table' => 'oc_users',
-  'default_table' => 'last_files',
+  'default_table' => 'oc_last_files',
   'tables' => [
-    'view_contact' => [
+    'oc_contact' => [
       #'sql' => "SELECT * FROM oc_contacts_cards_properties",
       'sql' => "SELECT c.id"
         #.",org.value as org"
@@ -31,7 +31,7 @@ $CONF['owncloud'] = [
       ,
       'row_parse_pre' => 'owncloud_row_parse',
     ],
-    'last_files' => [
+    'oc_last_files' => [
       'sql' => "SELECT path,mtime FROM oc_filecache WHERE path NOT LIKE 'files_versions/%' ORDER BY fileid DESC LIMIT 10",
       'row_parse_pre' => function(&$r) {
         $r['mtime'] = date ("Y-m-d H:i:s",$r['mtime']);
index b8cf5bc520df52a5560d927626b9c472d1e8252a..a1a167b74431c0c648eca77408d95dec2226f343 100644 (file)
@@ -88,6 +88,8 @@ class Db extends nb {
 
     # Tables
     if (isset($opt['tables'])) {
+      #debug($opt['tables']);
+      #foreach ($opt['tables'] as $name=>$param) debug($name);
       foreach ($opt['tables'] as $name=>$param) $this->table($name,$param);
       unset($opt['tables']);
     }
@@ -310,7 +312,7 @@ class Db extends nb {
   */
   public function table($name,$params=[]) {
     #if (!array_key_exists($name,$this->tables)) {
-    if (!$name) bye('empty name');
+    if (!$name) bye('table name is empty');
     if (empty($this->tables[$name])) {
       $this->tables[$name] = new Table($name,['db'=>$this]+$params);
     } elseif ($params) {
@@ -414,9 +416,6 @@ class Db extends nb {
     #if (!isset($this->tables)) {
       $this->_tables = true;
 
-# NB 09.09.16       $sql = $this->type('tables',true,$this->type);
-# NB 09.09.16       if (is_callable($sql)) $sql = $sql($this);
-# NB 09.09.16       $sql = $this->unvar($sql);
       $sql = $this->method('tables');
 
       foreach ($this->conn->query($sql,PDO::FETCH_ASSOC) as $row) {
@@ -456,6 +455,7 @@ class Db extends nb {
   }
 
   public function action($action,$table=null) {
+    #debug(($this->tables));
     $available = [
       ['(db.)?help','This help'],
       ['(db.)?ls','List databases from conf'],
@@ -489,7 +489,9 @@ class Db extends nb {
           #if ($count = $this->p('count','')) $this->pset('count',1);
           $engine = $this->p('engine','');
 
+          #var_dump ($this->tables());
           foreach ($this->tables() as $t) {
+            #debug($t->name);
             if (!empty($name) and !$this->str_match($t->name,$name)) continue;
             if (!empty($type) and !$this->str_match($t->type,$type)) continue;
             if (!empty($count) and !$this->str_match($t->count,$count)) continue;
@@ -498,6 +500,8 @@ class Db extends nb {
             $rows[] = $t->status();
           }
 
+          #bye($rows);
+          $rows = self::array_fill_assoc($rows);
           usort($rows,function($a,$b) { return strcmp($a['name'],$b['name']); });
           $return = $this->out($rows);
 
index a856b80e29277c06a8b3a871beb6a0561f231289..2c3ce1380270c1974109ca991def063bba07091a 100644 (file)
@@ -23,8 +23,8 @@ Class Table extends nb {
   public $type; # table, view, sql
   public $sql;
 # NB 28.03.16   public $fields_keys;
-  public $replace = array(); # replace by javascript
-  public $extras = array();
+  public $replace = []; # replace by javascript
+  public $extras = [];
   public $row_parse_pre; # Function to call in rows()
   public $row_parse_post; # Function to call in rows()
   public $count;
@@ -33,14 +33,14 @@ Class Table extends nb {
   public static $is_admin = true;
 
   # hidden, sort, ... fields
-  public static $params = array( 'db', 'table', 'limit', 'debug', 'action'
+  public static $params = [ 'db', 'table', 'limit', 'debug', 'action'
     , 'page', 'paged' # wordpress
-  );
+  ];
 
   public $fields;
   public $indexes;
 
-  function __construct($name,$opt=array()) {
+  function __construct($name,$opt=[]) {
 
     if (!is_scalar($name)) {
       $opt = $name;
@@ -1352,6 +1352,7 @@ Class Table extends nb {
   public function out($v,$head=array()) { return $this->db()->out($v,$head); }
 
   public function infos() {
+  debug('TODEL');
     return ['TODEL'];
   # TODEL - NB 07.09.16
     $this->type();
@@ -1678,17 +1679,26 @@ Class Table extends nb {
   }
 
   public function status($key=null) {
+    #if ($this->type!='table' and $this->type=!'view') { }
     if (!isset($this->status)) {
-      $this->status = [];
+      $this->create_temporary();
 
-      $sql = $this->db()->type('tables');
-      if (is_callable($sql)) $sql = $sql($this->db());
-      #$sql .= ' AND name='.$this->db()->quote($this->name);
+      $sql = $this->db()->method('tables');
       $sql = "SELECT * FROM ($sql) t WHERE name=".$this->db()->quote($this->name);
 
       $sth = $this->db()->conn->query($sql,PDO::FETCH_ASSOC);
       if (!empty($sth)) $this->status = $sth->fetch();
+      if (empty($this->status)) $this->status = [];
 
+      # Add to status array
+      foreach ([
+        'name',
+        'type',
+      ] as $k) {
+        if (!empty($this->$k) and empty($this->status[$k])) $this->status[$k] = $this->$k;
+      }
+
+      # Add from status array
       foreach ([
         'engine',
         'created',
@@ -1707,6 +1717,7 @@ Class Table extends nb {
       if (is_array($this->status[$k])) $this->status[$k] = count($this->status[$k]);
     }
 
+    #debug([$this->name,$this->status,$this->sql()]);
     if (!empty($key)) return ( empty($this->status[$key]) ? '' : $this->status[$key] );
     return $this->status;
   }
index 0b446678648def65ee00495b3a0b522d25fd53cf..e349f95d3dfbfcfbb69c7e5ba42749c353781599 100644 (file)
@@ -775,5 +775,17 @@ class NB {
     return $v ? $v[0] : '';
   }
 
+  public static function array_fill_assoc($rows) {
+    $keys = [];
+    foreach($rows as $k=>$v) {
+      $keys = array_merge_recursive(array_keys($v),$keys);
+    }
+    foreach($rows as $k=>$v) {
+      foreach ($keys as $key) {
+        if (empty($v[$key])) $rows[$k][$key] = '';
+      }
+    }
+    return $rows;
+  }
 } # < Class
 ?>