ソースを参照

updated Storage reinstallObject

Piotr Labudda 9 年 前
コミット
e5bec1fb79

+ 2 - 2
SE/schema/ant-object/default_db.TEST_PERMS/TestPermsAnt/TestPermsAnt.xsd

@@ -8,7 +8,7 @@
     targetNamespace="https://biuro.biall-net.pl/wfs/default_objects"
     version="1.0.0">
     <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="https://biuro.biall-net.pl/dev-pl/se-master/schema/gml/2.1.2/feature.xsd"/>
-    <xsd:complexType name="TEST_PERMSType">
+    <xsd:complexType name="TestPermsAntType">
         <xsd:complexContent>
             <xsd:extension base="gml:AbstractFeatureType">
                 <xsd:sequence>
@@ -62,7 +62,7 @@
             </xsd:extension>
         </xsd:complexContent>
     </xsd:complexType>
-    <xsd:element name="TEST_PERMS" type="default_objects:TEST_PERMSType" substitutionGroup="gml:_Feature"/>
+    <xsd:element name="TestPermsAnt" type="default_objects:TestPermsAntType" substitutionGroup="gml:_Feature"/>
 
     <xsd:simpleType name="TestPerms__instanceType">
         <xsd:restriction base="xsd:string">

+ 72 - 7
SE/se-lib/Route/Storage.php

@@ -1703,7 +1703,7 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		if (file_exists("{$antAclPath}/{$item['name']}.xsd")) {
 			DBG::log("{$antAclPath}/{$item['name']}.xsd", 'string', 'xsd file exists');
 			$outputType = 'XML';
-			$html = file_get_contents("{$antAclPath}/{$item['name']}.xsd");
+			$antOutput = file_get_contents("{$antAclPath}/{$item['name']}.xsd");
 		} else {
 			DBG::log($antAclPath, 'string', '$antAclPath');
 			$antBin = APP_PATH_WWW . DS . 'stuff' . DS . 'dita-ot-2.3.3' . DS . 'bin' . DS . 'ant';
@@ -1711,7 +1711,7 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 			V::exec($cmd, $out, $ret);
 			DBG::log($out, 'array', "DescribeFeatureType ret({$ret})");
 			$outputType = 'XML';
-			$html = []; $startRead = false;
+			$antOutput = []; $startRead = false;
 			foreach ($out as $line) {
 				// $line = "     [echo] OUTPUT__TYPE__XML"
 				if ('[echo]' == substr(trim($line), 0, 6)) {
@@ -1730,19 +1730,84 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 					if ('OUTPUT__END' == $line) {
 						break;
 					}
-					$html[]= $line;
+					$antOutput[]= $line;
 				}
 			}
-			if (!empty($html)) $html = implode("\n", $html);
+			if (!empty($antOutput)) $antOutput = implode("\n", $antOutput);
 		}
-		if (empty($html)) UI::alert('danger', "Empty output!");
+		if (empty($antOutput)) UI::alert('danger', "Empty output!");
 		else {
+			echo UI::h('p', [], "Ant Schema:");
 			if ('XML' == $outputType) {
-				echo UI::h('pre', [], htmlspecialchars($html));
+				echo UI::h('pre', ['style' => 'max-height:400px; overflow:scroll'], htmlspecialchars($antOutput));
 			} else if ('HTML' == $outputType) {
-				echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
+				echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $antOutput);
 			}
 		}
