فهرست منبع

added support for primaryKey in xsd schema - Storage Reinstall

Piotr Labudda 8 سال پیش
والد
کامیت
f3c2ed1715
3فایلهای تغییر یافته به همراه28 افزوده شده و 6 حذف شده
  1. 12 5
      SE/se-lib/Route/Storage/AclReinstall.php
  2. 2 1
      SE/se-lib/Schema/SystemObjectFieldStorageAcl.php
  3. 14 0
      SE/se-lib/XML.php

+ 12 - 5
SE/se-lib/Route/Storage/AclReinstall.php

@@ -145,7 +145,16 @@ class Route_Storage_AclReinstall extends RouteBase {
 
 		Lib::loadClass('XML');
 		$xsdType = XML::getXsdTypeFromXsdSchema("{$antAclPath}/{$item['name']}.xsd", $namespace = $item['namespace'], $name = $item['name']);
+		DBG::nicePrint($item, '$item');
 		DBG::nicePrint($xsdType, '$xsdType');
+
+		echo '<hr>';
+		echo UI::h('h3', [], "Lista zmian:");
+
+		echo ($item['primaryKey'] != $xsdType['primaryKey'])
+		?	UI::h('p', [ 'style' => "" ], "@primaryKey - zmiana z '{$item['primaryKey']}' na '{$xsdType['primaryKey']}'")
+		:	UI::h('p', [ 'style' => "font-style:italic; color:silver" ], "@primaryKey - bez zmian");
+
 		if (empty($xsdType['struct'])) throw new Exception("Field list not found for '{$item['namespace']}'");
 		foreach ($xsdType['struct'] as $fieldName => $x) {
 			$listEnum = [];
@@ -177,7 +186,7 @@ class Route_Storage_AclReinstall extends RouteBase {
 					return UI::h('li', [], $fieldName);
 				}, $diffFieldsToCreate)),
 			])
-		:	UI::h('p', [ 'style' => "font-style:italic" ], "Brak pól do dodania");
+		:	UI::h('p', [ 'style' => "font-style:italic; color:silver" ], "Brak pól do dodania");
 		echo (!empty($diffFieldsToRemove))
 		?	UI::h('details', [ 'open' => "open", 'style' => "margin:4px 0; color:#8a6d3b; background-color:#fcf8e3; border:1px solid #faebcc;" ], [
 				UI::h('summary', [ 'style' => "padding:4px; outline:none; cursor:pointer" ], "Pola do usunięcia (".count($diffFieldsToRemove)."):"),
@@ -185,7 +194,7 @@ class Route_Storage_AclReinstall extends RouteBase {
 					return UI::h('li', [], $fieldName);
 				}, $diffFieldsToRemove)),
 			])
-		:	UI::h('p', [ 'style' => "font-style:italic" ], "Brak pól do usunięcia");
+		:	UI::h('p', [ 'style' => "font-style:italic; color:silver" ], "Brak pól do usunięcia");
 		foreach ($sameFields as $fieldName) {
 			// UI::alert('warning', "TODO: is field changed? '{$fieldName}'");
 			$oldField = array_filter($item['field'], function ($field) use ($fieldName) { return ( $fieldName === $field['fieldNamespace'] ); });
@@ -201,10 +210,8 @@ class Route_Storage_AclReinstall extends RouteBase {
 			if (json_encode($newField['appInfo']) !== $oldField['appInfo']) $fieldDiff[] = 'appInfo';
 			echo (!empty($fieldDiff))
 			?	UI::h('p', [ 'style' => "" ], "Pole '{$fieldName}' - zmiany: " . implode(", ", $fieldDiff))
-			:	UI::h('p', [ 'style' => "font-style:italic" ], "Pole '{$fieldName}' - bez zmian");
+			:	UI::h('p', [ 'style' => "font-style:italic; color:silver" ], "Pole '{$fieldName}' - bez zmian");
 		}
-
-		throw new Exception("TODO: Podgląd zmian dla AntAcl {$item['namespace']} ...");
 	}
 	public function printReinstallTableAclPreview($item) {
 		throw new Exception("TODO: Podgląd zmian dla tabeli {$item['namespace']} ...");

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

@@ -175,7 +175,8 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 		}
 		SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
 			'namespace' => $item['namespace'],
-			'isStructInstalled' => 1
+			'isStructInstalled' => 1,
+			'primaryKey' => $xsdType['primaryKey'],
 		]);
 		$zasobTableName = substr($item['objectNamespace'], strlen('default_db/'));
 		$zasobTableName = (false !== strpos($zasobTableName, '/'))

+ 14 - 0
SE/se-lib/XML.php

@@ -392,6 +392,7 @@ class XML {
 			'nsPrefix' => null,
 			'name' => null,
 			'nsUri' => null,
+			'primaryKey' => null,
 			'targetNsUri' => V::get('targetNamespace', '', $schema[1])
 		];
 		if (!$xsdType['targetNsUri']) throw new Exception("Missing schema target namespace declaration '{$name}'");
@@ -409,6 +410,10 @@ class XML {
 		foreach ($schema[2] as $n) {
 			if (!XML::isXsdTag($n[0], 'complexType')) continue;
 			if ($xsdType['name'] != V::get('name', '', $n[1])) continue;
+			DBG::log($n, 'array', "TODO: find system_cache__appinfo:primaryKey from complexType");
+			if (array_key_exists('system_cache__appinfo:primaryKey', $n[1])) {
+				$xsdType['primaryKey'] = V::get('system_cache__appinfo:primaryKey', '', $n[1]);
+			}
 			// complexType/sequence/element
 			// complexType/complexContent/extension[base=...]/sequence/element
 			switch ($n[2][0][0]) {
@@ -428,6 +433,15 @@ class XML {
 			}
 			// if ($n[2][0][0] != 'xsd:complexContent') throw new Exception("Error Parsing Schema - expected 'complexType/complexContent'");
 		}
+		if (empty($xsdType['primaryKey'])) {
+			foreach ($xsdType['struct'] as $fieldName => $field) {
+				if ('ID' === strtoupper($fieldName)) {
+					$xsdType['primaryKey'] = $fieldName;
+					break;
+				}
+			}
+		}
+		if (empty($xsdType['primaryKey'])) throw new Exception("Missing primaryKey for schema '{$namespace}'");
 		return $xsdType;
 	}