]> git.nbdom.net Git - nb.git/commitdiff
str_match
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Thu, 30 Jun 2016 15:48:58 +0000 (16:48 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Thu, 30 Jun 2016 15:48:58 +0000 (16:48 +0100)
etc/dbs/ui.php
lib/php/db.php
lib/php/nb.php

index 575d2a8788a89e3e62bef24f49c37baeb6790ae4..8a6ed537aeee91a05583aa62e5180608a145c017 100644 (file)
@@ -5,6 +5,7 @@ $CONF['_ui'] = array(
   'default_table' => 'node',
 
   'sql_replace' => function($sql) {
+    if (!Db::p('db.type')) return $sql;
     $r = [];
 
     $r["CAST(started as char(30)),duration||' seconds'"] = "from_unixtime(UNIX_TIMESTAMP(started)+duration)";
index 67b973758db686ed927be4614f0841be8299aacc..3633f80d82ae4ad7c130d816b616b3f1c82c74b9 100644 (file)
@@ -401,9 +401,8 @@ class Db extends nb {
           $type = self::p('type','');
 
           foreach ($this->tables() as $t) {
-# NB 27.06.16             if (!empty($name) and strpos($t->name,$name) === false) continue;
-            if (!empty($name) and !preg_match('/'.$name.'/',$t->name)) continue;
-            if (!empty($type) and strpos($t->type,$type) === false) continue;
+            if (!empty($name) and !$this->str_match($t->name,$name)) continue;
+            if (!empty($type) and !$this->str_match($t->type,$type)) continue;
             $rows[] = $t->infos();
           }
 
@@ -414,24 +413,29 @@ class Db extends nb {
 
         } elseif ($action == 'db.dbs' or $action == 'dbs') {
           if (self::p('hash') or self::p('all')) {
+
             $fields = ['id','name','host','type'];
             $dbs = [];
             $name = self::p('name','');
             $type = self::p('type','');
+
             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;
               }
-# NB 27.06.16             if (!empty($name) and strpos($db['name'],$name) === false) continue;
-            if (!empty($name) and !preg_match('/'.$name.'/',$db['name'])) continue;
-            if (!empty($type) and strpos($db['type'],$type) === false) continue;
+
+              if (!empty($name) and !$this->str_match($db['name'],$name)) continue;
+              if (!empty($type) and !$this->str_match($db['type'],$type)) continue;
               $dbs[] = $db;
             }
+
             $return = $this->out($dbs,$fields);
+
           }
           else $return = $this->out($this->dbs,"id");
 
@@ -626,9 +630,8 @@ class Db extends nb {
 
     foreach ($tables as $t) {
       if (!empty($tables) and empty($tables[$t->name])) continue;
-      if (!empty($type) and strpos($t->type,$type) === false) continue;
-# NB 27.06.16       if (!empty($name) and strpos($t->name,$name) === false) continue;
-      if (!empty($name) and !preg_match('/'.$name.'/',$t->name)) continue;
+      if (!empty($name) and !$this->str_match($t->name,$name)) continue;
+      if (!empty($type) and !$this->str_match($t->type,$type)) continue;
 
       if ($insert) {
         echo "\n-- ".strtoupper($t->type).": ".$t->name."\n";
index c5470a1cf7ab3a010b621959cfdb1877898e65b7..63aee7ff1f427071c564f5d08e04cd274b3622f6 100644 (file)
@@ -3,17 +3,6 @@ if (!defined('NB_ROOT')) define('NB_ROOT',realpath(dirname(__FILE__).'/../..'));
 if (!defined('NB_EOL')) define('NB_EOL',defined('NB_PROD') ? '' : "\n");
 require_once(realpath(dirname(__FILE__).'/functions.php'));
 #$nb = new NB(); debug($nb->test());
-/*
-if (empty($_SERVER['DOCUMENT_ROOT'])) var_export([
-  '~0    : 0' => nb::str_match('~0','0'),
-  'null  : 0' => nb::str_match('null','0'),
-  'null  : ""' => nb::str_match('null',''),
-  '!null : ""' => nb::str_match('!null',''),
-  '!~zaz : "zaza"' => nb::str_match('!~zaz','zaza'),
-  '~zaz  : "zaza"' => nb::str_match('~zaz','zaza'),
-  'za*   : "zaza"' => nb::str_match('za*','zaza'),
-]);
-*/
 if (class_exists('NB')) return;
 class NB {
 
@@ -537,7 +526,7 @@ class NB {
     }
   }
 
-  public static function str_match($pattern,$string) {
+  public static function str_match($string,$pattern) {
       $match = false;
 
       // No empty values