Parcourir la source

fixed updateCache in storage

Piotr Labudda il y a 7 ans
Parent
commit
ee872fa1cf
1 fichiers modifiés avec 38 ajouts et 19 suppressions
  1. 38 19
      SE/se-lib/Schema/SystemObjectStorageAcl.php

+ 38 - 19
SE/se-lib/Schema/SystemObjectStorageAcl.php

@@ -86,6 +86,22 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 			}
 		}
 
+		// Remove AntAcl with no struct (!hasStruct)
+		DB::getPDO()->execSql("
+			DELETE from `CRM_#CACHE_ACL_OBJECT`
+			where hasStruct = 0 and _type = 'AntAcl' and idZasob IS NULL
+		");
+		// TODO: Fix AntAcl without struct but added to Zasoby
+		$toRemoveInstalledAntAcl = DB::getPDO()->fetchAll("
+			select *
+			from `CRM_#CACHE_ACL_OBJECT`
+			where hasStruct = 0 and _type = 'AntAcl' and idZasob IS NOT NULL
+		");
+		DBG::nicePrint($toRemoveInstalledAntAcl, "to remove AntAcl added to Zasoby already but without xsd file");
+		foreach ($toRemoveInstalledAntAcl as $antAclToRmInfo) {
+			self::deleteObjectFromCache($antAclToRmInfo['idZasob'], $antAclToRmInfo['namespace']);
+		}
+
 		// Fix objects AntAcl which struct is not installed
 		$listAntAclObjectsToFix = DB::getPDO()->fetchAll("
 			select t.*
@@ -113,19 +129,14 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 				{
 					Lib::loadClass('Schema_SystemObjectFieldStorageAcl');
 
-					{ // check if build.xml file still eixsts
-						$item = [];
-						$exNs = explode('/', $namespace);
-						$item['name'] = array_pop($exNs);
-						$item['nsPrefix'] = implode('__x3A__', $exNs);
-						$item['typeName'] = implode('__x3A__', $exNs) . ':' . $item['name'];
-
-						$antAclPath = Schema_SystemObjectFieldStorageAcl::getAntAclXsdBasePath($item['typeName']);
+					{ // if build.xml file not exists then remove from Acl Cache (and Zasoby)
+						Lib::loadClass('Api_WfsNs');
+						$typeName = Api_WfsNs::toTypeName($namespace);
+						$antAclPath = Schema_SystemObjectFieldStorageAcl::getAntAclXsdBasePath($typeName);
 						if (!file_exists("{$antAclPath}/build.xml")) {
 							UI::alert('danger', "Ant build file not exists for namespace '{$antAclInfo['namespace']}' - Removing AntAcl");
-							Schema_SystemObjectStorageAcl::deleteObjectFromCache($antAclInfo['idZasob'], $antAclInfo['namespace']);
-
-							// throw new Exception("Ant build file not exists #TEST_OFF");
+							self::deleteObjectFromCache($antAclInfo['idZasob'], $antAclInfo['namespace']);
+							ob_get_clean();
 							continue;
 						}
 					}
@@ -135,11 +146,12 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 						$objFieldAcl->updateCache($namespace);
 					} catch (Exception $e) {
 						UI::alert('danger', $e->getMessage());
-						Schema_SystemObjectStorageAcl::deleteObjectFromCache($antAclInfo['idZasob'], $antAclInfo['namespace']);
+						self::deleteObjectFromCache($antAclInfo['idZasob'], $antAclInfo['namespace']);
+						ob_get_clean();
 						continue;
 					}
-					$reinstallLog = ob_get_clean();
 				}
+				$reinstallLog = ob_get_clean();
 				// DBG::nicePrint($reinstallLog, "\$reinstallLog ({$namespace})");
 
 				$fieldCacheStruct = DB::getPDO()->fetchAll("
@@ -221,7 +233,7 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 		}
 		DB::getPDO()->execSql("
 			insert into `{$this->_rootTableName}` (namespace, idZasob, idDatabase, description, hasStruct)
-			select concat('{$source['nsPrefix']}/', t.`DESC`)
+			select concat('default_objects/', t.`DESC`)
 				, t.ID as idZasob
 				, '{$idSource}' as idDatabase
 				, t.`OPIS` as description
@@ -257,26 +269,28 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 			from INFORMATION_SCHEMA.TABLES t
 			where t.TABLE_SCHEMA = '{$dbName}'
 				and t.TABLE_NAME not like '%#%'
+				and t.TABLE_NAME not like '%@%'
 			on duplicate key update _rootTableName = t.TABLE_NAME
 				, hasStruct = 1
 				, isStructInstalled = 1
 		");
+
+		// Insert to Cache from Zasoby
+		// NOTE: hasStruct cannot be set bc struct may not exists
 		DB::getPDO()->execSql("
-			insert into `{$this->_rootTableName}` (namespace, idZasob, idDatabase, description, hasStruct)
-			select IF(t.`DESC` like 'default_db/%',
+			insert into `{$this->_rootTableName}` (namespace, idZasob, idDatabase, description)
+			select IF(t.`DESC` like '{$source['nsPrefix']}/%',
 					t.`DESC`,
 					concat('{$source['nsPrefix']}/', t.`DESC`)
 				) as namespace
 				, t.ID as idZasob
 				, '{$source['idZasob']}' as idDatabase
 				, t.`OPIS` as description
-				, 1 as hasStruct
 			from CRM_LISTA_ZASOBOW t
 			where t.`TYPE` = 'TABELA'
 				and t.A_STATUS in('NORMAL', 'WAITING')
 				and t.PARENT_ID = {$source['idZasob']}
 			on duplicate key update idZasob = t.ID
-				, hasStruct = 1
 		");
 	}
 	function _updateAntObjectCache($buildXmlPath, $basePath) {
@@ -486,8 +500,13 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 		", [
 			':namespace' => $namespace,
 		]);
+		DB::getPDO()->insert('CRM_LISTA_ZASOBOW_HIST', [
+			'ID_USERS2' => $idZasob,
+			'A_STATUS' => "DELETED",
+			'A_RECORD_UPDATE_AUTHOR' => "update-acl-cache",
+			'A_RECORD_UPDATE_DATE' => "NOW()",
+		]);
 		DB::getPDO()->update('CRM_LISTA_ZASOBOW', 'ID', $idZasob, [
-			'PARENT_ID' => -1,
 			'A_STATUS' => "DELETED",
 			'A_RECORD_UPDATE_AUTHOR' => "update-acl-cache",
 			'A_RECORD_UPDATE_DATE' => "NOW()",