|
|
@@ -141,6 +141,7 @@ class Route_Storage_AclReinstall extends RouteBase {
|
|
|
switch ($objectItem['_type']) {
|
|
|
case 'AntAcl': $this->printReinstallAntAclPreview($objectItem); break;
|
|
|
case 'TableAcl': $this->printReinstallTableAclPreview($objectItem); break;
|
|
|
+ case 'StorageAcl': $this->printReinstallStorageAclPreview($objectItem); break;
|
|
|
default: throw new Exception("TODO: Not Implemented type '{$objectItem['_type']}'");
|
|
|
}
|
|
|
}
|
|
|
@@ -222,6 +223,81 @@ class Route_Storage_AclReinstall extends RouteBase {
|
|
|
public function printReinstallTableAclPreview($item) {
|
|
|
throw new Exception("TODO: Podgląd zmian dla tabeli {$item['namespace']} ...");
|
|
|
}
|
|
|
+ public function printReinstallStorageAclPreview($item) {
|
|
|
+ DBG::nicePrint($item, '$item');
|
|
|
+ $acl = SchemaFactory::loadDefaultObject($item['name']);
|
|
|
+ DBG::nicePrint($acl, '$acl');
|
|
|
+ $xsdType = [
|
|
|
+ 'primaryKey' => $acl->getPrimaryKeyField(),
|
|
|
+ 'struct' => $acl->getFieldsWithXsdTypes()
|
|
|
+ ];
|
|
|
+ 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 = [];
|
|
|
+ if (!empty($x['restrictions']['enumeration'])) {
|
|
|
+ $listEnum = $x['restrictions']['enumeration'];
|
|
|
+ unset($x['restrictions']['enumeration']);
|
|
|
+ }
|
|
|
+ if (!empty($listEnum)) {
|
|
|
+ DBG::log($listEnum, 'array', "\$listEnum for field '{$fieldName}'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $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', [ 'open' => "open" ], [
|
|
|
+ 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; 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)."):"),
|
|
|
+ UI::h('ul', [], array_map(function ($fieldName) {
|
|
|
+ return UI::h('li', [], $fieldName);
|
|
|
+ }, $diffFieldsToRemove)),
|
|
|
+ ])
|
|
|
+ : 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'] ); });
|
|
|
+ $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; color:silver" ], "Pole '{$fieldName}' - bez zmian");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public function viewXsdSourceAction() {
|
|
|
try {
|