فهرست منبع

added fix in Storage for objects AntAcl which struct if is not installed

Piotr Labudda 8 سال پیش
والد
کامیت
c8cba9e3c1
2فایلهای تغییر یافته به همراه70 افزوده شده و 1 حذف شده
  1. 1 1
      SE/se-lib/Route/Storage.php
  2. 69 0
      SE/se-lib/Schema/SystemObjectStorageAcl.php

+ 1 - 1
SE/se-lib/Route/Storage.php

@@ -986,7 +986,7 @@ class Route_Storage extends RouteBase {
 		if (empty($namespace)) throw new Exception("Missing param namespace");
 		$item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
 		if (empty($item)) throw new HttpException("Namespace not found", 404);
-		DBG::log($item, 'array', "TODO: activateObjectAjax \$item");
+		DBG::log($item, 'array', "activateObjectAjax \$item");
 		if ($item['isObjectActive']) throw new AlertSuccessException("Namespace '{$namespace}' already active");
 		if (!$item['hasStruct']) throw new Exception("Missing struct for namespace '{$namespace}'");
 		if (!$item['isStructInstalled']) throw new Exception("Namespace struct not installed '{$namespace}'");

+ 69 - 0
SE/se-lib/Schema/SystemObjectStorageAcl.php

@@ -231,6 +231,75 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 			}
 		}
 
+		// Fix objects AntAcl which struct is not installed
+		$listAntAclObjectsToFix = DB::getPDO()->fetchAll("
+			select t.*
+			from `CRM_#CACHE_ACL_OBJECT` t
+			where t._type = 'AntAcl'
+				and t.idZasob is not NULL
+				and t.hasStruct = 1
+				and t.isStructInstalled = 0
+		");
+		if (!empty($listAntAclObjectsToFix)) {
+			UI::alert('info', "Fix AntAcl objects which is not installed (total: ".count($listAntAclObjectsToFix).")");
+			foreach ($listAntAclObjectsToFix as $antAclInfo) {
+				$namespace = $antAclInfo['namespace'];
+				DBG::nicePrint($antAclInfo, "\$antAclInfo ({$namespace})");
+				$zasobyStruct = DB::getPDO()->fetchAll("
+					select z.ID, z.`DESC`
+					from `CRM_LISTA_ZASOBOW` z
+					where z.PARENT_ID = :parent_id
+						and z.`TYPE` = 'KOMORKA'
+				", [ ':parent_id' => $antAclInfo['idZasob'] ]);
+				DBG::nicePrint($zasobyStruct, "\$zasobyStruct ({$namespace})");
+
+				ob_start();
+				Lib::loadClass('Schema_SystemObjectFieldStorageAcl');
+				$objFieldAcl = new Schema_SystemObjectFieldStorageAcl();
+				$objFieldAcl->updateCache($namespace);
+				$reinstallLog = ob_get_clean();
+				// DBG::nicePrint($reinstallLog, "\$reinstallLog ({$namespace})");
+
+				$fieldCacheStruct = DB::getPDO()->fetchAll("
+					select t.namespace, t.fieldNamespace
+					from `CRM_#CACHE_ACL_OBJECT_FIELD` t
+					where t.objectNamespace = :namespace
+						and t.idZasob is NULL
+				", [ ':namespace' => $namespace ]);
+				DBG::nicePrint($fieldCacheStruct, "\$fieldCacheStruct ({$namespace})");
+
+				$fieldsToFix = [];
+				foreach ($fieldCacheStruct as $cacheField) {
+					$fieldName = $cacheField['fieldNamespace'];
+					foreach ($zasobyStruct as $fieldZasob) {
+						if ($fieldZasob['DESC'] === $fieldName) {
+							$fieldsToFix[] = [
+								'idZasob' => $fieldZasob['ID'],
+								'namespace' => $cacheField['namespace'],
+							];
+						}
+					}
+				}
+				DBG::nicePrint($fieldsToFix, "\$fieldsToFix ({$namespace})");
+
+				foreach ($fieldsToFix as $fixField) {
+					$affected = SchemaFactory::loadDefaultObject('SystemObjectField')->updateItem([
+						'namespace' => $fixField['namespace'],
+						'idZasob' => $fixField['idZasob']
+					]);
+					if (!$affected) UI::alert('warning', "field ({$fixField['namespace']}) update idZasob failed");
+				}
+
+				$affected = SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
+					'namespace' => $namespace,
+					'isObjectActive' => 1
+				]);
+				($affected)
+				?	UI::alert('success', "object ({$namespace}) activated")
+				:	UI::alert('warning', "object ({$namespace}) activation failed");
+			}
+		}
+
 		// // foreach ... DB::getPDO($idDatabase)->fetchAll(select real _rootTableName)
 		// foreach (Core_AclHelper::getCustomAclList() as $typeName) {
 		//	 $ns = Core_AclHelper::parseTypeName($typeName);