+
+		Lib::loadClass('XML');
+		$schema = XML::readXmlFileToArray("{$antAclPath}/{$item['name']}.xsd");
+		if (empty($schema)) throw new Exception("Missing schema");
+		$xsdType = [ // find xsd:element with @name = $item['name']
+			'nsPrefix' => null,
+			'name' => null,
+			'nsUri' => null,
+			'targetNsUri' => V::get('targetNamespace', '', $schema[1])
+		];
+		if (!$xsdType['targetNsUri']) throw new Exception("Missing schema target namespace declaration '{$item['name']}'");
+		foreach ($schema[2] as $n) {
+			if ('xsd:element' != $n[0]) continue;
+			if ($item['name'] != V::get('name', '', $n[1])) continue;
+			list($xsdType['nsPrefix'], $xsdType['name']) = explode(':', V::get('type', '', $n[1]));
+		}
+		if (!$xsdType['nsPrefix'] || !$xsdType['name']) throw new Exception("Missing schema root element name = '{$item['name']}'");
+
+		$xsdType['nsUri'] = V::get("xmlns:{$xsdType['nsPrefix']}", '', $schema[1]);// find xmlns:default_objects = "https://biuro.biall-net.pl/wfs/default_objects"
+		if (!$xsdType['nsUri']) throw new Exception("Missing schema root element namespace declaration = '{$item['name']}'");
+		if ($xsdType['nsUri'] != $xsdType['targetNsUri']) throw new Exception("TODO: type ns is not the same as targetNamespace '{$item['name']}'");// TODO
+
+		foreach ($schema[2] as $n) {
+			if ('xsd:complexType' != $n[0]) continue;
+			if ($xsdType['name'] != V::get('name', '', $n[1])) continue;
+			DBG::nicePrint($n, 'TODO: parse complexType');
+			// complexType/complexContent/extension[base=...]/sequence/element
+			if ($n[2][0][0] != 'xsd:complexContent') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent'");
+			if ($n[2][0][2][0][0] != 'xsd:extension') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent/extension'");
+			$xsdType['extensionBase'] = V::get('base', '', $n[2][0][2][0][1]);
+			if ($n[2][0][2][0][2][0][0] != 'xsd:sequence') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent/extension/sequence'");
+			foreach ($n[2][0][2][0][2][0][2] as $f) {
+				if ($f[0] !== 'xsd:element') {
+					DBG::log($n, 'array', "Schema xsd parse error - Not implemented node type '{$f[0]}'");
+					continue;
+				}
+				$fieldName = V::get('name', '', $f[1]);
+				if (!$fieldName) throw new Exception("Error Parsing Schema - expected 'element[@name]'");
+				$xsdType['struct'][$fieldName] = [
+					'type' => V::get('type', '', $f[1]),
+					'ref' => V::get('ref', '', $f[1]),
+					'minOccurs' => V::get('minOccurs', 0, $f[1], 'int'),
+					'maxOccurs' => V::get('maxOccurs', '1', $f[1]),
+				];
+			}
+		}
+
+		DBG::nicePrint($xsdType, '$xsdType');
+		// TODO: insert fields $xsdType['struct'] by 'SystemObjectField'
+		// getStorage('SystemObjectField')->update(['isActive' => 0], ['#refFrom' => ['ns' => 'SystemObject', 'pk' => $item['namespace']]]) // TODO: update pk in SysObj schema
+		// getStorage('SystemObjectField')->insertOrUpdate([ 'isActive' => 1, ... , '@insert' => [], '@update' => [] ])
+
+		{
+			DBG::nicePrint($schema, '$schema');
+			Lib::loadClass('Core_XmlWriter');
+			ob_start();
+			$xmlWriter = new Core_XmlWriter();
+			$xmlWriter->openUri('php://output');
+			$xmlWriter->setIndent(true);
+			$xmlWriter->startDocument('1.0','UTF-8');
+			$xmlWriter->h($schema[0], $schema[1], $schema[2]);
+			$xmlWriter->endDocument();
+			echo UI::h('pre', ['style' => 'max-height:400px; overflow:scroll'], htmlspecialchars(ob_get_clean()));
+		}
 	}
 
 }

+ 1 - 1
SE/se-lib/Schema/SystemObjectFieldStorageAcl.php

@@ -4,7 +4,7 @@ Lib::loadClass('Core_AclSimpleSchemaBase');
 Lib::loadClass('ParseOgcFilter');
 Lib::loadClass('Router');
 
-class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
+class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 
   public $_simpleSchema = [
     'root' => [

+ 1 - 1
SE/se-lib/Schema/SystemObjectStorageAcl.php

@@ -9,7 +9,7 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
   public $_simpleSchema = [
     'root' => [
       '@namespace' => 'default_objects/SystemObject',
-      '@primaryKey' => 'idZasob',
+      '@primaryKey' => 'idZasob', // TODO: namespace
       'idZasob' => [ '@type' => 'xsd:integer' ],
       'idDatabase' => [ '@type' => 'xsd:integer' ],
       'namespace' => [ '@type' => 'xsd:string' ],