]> git.nbdom.net Git - nb.git/commitdiff
bin/nb-update
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Feb 2018 02:35:18 +0000 (02:35 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Feb 2018 02:35:18 +0000 (02:35 +0000)
bin/nb-update
etc/dbq/ldap.php
lib/php/db/field.php
lib/php/db/table.php
lib/php/db/types/ldap.php
lib/php/ldap.php
www/dbq/dbq.php

index 385d2fd4ae672b00d4edec87ee0cab3ab1570a1f..6ab5e4c1c7443b819e1c2b317867f4f8b41f0441 100755 (executable)
@@ -107,10 +107,10 @@ for repo in $(nb_repos); do
   fi
 
   echo
-  key="repo.$name.$branch"
-  nb_api_post_host_info "key=${key}.path"        "val=$repo"
-  nb_api_post_host_info "key=${key}.exit_code"   "val=$ex"
-  #nb_api_post_host_info "key=${key}.last_commit" val=$(cd "$repo" && git log | head -1 | awk '/^commit/ { print $2; exit; }')
+  nb_api_post_host_info "key=${NAME}.$repo" "val=name:$name branch:$branch"
+# NB 06.02.18   key="repo.$name.$branch"
+# NB 06.02.18   nb_api_post_host_info "key=${key}.path"        "val=$repo"
+# NB 06.02.18   nb_api_post_host_info "key=${key}.exit_code"   "val=$ex"
 
 done
 
index af04172bc186aad4105873cd4a6a0bb7deb8ac42..f4e127be0513af1aafa7feabcf397445573bd518 100644 (file)
@@ -52,7 +52,12 @@ $DBQ['ldap'] = $GLOBALS['DBQ_LDAP'] + [
        'type' => 'ldap',
        'tables' => [
                $filter => [
-                       'fields' => ['dn','objectClass'],
+                       #'fields' => ['dn','objectClass'],
+                       'fields' => [
+                                       'dn' => (new Field(['name'=>'dn','key'=>true])),
+                                       'objectClass' => (new Field(['name'=>'objectClass'])),
+                       ],
+                       'type' => 'table',
                ],
        ],
        'default_table' => $filter,
index bf0080e15a2c3e34ff3bd75cbb234d2bb4c74a69..72d93f1d1dceceacf8cd3f0ec5ade27673f82256 100644 (file)
@@ -31,8 +31,10 @@ class field extends nb {
     foreach ($attr as $k => $v) { $this->$k = $v; }
   }
 
-  public static function default2str($default) {
-    if ($this->default == "''") $this->default = '';
+  public function default2str($default=null) {
+# NB 06.02.18 Bug    if ($this->default == "''") $this->default = '';
+               if ($default === null) $default = $this->default;
+
 # NB 12.12.17     if (strtoupper($default) == "NULL") $default = null;
     #if (strtoupper($default) == "NOW()") $default = null;
 # NB 08.01.18     if (strtoupper($default) == "NOW()") $default = $date_microtime();
@@ -146,12 +148,14 @@ class field extends nb {
   }
 
   public function sql_name_cast_text() {
+               if (empty($this->db())) return $this->name;
     $name = $this->db()->sql_name($this->name);
     return $this->db()->cast_text($name);
   }
 
   public function sql_name($cast=false) {
                if ($cast and !$this->text()) return $this->sql_name_cast_text();
+               if (empty($this->db())) return $this->name;
     return $this->db()->sql_name($this->name);
   }
 
@@ -292,7 +296,7 @@ class field extends nb {
     #if ($value === null) return '';
     static $sqlite = null; if ($sqlite === null) {
       $db = $this->db();
-      $sqlite = (bool)($db->type == 'sqlite');
+      $sqlite = (bool)(!empty($db->type) and $db->type == 'sqlite');
     }
 
     # Anoying, sqlite does not format properly !
index fb7f2fd4fb86917cf978553aebe4918f2fbdf9ec..a95222d3be97f0b098e25b848da8beb463ddc3d6 100644 (file)
@@ -473,7 +473,7 @@ Class Table extends nb {
                return $ret;
        }
 
-       private function fields_keys(&$others=[]) {
+       public function fields_keys(&$others=[]) {
 
                $fields_keys = [];
 
@@ -542,13 +542,11 @@ Class Table extends nb {
                if ($values === null) $values = $this->p();
                if (!is_array($values)) $values = [$values];
 
-# NB 23.11.17     $fields = $this->fields();
-# NB 23.11.17     $keys = $this->fields_keys();
-
+               if (!$add) {
                $sql = $this->sql_edit($values,$add);
-
                $st = $this->db()->conn->prepare($sql);
                $st->execute();
+               }
 
                // Params
                $form_hidden = '';
@@ -604,7 +602,7 @@ Class Table extends nb {
 # NB 08.01.18         if ($add and !preg_match('/^(null|.*\(.*)?$/',strtolower($field->default))) {
 # NB 08.01.18           $row[$name] = $field->default;
                                if ($add) {
-                                       $row[$name] = $field->default2str($field->default);
+                                       $row[$name] = $field->default2str();
 
                                } elseif(!isset($row[$name])) {
                                        $row[$name] = '';
@@ -999,6 +997,17 @@ Class Table extends nb {
                        $call = $opt['row_parse_pre']; $call($row,$this,$opt);
                }
 
+               //
+               // Fields filter
+               //
+               if ($this->fields_only) {
+                       $new_row = [];
+                       foreach ($this->fields_only as $k) {
+                               if (isset($row[$k])) $new_row[$k] = $row[$k];
+                       }
+                       $row = $new_row;
+               }
+
                //
                // Format
                //
@@ -1062,7 +1071,7 @@ Class Table extends nb {
                #
                # Fields
                #
-               $fields = $this->fields();
+               $opt['fields'] = $fields = $this->fields();
                if ($this->fields_only) {
                        foreach ($fields as $k=>$v) {
                                if (!in_array($k,$this->fields_only)) unset($fields[$k]);
@@ -1087,38 +1096,38 @@ Class Table extends nb {
                list($sql,$where,$limit,$select_count) = $this->rows_sql($opt);
                $nosql = $this->db()->conf_type('nosql');
 
-       if ($nosql) {
-               $sql = empty($this->sql) ? $this->name : $this->sql;
-               $fct = $this->db()->conf_type('prepare');
-               if ($fct) $st = $fct($this,$sql);
-               if (!$fct = $this->db()->conf_type('fetch')) {
-                       $fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); };
-               }
-               #$fct = function() { return false; };
-               #$fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); };
-
-       } else {
-       
-               if ($this->db()->type == 'pgsql') {
-                       $sql_orig = $sql;
-                       $this->db()->conn->beginTransaction();
-                       $sql = "DECLARE table_rows CURSOR FOR $sql";
-                       $cursor = $this->db()->conn->prepare($sql);
-                       $cursor->execute();
-                       $sql = "FETCH 1 FROM table_rows";
+               if ($nosql) {
+                       $sql = empty($this->sql) ? $this->name : $this->sql;
+                       $fct = $this->db()->conf_type('rows_prepare');
+                       if ($fct) $st = $fct($this,$sql);
+                       if (!$fct = $this->db()->conf_type('rows_fetch')) {
+                               $fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); };
+                       }
+                       #$fct = function() { return false; };
+                       #$fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); };
 
                } else {
-                       $this->db()->conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
-               }
+               
+                       if ($this->db()->type == 'pgsql') {
+                               $sql_orig = $sql;
+                               $this->db()->conn->beginTransaction();
+                               $sql = "DECLARE table_rows CURSOR FOR $sql";
+                               $cursor = $this->db()->conn->prepare($sql);
+                               $cursor->execute();
+                               $sql = "FETCH 1 FROM table_rows";
 
-               $st = $this->db()->conn->prepare($sql);#,[PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]);
-               if (empty($cursor)) {
-                       $fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); };
-                       $st->execute();
-               } else {
-                       $fct = function() use($st) { if ($st->execute()) return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); };
-               }
-}
+                       } else {
+                               $this->db()->conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
+                       }
+
+                       $st = $this->db()->conn->prepare($sql);#,[PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]);
+                       if (empty($cursor)) {
+                               $fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); };
+                               $st->execute();
+                       } else {
+                               $fct = function() use($st) { if ($st->execute()) return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); };
+                       }
+       }
                if (!empty($opt['query'])) return $st;
                #
                # Use the module out when format unknow
@@ -1182,17 +1191,6 @@ Class Table extends nb {
 
                        $call = $this->rows_parsers($row,$opt);
 
-                       #
-                       # Fields filter
-                       #
-                       if ($this->fields_only) {
-                               $new_row = [];
-                               foreach ($this->fields_only as $k) {
-                                       if (isset($row[$k])) $new_row[$k] = $row[$k];
-                               }
-                               $row = $new_row;
-                       }
-
                        #
                        # Preffix
                        #
@@ -2174,7 +2172,8 @@ Class Table extends nb {
                // Criterias
                //
                $r .= '<div class="criterias">';
-               foreach ( $this->fields() as $k => $f) {
+               if (!isset($opt['fields'])) $opt['fields'] = $this->fields();
+               foreach ($opt['fields'] as $k => $f) {
 
                        if ($f->is_encrypt()) continue;
                        $v = $this->p($k);
index ae37ec1ee8891e9c0b4c83d98e0f1289557899c2..bba01a51003aaba919c58bf53c5b60826e05ade5 100644 (file)
@@ -8,12 +8,12 @@ $DB_TYPES['ldap'] = [
        'quote' => function($v) { return $v; },
        'nosql' => true,
        #'prepare' => function($sql) { return $this->ldap->prepare($sql); },
-       'prepare' => function($table,$sql) {
+       'rows_prepare' => function($table,$sql) {
                $fields = (empty($table->fields_only) ? array_keys($table->fields()) : $table->fields_only);
                #foreach (array_keys($table->fields) as $k) { if (!in_array($k,$fields)) unset($table->fields[$k]); }
                $table->db()->ldap->prepare($sql,['attrs'=>$fields]); return $table->db()->ldap;
        },
-       'fetch' => function($table) {
+       'rows_fetch' => function($table) {
                #debug($table->fields_only);
                #debug($table->fields_only);
                $row = $table->db()->ldap->fetch();
index 6e687358c80a7480998654a6310bc256628ef8c0..7b6f79bc8c7a37177fe70cfda54ac133514ef257 100644 (file)
@@ -135,7 +135,7 @@ class Ldap {
                 */
        }
 
-       /// PDO compatible
+       /// DB / PDO compatible
        public function setAttribute($k,$v) { }
 
        public function prepare($sql,$o=[]) {
@@ -173,5 +173,15 @@ class Ldap {
                return $this->entry($this->entry,$dn);
        }
 
+       public function _field($name) {
+               return new Field([
+                       'name' => $name,
+                       'type' => 'text',
+               ]);
+       }
+
+       public function _fields_keys(&$others=[]) {
+               return $this->fields('dn');
+       }
        public function closeCursor() {}
 }
index 4e74eda404364a918866ac54408183ae2578e0a5..b8984f034f98b2ca797ce1a75d47a5bfd110fd09 100644 (file)
@@ -435,13 +435,14 @@ class DbQ extends nb {
 
        public function vi($add=false) {
                $all = [];
+               $nosql = $this->db->conf_type('nosql');
+
+               $fields = $this->vi_extract_fields();
 
                $keys = $this->table->fields_keys($all);
                if (!$keys) $keys = $all;
                $keys = array_keys($keys);
 
-               $fields = $this->vi_extract_fields();
-
                $values = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : explode($this->param_args_sep,$this->params['args']);
                foreach ($values as $k=>$v) {
                        if (!in_array($k,$keys)) unset($values[$k]);
@@ -473,7 +474,7 @@ class DbQ extends nb {
        }
 
        public function table_rw() {
-               return (1
+               return (int)(1
                        and ($this->perm >= self::READ)
                        and !empty($this->table)
                        and !empty($this->table->type())