Browse Source

updated acl reinstall - moved parse xsd to XML, added reinstall after POST, todo preview reinstall

Piotr Labudda 8 years ago
parent
commit
bfdc78cf0f

+ 82 - 0
SE/se-lib/Route/Storage/AclReinstall.php

@@ -21,6 +21,30 @@ class Route_Storage_AclReinstall extends RouteBase {
 			$namespace = V::get('namespace', '', $_GET);
 			if (empty($namespace)) throw new Exception("Missing param namespace");
 			echo UI::h('h3', [], $namespace);
+			echo UI::h('p', [], [
+				UI::h('a', [
+					'href' => Router::getRoute('Storage_AclStruct')->getLink('', [ 'namespace' => $namespace ]),
+					'class' => "btn btn-md btn-link",
+				], "<i class=\"glyphicon glyphicon-arrow-left\"></i> Wróć do struktury"),
+			]);
+
+			if ('reinstall' !== V::get('_postTask', '', $_POST)) {
+				echo UI::hButtonPost("Reinstall", [
+					'data' => [
+						'_postTask' => 'reinstall'
+					],
+					'class' => 'btn btn-md btn-danger',
+					'title' => "Reinstall structure"
+				]);
+				echo '<hr>';
+				try {
+					$this->printReinstallPreview($namespace);
+				} catch (Exception $e) {
+					DBG::log($e);
+					UI::alert('danger', $e->getMessage());
+				}
+				return;
+			}
 
 			Lib::loadClass('Schema_SystemObjectFieldStorageAcl');
 			$objFieldAcl = new Schema_SystemObjectFieldStorageAcl();
@@ -61,4 +85,62 @@ class Route_Storage_AclReinstall extends RouteBase {
 		UI::dol();
 	}
 
+	public function printReinstallPreview($namespace) {
+		$objectItem = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => "*,field" ]);
+		DBG::log($objectItem, 'array', '$objectItem preview');
+
+		switch ($objectItem['_type']) {
+			case 'AntAcl': $this->printReinstallAntAclPreview($objectItem); break;
+			case 'TableAcl': $this->printReinstallTableAclPreview($objectItem); break;
+			default: throw new Exception("TODO: Not Implemented type '{$objectItem['_type']}'");
+		}
+	}
+	public function printReinstallAntAclPreview($item) {
+		$antAclPath = APP_PATH_SCHEMA . DS . 'ant-object' . DS . str_replace(['__x3A__', ':'], ['.', '/'], $item['typeName']);
+		if (!file_exists("{$antAclPath}/build.xml")) throw new Exception("Ant build file not exists");
+
+		Lib::loadClass('XML');
+		$xsdType = XML::getXsdTypeFromXsdSchema("{$antAclPath}/{$item['name']}.xsd", $namespace = $item['namespace'], $name = $item['name']);
+		DBG::nicePrint($xsdType, '$xsdType');
+		if (empty($xsdType['struct'])) throw new Exception("Field list not found for '{$item['namespace']}'");
+		foreach ($xsdType['struct'] as $fieldName => $x) {
+			$listEnum = [];
+			if (!empty($x['restrictions']['enumeration'])) {
+				$listEnum = $x['restrictions']['enumeration'];
+				unset($x['restrictions']['enumeration']);
+			}
+			// DB::getPDO()->insertOrUpdate($this->_rootTableName, [
+			// 	'namespace' => "{$item['namespace']}/{$fieldName}",
+			// 	'objectNamespace' => $item['namespace'],
+			// 	'idDatabase' => $item['idDatabase'],
+			// 	'_rootTableName' => $item['_rootTableName'],
+			// 	'fieldNamespace' => $fieldName,
+			// 	'xsdType' => $x['type'],
+			// 	'xsdRestrictions' => json_encode($x['restrictions']),
+			// 	'appInfo' => json_encode($x['appInfo']),
+			// 	'minOccurs' => $x['minOccurs'],
+			// 	'maxOccurs' => $x['maxOccurs'],
+			// 	'isActive' => 1
+			// ]);
+			if (!empty($listEnum)) {
+				DBG::nicePrint($listEnum, "\$listEnum for field '{$fieldName}'");
+				foreach ($listEnum as $value => $label) {
+					// DB::getPDO()->insertOrUpdate("{$this->_rootTableName}_enum", [
+					// 	'namespace' => "{$item['namespace']}/{$fieldName}/@{$value}",
+					// 	'fieldNamespace' => $fieldName,
+					// 	'objectNamespace' => $item['namespace'],
+					// 	'value' => $value,
+					// 	'label' => $label,
+					// 	'isActive' => 1
+					// ]);
+				}
+			}
+		}
+		throw new Exception("TODO: printReinstallAntAclPreview...");
+	}
+	public function printReinstallTableAclPreview($item) {
+		throw new Exception("TODO: printReinstallTableAclPreview...");
+
+	}
+
 }

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

