Piotr Labudda 9 лет назад
Родитель
Сommit
ae5ee87a17
2 измененных файлов с 46 добавлено и 53 удалено
  1. 22 19
      SE/se-lib/Route/Storage.php
  2. 24 34
      SE/se-lib/Schema/SystemObjectStorageAcl.php

+ 22 - 19
SE/se-lib/Route/Storage.php

@@ -1653,7 +1653,7 @@ jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(
 		UI::dol();
 	}
 
-	public function systemObjectsAction() {
+	public function systemObjectsAction() {// TableAjax view: index.php?_route=ViewTableAjax&namespace=default_objects/SystemObject
 		UI::gora();
 		UI::menu();
 		$this->navView();
@@ -1663,22 +1663,26 @@ jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(
 			UI::table([
 				'rows' => array_map(
 					function ($item) {
+						$exNs = explode('/', $item['namespace']);
+						$name = array_pop($exNs);
+						$typeName = implode('__x3A__', $exNs) . ':' . $name;
 						return [
 							'ns' => $item['namespace'],
-							'nazwa' => $item['nazwa'],
+							'nazwa' => $name,
 							'edit' => '<a href="index.php?_route=ViewTableAjax&namespace=' . $item['namespace'] . '">edit</a>',
-							'wfs Describe' => '<a href="wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureType&TYPENAME=' . $item['typeName'] . '">DescribeFeatureType</a>',
-							'wfs getFeature' => '<a href="wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME=' . $item['typeName'] . '&MAXFEATURES=10">GetFeature</a> (max:10)'
+							'wfs Describe' => '<a href="wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureType&TYPENAME=' . $typeName . '">DescribeFeatureType</a>',
+							'wfs getFeature' => '<a href="wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME=' . $typeName . '&MAXFEATURES=10">GetFeature</a> (max:10)'
 						];
 					}
 					, $acl->getItems([
-						'order_by' => 'ID',
+						'order_by' => 'namespace',
 						'order_dir' => 'asc'
 					])
 				)
 			]);
 		} catch (Exception $e) {
 			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+			DBG::log($e);
 		}
 		UI::dol();
 	}
@@ -1687,22 +1691,17 @@ jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(
 		UI::gora();
 		UI::startContainer();
 		try {
-			$ns = V::get('namespace', '', $_GET);
-			if (empty($ns)) throw new Exception("Missing param namespace");
-			$exNs = explode('/', $ns);
-			if (1 == count($exNs)) throw new Exception("Wrong param namespace");
-			$name = array_pop($exNs);
-			$nsPrefix = implode('__x3A__', $exNs);
+			$namespace = V::get('namespace', '', $_GET);
+			if (empty($namespace)) throw new Exception("Missing param namespace");
 			Lib::loadClass('Schema_SystemObjectStorageAcl');
 			$acl = new Schema_SystemObjectStorageAcl();
 			$items = $acl->getItems([
-				'f_name' => "={$name}",
-				'f_nsPrefix' => "={$nsPrefix}"
+				'f_namespace' => "={$namespace}",
 			]);
-			if (empty($items)) throw new Exception("SystemObject '{$ns}' not found");
+			if (empty($items)) throw new Exception("SystemObject '{$namespace}' not found");
 			$item = reset($items);
-			if (empty($item)) throw new Exception("SystemObject '{$ns}' not found");
-			DBG::nicePrint($item, '$item');
+			if (empty($item)) throw new Exception("SystemObject '{$namespace}' not found");
+			DBG::log($item, 'array', '$item');
 
 			switch ($item['_type']) {
 				case 'AntAcl': $this->reinstallAntAcl($item); break;
@@ -1710,6 +1709,7 @@ jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(
 			}
 		} catch (Exception $e) {
 			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+			DBG::log($e);
 		}
 		UI::endContainer();
 		UI::dol();
@@ -1717,12 +1717,15 @@ jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(
 
 	public function reinstallAntAcl($item) {
 		Lib::loadClass('AntAclBase');
-		$antAclPath = APP_PATH_SCHEMA . DS . 'ant-object' . DS . implode('.', explode('__x3A__', $item['nsPrefix'])) . DS . $item['name'];
-		DBG::nicePrint($antAclPath, '$antAclPath');
+		$exNs = explode('/', $item['namespace']);
+		$name = array_pop($exNs);
+		$antAclPath = APP_PATH_SCHEMA . DS . 'ant-object' . DS . implode('.', $exNs) . DS . $name;
+		if (!file_exists("{$antAclPath}/build.xml")) throw new Exception("Ant build file not exists");
+		DBG::log($antAclPath, 'string', '$antAclPath');
 		$antBin = APP_PATH_WWW . DS . 'stuff' . DS . 'dita-ot-2.3.3' . DS . 'bin' . DS . 'ant';
 		$cmd = "cd {$antAclPath} && {$antBin} DescribeFeatureType 2>&1";
 		V::exec($cmd, $out, $ret);
-		DBG::nicePrint($out, "DescribeFeatureType ret({$ret})");
+		DBG::log($out, 'array', "DescribeFeatureType ret({$ret})");
 		$outputType = 'XML';
 		$html = []; $startRead = false;
 		foreach ($out as $line) {

+ 24 - 34
SE/se-lib/Schema/SystemObjectStorageAcl.php

@@ -12,13 +12,11 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
       '@primaryKey' => 'idZasob',
       'idZasob' => [ '@type' => 'xsd:integer' ],
       'idDatabase' => [ '@type' => 'xsd:integer' ],
-      'nsPrefix' => [ '@type' => 'xsd:string' ],
-      'name' => [ '@type' => 'xsd:string' ],
+      'namespace' => [ '@type' => 'xsd:string' ],
       '_rootTableName' => [ '@type' => 'xsd:string' ],
       '_type' => [ '@type' => 'xsd:string' ],
       'isActive' => [ '@type' => 'xsd:integer' ], // installed
       'description' => [ '@type' => 'xsd:string' ],
-      'namespace' => [ '@type' => 'xsd:string' ],
       'reinstallLink' => [ '@type' => 'p5:www_link' ],
       // 'A_RECORD_CREATE_AUTHOR' => [ '@type' => 'xsd:string' , '@label' => 'autor' ],
       // 'A_RECORD_CREATE_DATE' => [ '@type' => 'xsd:date' , '@label' => 'utworzono' ],
@@ -101,19 +99,19 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 
   public function updateCache($idDatabase = null) {
     DBG::simpleLog('schema', "SystemObject::updateCache...");
-    DB::getPDO()->execSql(" drop table if exists `{$this->_rootTableName}` "); // TODO: DBG
+    // DB::getPDO()->execSql(" drop table if exists `{$this->_rootTableName}` "); // TODO: DBG
+    DB::getPDO()->execSql(" update `{$this->_rootTableName}` set isActive = 0 ");
     DB::getPDO()->execSql("
       create table if not exists `{$this->_rootTableName}` (
         `idZasob` int(11) DEFAULT NULL,
         `idDatabase` int(11) NOT NULL,
-        `nsPrefix` varchar(255) DEFAULT '',
-        `name` varchar(255) DEFAULT '',
+        `namespace` varchar(255) DEFAULT '',
         `_rootTableName` varchar(255) DEFAULT '',
         `_type` varchar(255) DEFAULT '',
         `isActive` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'installed',
         `description` varchar(255) DEFAULT '',
         UNIQUE KEY `idZasob` (idZasob),
-        UNIQUE KEY `typeName` (nsPrefix, name),
+        UNIQUE KEY `namespace` (namespace),
         KEY `isActive` (isActive)
       ) ENGINE=MyISAM  DEFAULT CHARSET=latin2
     ");
@@ -129,13 +127,12 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 						$namespace = $acl->getNamespace();
 						$name = $acl->getName();
 		        DB::getPDO()->execSql("
-		          insert ignore into `{$this->_rootTableName}` (nsPrefix, idDatabase, _type, name, description, isActive)
+		          insert ignore into `{$this->_rootTableName}` (namespace, idDatabase, _type, description, isActive)
 		            values (
-		              '{$source['nsPrefix']}'
+		              '{$source['nsPrefix']}/{$name}'
 									, '{$source['idZasob']}'
                   , 'StorageAcl'
-									, '{$name}'
-									, ''
+									, '{$namespace}' -- test
 									, '1'
 		            )
 		        ");
@@ -144,11 +141,10 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 					}
 				}
         DB::getPDO()->execSql("
-          insert into `{$this->_rootTableName}` (idZasob, nsPrefix, idDatabase, name, description, isActive)
-            select t.ID as idZasob
-                , '{$source['nsPrefix']}' as nsPrefix
+          insert into `{$this->_rootTableName}` (namespace, idZasob, idDatabase, description, isActive)
+            select concat('{$source['nsPrefix']}/', t.`DESC`)
+                ,  t.ID as idZasob
                 ,  '{$source['idZasob']}' as idDatabase
-                ,  t.`DESC` as name
                 ,  t.`OPIS` as description
                 ,  1 as isActive
             from CRM_LISTA_ZASOBOW t
@@ -168,10 +164,9 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
             UI::alert('warning', "TODO: { id: {$source['idZasob']}, nsPrefix: '{$source['nsPrefix']}', dbName: '{$dbName}', dbType: '{$dbType}'} ...");
             // TODO: if another DB split select and insert
             DB::getPDO()->execSql("
-              insert into `{$this->_rootTableName}` (idDatabase, nsPrefix, name, _rootTableName, _type, description)
-                select '{$source['idZasob']}' as idDatabase
-                    , '{$source['nsPrefix']}' as nsPrefix
-                    , t.TABLE_NAME as name
+              insert into `{$this->_rootTableName}` (namespace, idDatabase, _rootTableName, _type, description)
+                select concat('{$source['nsPrefix']}/', t.TABLE_NAME) as namespace
+                    , '{$source['idZasob']}' as idDatabase
                     , t.TABLE_NAME as _rootTableName
                     , 'TableAcl' as _type
                     , t.TABLE_COMMENT as description
@@ -180,13 +175,12 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
               on duplicate key update _rootTableName = t.TABLE_NAME
             ");
             DB::getPDO()->execSql("
-              insert into `{$this->_rootTableName}` (idZasob, nsPrefix, idDatabase, name, description, isActive)
-                select t.ID as idZasob
-                    , '{$source['nsPrefix']}' as nsPrefix
-                    ,  '{$source['idZasob']}' as idDatabase
-                    ,  t.`DESC` as name
-                    ,  t.`OPIS` as description
-                    ,  1 as isActive
+              insert into `{$this->_rootTableName}` (namespace, idZasob, idDatabase, description, isActive)
+                select concat('{$source['nsPrefix']}/', t.`DESC`) as namespace
+                    , t.ID as idZasob
+                    , '{$source['idZasob']}' as idDatabase
+                    , t.`OPIS` as description
+                    , 1 as isActive
                 from CRM_LISTA_ZASOBOW t
                 where t.`TYPE` = 'TABELA'
                   and t.A_STATUS in('NORMAL', 'WAITING')
@@ -225,15 +219,13 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
         // $namespace = $acl->getNamespace();
         // $name = $acl->getName();
         $idDatabase = DB::getPDO($sourceName)->getZasobId();
-        $sqlNsPrefix = "{$sourceName}__x3A__{$rootTableName}";
-        $sqlName = $name;
+        $sqlNamespace = "{$sourceName}/{$rootTableName}/{$name}";
         DB::getPDO()->execSql("
-          insert into `{$this->_rootTableName}` (nsPrefix, idDatabase, _type, name, description, isActive)
+          insert into `{$this->_rootTableName}` (namespace, idDatabase, _type, description, isActive)
             values (
-              '{$sqlNsPrefix}'
+              '{$sqlNamespace}'
               , '{$idDatabase}'
               , 'AntAcl'
-              , '{$sqlName}'
               , ''
               , '1'
             )
@@ -344,9 +336,7 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
   }
 
   public function buildFeatureFromSqlRow($item) {
-    $namespace = str_replace('__x3A__', '/', $item['nsPrefix']) . '/' . $item['name'];
-    $item['namespace'] = $namespace;
-    $item['reinstallLink'] = Router::getRoute('Storage')->getLink('objectReinstall', [ 'namespace' => $namespace ]);
+    $item['reinstallLink'] = Router::getRoute('Storage')->getLink('objectReinstall', [ 'namespace' => $item['namespace'] ]);
     return $item;
   }