Explorar o código

fixed reinstall struct - remove not used ref config

Piotr Labudda %!s(int64=8) %!d(string=hai) anos
pai
achega
8c41bf8d42
Modificáronse 2 ficheiros con 57 adicións e 2 borrados
  1. 13 0
      SE/se-lib/ACL.php
  2. 44 2
      SE/se-lib/Route/Storage/AclReinstall.php

+ 13 - 0
SE/se-lib/ACL.php

@@ -478,6 +478,19 @@ class ACL {
 			':namespace' => $namespace,
 		]);
 	}
+	public static function getChildRefFullList($namespace) {
+		if (!$namespace) throw new Exception("Missing namespace");
+		return DB::getPDO()->fetchAll("
+			select c.CHILD_NAME as namespace
+				, c.A_STATUS
+				, c.ID
+			from CRM_REF_CONFIG c
+			where c.ROOT_OBJECT_NS = :namespace
+				and c.A_STATUS = 'NORMAL'
+		", [
+			':namespace' => $namespace,
+		]);
+	}
 
 	public static function fetchRefs($namespace, $childNamespace, $primaryKey, $params = []) { // TODO: $params: limit, total
 		if (!$namespace) throw new Exception("Missing namespace");

+ 44 - 2
SE/se-lib/Route/Storage/AclReinstall.php

@@ -40,8 +40,50 @@ class Route_Storage_AclReinstall extends RouteBase {
 					'table' => ACL::getInstanceTable($namespace),
 				], "dbg");
 
+				$item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
+
+				$childRefList = ACL::getChildRefFullList($namespace);
+				DBG::nicePrint($childRefList, '$childRefList');
+				DBG::nicePrint($item, '$item');
+				$activeFields = array_filter($item['field'], function ($field) {
+					return ($field['isActive'] > 0);
+				});
+				$fieldNsList = array_map(function ($field) {
+					return $field['fieldNamespace'];
+				}, $activeFields);
+				DBG::nicePrint($fieldNsList, '$fieldNsList');
+				if ('AntAcl' === $item['_type']) {
+					foreach ($childRefList as $childRef) { // [ namespace, A_STATUS ]
+						if ($childRef['A_STATUS'] !== 'DELETED' && !in_array($childRef['namespace'], $fieldNsList)) {
+							UI::alert('danger', "remove ref config for '{$childRef['namespace']}' ...");
+							if (!$childRef['ID']) throw new Exception("Missing ref config ID");
+							DB::getPDO()->update('CRM_REF_CONFIG', 'ID', $childRef['ID'], [
+								'A_STATUS' => 'DELETED',
+								'A_LAST_ACTION_DATE' => 'NOW()',
+							]);
+						}
+						else if ($childRef['A_STATUS'] !== 'DELETED' && in_array($childRef['namespace'], $fieldNsList)) {
+							UI::alert('info', "ref config for '{$childRef['namespace']}' active - OK");
+						}
+						else if ($childRef['A_STATUS'] === 'DELETED' && in_array($childRef['namespace'], $fieldNsList)) {
+							UI::alert('warning', "activate ref config for '{$childRef['namespace']}' ...");
+							if (!$childRef['ID']) throw new Exception("Missing ref config ID");
+							DB::getPDO()->update('CRM_REF_CONFIG', 'ID', $childRef['ID'], [
+								'A_STATUS' => 'NORMAL',
+								'A_LAST_ACTION_DATE' => 'NOW()',
+							]);
+						}
+						else if ($childRef['A_STATUS'] === 'DELETED' && !in_array($childRef['namespace'], $fieldNsList)) {
+							UI::alert('info', "ref config for '{$childRef['namespace']}' removed - OK");
+						}
+						else {
+							UI::alert('danger', "Not implemented action for '{$childRef['namespace']}'");
+						}
+					}
+					// TODO: create missing refConfig - field is not in $childRefList
+				}
+
 				{
-					$item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
 					if ('AntAcl' === $item['_type']) {
 						$dbName = DB::getPDO()->getDatabaseName();
 						$sqlFunBody = ACL::generateIsInstanceFunctionBody($namespace, $item);
@@ -136,7 +178,7 @@ class Route_Storage_AclReinstall extends RouteBase {
 			])
 		:	UI::h('p', [ 'style' => "font-style:italic" ], "Brak pól do dodania");
 		echo (!empty($diffFieldsToRemove))
-		?	UI::h('details', [ 'open' => "open", 'style' => "margin:4px 0; background-color:#ccc; border:1px solid #ddd" ], [
+		?	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);