@@ -124,50 +124,7 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 		if (!file_exists("{$antAclPath}/build.xml")) throw new Exception("Ant build file not exists");
 
 		Lib::loadClass('XML');
-		$schema = XML::readXmlFileToArray("{$antAclPath}/{$item['name']}.xsd");
-		if (empty($schema)) throw new Exception("Missing schema file for '{$item['namespace']}'");
-		$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 (!XML::isXsdTag($n[0], 'element')) 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 (!XML::isXsdTag($n[0], 'complexType')) continue;
-			if ($xsdType['name'] != V::get('name', '', $n[1])) continue;
-			DBG::nicePrint($n, 'TODO: parse complexType');
-			// complexType/sequence/element
-			// complexType/complexContent/extension[base=...]/sequence/element
-			switch ($n[2][0][0]) {
-				case 'xs:sequence':
-				case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $n[2][0]); break;
-				case 'xs:complexContent':
-				case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $n[2][0]); break;
-				case 'xs:annotation':
-				case 'xsd:annotation': {
-					switch ($n[2][1][0]) {
-						case 'xs:sequence':
-						case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $n[2][1]); break;
-						case 'xs:complexContent':
-						case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $n[2][1]); break;
-					}
-				} break;
-			}
-			// if ($n[2][0][0] != 'xsd:complexContent') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent'");
-		}
-
+		$xsdType = XML::getXsdTypeFromXsdSchema("{$antAclPath}/{$item['name']}.xsd", $namespace = $item['namespace'], $name = $item['name']);
 		DBG::nicePrint($xsdType, '$xsdType');
 		if (empty($xsdType['struct'])) throw new Exception("Field list not found for '{$item['namespace']}'");
 		foreach ($xsdType['struct'] as $fieldName => $x) {

+ 47 - 1
SE/se-lib/XML.php

@@ -244,7 +244,7 @@ class XML {
 			foreach ($nodeArray[2] as $c) {
 				switch (XML::getTagName($c[0])) {
 					case 'annotation': { // skip xsd:element/xsd:annotation
-						DBG::nicePrint($c, "TODO: xsd:annotation/xsd:appinfo '{$fieldName}'");
+						DBG::log($c, 'array', "xsd:annotation/xsd:appinfo '{$fieldName}'");
 						// <xsd:annotation>
 						//		<xsd:appinfo>
 						//			 <system_cache__appinfo:flat_relation_cache>
@@ -385,4 +385,50 @@ class XML {
 		return $fields;
 	}
 
+	public static function getXsdTypeFromXsdSchema($xsdFilePath, $namespace, $name) {
+		$schema = XML::readXmlFileToArray($xsdFilePath);
+		if (empty($schema)) throw new Exception("Missing schema file for '{$namespace}'");
+		$xsdType = [ // find xsd:element with @name = $name
+			'nsPrefix' => null,
+			'name' => null,
+			'nsUri' => null,
+			'targetNsUri' => V::get('targetNamespace', '', $schema[1])
+		];
+		if (!$xsdType['targetNsUri']) throw new Exception("Missing schema target namespace declaration '{$name}'");
+		foreach ($schema[2] as $n) {
+			if (!XML::isXsdTag($n[0], 'element')) continue;
+			if ($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 = '{$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 = '{$name}'");
+		if ($xsdType['nsUri'] != $xsdType['targetNsUri']) throw new Exception("TODO: type ns is not the same as targetNamespace '{$name}'");// TODO
+
+		foreach ($schema[2] as $n) {
+			if (!XML::isXsdTag($n[0], 'complexType')) continue;
+			if ($xsdType['name'] != V::get('name', '', $n[1])) continue;
+			// complexType/sequence/element
+			// complexType/complexContent/extension[base=...]/sequence/element
+			switch ($n[2][0][0]) {
+				case 'xs:sequence':
+				case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $n[2][0]); break;
+				case 'xs:complexContent':
+				case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $n[2][0]); break;
+				case 'xs:annotation':
+				case 'xsd:annotation': {
+					switch ($n[2][1][0]) {
+						case 'xs:sequence':
+						case 'xsd:sequence': $xsdType['struct'] = XML::findFieldsFromSequence($schema, $n[2][1]); break;
+						case 'xs:complexContent':
+						case 'xsd:complexContent': $xsdType['struct'] = XML::findFieldsFromComplexContent($schema, $n[2][1]); break;
+					}
+				} break;
+			}
+			// if ($n[2][0][0] != 'xsd:complexContent') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent'");
+		}
+		return $xsdType;
+	}
+
 }