Sfoglia il codice sorgente

updated diff for AntAcl structure

Piotr Labudda 8 anni fa
parent
commit
54b2b572a1
1 ha cambiato i file con 50 aggiunte e 27 eliminazioni
  1. 50 27
      SE/se-lib/Route/Storage/AclReinstall.php

+ 50 - 27
SE/se-lib/Route/Storage/AclReinstall.php

@@ -109,38 +109,61 @@ class Route_Storage_AclReinstall extends RouteBase {
 				$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
-					// ]);
-				}
+				DBG::log($listEnum, 'array', "\$listEnum for field '{$fieldName}'");
 			}
 		}
-		throw new Exception("TODO: printReinstallAntAclPreview...");
+
+		$old = [
+			'fields' => array_map(function ($field) { return $field['fieldNamespace']; }, $item['field']),
+		];
+		$new = [
+			'fields' => array_keys($xsdType['struct']),
+		];
+
+		sort($old['fields']);
+		sort($new['fields']);
+		$diffFieldsToCreate = array_diff($new['fields'], $old['fields']);
+		$diffFieldsToRemove = array_diff($old['fields'], $new['fields']);
+		$sameFields = array_intersect($new['fields'], $old['fields']);
+		echo (!empty($diffFieldsToCreate))
+		?	UI::h('details', [], [
+				UI::h('summary', [], "Pola do dodania (".count($diffFieldsToCreate).")"),
+				UI::h('ul', [], array_map(function ($fieldName) {
+					return UI::h('li', [], $fieldName);
+				}, $diffFieldsToCreate)),
+			])
+		:	UI::h('p', [ 'style' => "font-style:italic" ], "Brak pól do dodania");
+		echo (!empty($diffFieldsToRemove))
+		?	UI::h('details', [], [
+				UI::h('summary', [], "Pola do usunięcia (".count($diffFieldsToRemove).")"),
+				UI::h('ul', [], array_map(function ($fieldName) {
+					return UI::h('li', [], $fieldName);
+				}, $diffFieldsToRemove)),
+			])
+		:	UI::h('p', [ 'style' => "font-style:italic" ], "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'] ); });
+			$oldField = ($oldField) ? reset($oldField) : null;
+			// DBG::nicePrint($oldField, "\$oldField '$fieldName'");
+			$newField = $xsdType['struct'][$fieldName];
+			// DBG::nicePrint($newField, "\$newField '$fieldName'");
+			$fieldDiff = [];
+			if ($newField['type'] !== $oldField['xsdType']) $fieldDiff[] = 'xsdType';
+			if ($newField['minOccurs'] != $oldField['minOccurs']) $fieldDiff[] = 'minOccurs';
+			if ($newField['maxOccurs'] != $oldField['maxOccurs']) $fieldDiff[] = 'maxOccurs';
+			if (json_encode($newField['restrictions']) !== $oldField['xsdRestrictions']) $fieldDiff[] = 'xsdRestrictions';
+			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");
+		}
+
+		throw new Exception("TODO: Podgląd zmian dla AntAcl {$item['namespace']} ...");
 	}
 	public function printReinstallTableAclPreview($item) {
-		throw new Exception("TODO: printReinstallTableAclPreview...");
-
+		throw new Exception("TODO: Podgląd zmian dla tabeli {$item['namespace']} ...");
 	}
 
 }