Przeglądaj źródła

mv to PDO in Xsd api route

Piotr Labudda 6 lat temu
rodzic
commit
e0318248eb
1 zmienionych plików z 17 dodań i 15 usunięć
  1. 17 15
      SE/se-lib/Api/Xsd.php

+ 17 - 15
SE/se-lib/Api/Xsd.php

@@ -27,28 +27,30 @@ class Api_Xsd extends ApiRouteBase {
 		$this->_dataSourceName = array_shift($request->segments);
 
 		if ('default_db' == $this->_dataSourceName) {
-			$db = DB::getDB();
-
 			$limit = 1000;
-			$tbls = array();
-			$sql = "show full tables";
-			$res = $db->query($sql);
-			while ($r = $db->fetch($res)) {
-				if ('BASE TABLE' == $r->Table_type) {
-					$tblName = get_object_vars($r);
-					$tblName = array_values($tblName);
-					$tblName = reset($tblName);
-
-					if ('DEALS_TABLE_2015_03_17_zest_dla_zubryka' == $tblName) continue;// fields name 'grup_concat(...'
-					if (false !== strpos($tblName, '#')) continue;
-
+			$rawListAllTables = DB::getPDO()->fetchAll(" show full tables where Table_type = 'BASE TABLE' ");
+			$listAllTableNames = array_map(function ($item) {
+				$values = array_values($item);
+				return $values[0];
+			}, $rawListAllTables);
+			$listAllowedTableNames = array_filter($listAllTableNames, function ($tableName) {
+				if (false !== strpos($tableName, '@')) return false;
+				if (false !== strpos($tableName, '#')) return false;
+				if ('_HIST' === substr($tableName, -1 * strlen('_HIST'))) return false;
+				if ('DEALS_TABLE_2015_03_17_zest_dla_zubryka' === $tableName) return false; // fields name 'grup_concat(...'
+				return true;
+			});
+			$tbls = [];
+			$tableNames = array_slice($listAllowedTableNames, 0, $limit);
+			foreach ($tableNames as $tblName) {
 					$ds = new Data_Source();
 					$ds->set_table($tblName);
 					$ds->get_cols();
 					$tbls[$tblName] = $ds;
+
 					if (--$limit < 0) break;
-				}
 			}
+
 			$xml = <<<XMLEOF
 <?xml version="1.0"?>
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:{$this->_dataSourceName}="http://biuro.biall-net.pl/xmlschema_procesy5/{$this->_dataSourceName}" targetNamespace="http://biuro.biall-net.pl/xmlschema_procesy5/{$this->_dataSourceName}">