Parcourir la source

Merge branch 'master' of ssh://biuro.biall-net.pl:2222/plabudda/se

* 'master' of ssh://biuro.biall-net.pl:2222/plabudda/se:
  rm REF_PARAMS from ref table
a.binder il y a 7 ans
Parent
commit
1ab2d86da3
4 fichiers modifiés avec 67 ajouts et 27 suppressions
  1. 4 1
      SE/se-lib/AntAclBase.php
  2. 1 1
      SE/se-lib/Core/AclHelper.php
  3. 58 21
      SE/se-lib/RefConfig.php
  4. 4 4
      SE/se-lib/Route/Status.php

+ 4 - 1
SE/se-lib/AntAclBase.php

@@ -534,10 +534,13 @@ class AntAclBase extends Core_AclBase {
 		}, $fields);
 	}
 	public function _getField($fieldName) {
+		if (!$fieldName) throw new Exception("Empty field name! '{$this->_namespace}'");
+
 		foreach ($this->getFields() as $field) {
 			if ($fieldName === $field['fieldNamespace']) return $field;
 		}
-		throw new Exception("Field not found '{$this->_namespace}/{$fieldName}'");
+
+		throw new Exception("Field '{$fieldName}' not found '{$this->_namespace}/{$fieldName}'");
 	}
 
 	public function getSqlPrimaryKeyField() { return $this->_primaryKey; }

+ 1 - 1
SE/se-lib/Core/AclHelper.php

@@ -107,7 +107,7 @@ class Core_AclHelper {// Helper class for Acl
 					$acl = StorageAclBase::buildInstance($objItem['idZasob'], $objItem);
 					return $acl;
 				} break;
-				default: throw new Exception("Not Implemented acl type '{$objItem['_type']}'");
+				default: throw new Exception("Not Implemented acl type '{$objItem['_type']}' for namespace '{$namespace}'");
 			}
 		} catch (Exception $e) {
 			DBG::log($e);

+ 58 - 21
SE/se-lib/RefConfig.php

@@ -33,7 +33,7 @@ Lib::loadClass('SchemaVersionUpgrade');
 class RefConfig {
 
 	// $REF_TABLE_VERSION = 5; // TODO: add unique key to (PRIMARY_KEY, REMOTE_PRIMARY_KEY)
-	static $REF_TABLE_VERSION = 5;
+	static $REF_TABLE_VERSION = 6;
 	// $REF_TABLE_VERSION = 4; // added ref event log table - `CRM__#REF_LOG__*`
 
 	static function isActive($objectNamespace, $childTypeName) {
@@ -61,6 +61,32 @@ class RefConfig {
 		$cacheRefConfigs[$cacheKey] = $refConfig;
 		return $refConfig;
 	}
+	static function getRefConfigById($id) {
+		$refInfo = DB::getPDO()->fetchFirst("
+			select c.ID, c.A_STATUS, c.VERSION, c.SOURCE
+				, c.ROOT_OBJECT_NS
+				, c.CHILD_NAME
+			from `CRM_REF_CONFIG` c
+			where c.ID = :id
+		", [
+			':id' => $id,
+		]);
+		if (!$refInfo['ID']) throw new Exception("Ref table not found in ref config table (id '{$id}')");
+		$rootObjectNamespace = $refInfo['ROOT_OBJECT_NS'];
+		$childTypeName = $refInfo['CHILD_NAME'];
+		$rootAcl = ACL::getAclByNamespace($rootObjectNamespace);
+		if (!($rootAcl instanceof AntAclBase)) throw new Exception("Ref allowed only for AntAcl objects");
+		$fieldInfo = $rootAcl->_getField($childTypeName); // throws Exception if field not exists
+		$refConfig = Type_RefConfig::build($refInfo);
+		if ('WAITING' == $refConfig->status || $refConfig->version < self::$REF_TABLE_VERSION) {
+			$typeField = Type_Field::build($fieldInfo);
+			self::update($rootObjectNamespace, $childTypeName, $typeField, $refConfig);
+			$refConfig = self::fetch($rootObjectNamespace, $childTypeName, $childNamespace);
+		}
+
+		$cacheRefConfigs[$cacheKey] = $refConfig;
+		return $refConfig;
+	}
 
 	/** static function fetch(Type_Namespace $rootObjectNamespace, Type_TypeName $childName, Type_Namespace $childNamespace = null): Type_RefConfig */
 	static function fetch($rootObjectNamespace, $childName, $childNamespace = null) { // @returns Type_RefConfig
@@ -212,7 +238,8 @@ class RefConfig {
 			// 'VERSION' => self::$REF_TABLE_VERSION
 		]);
 		self::upgradeRefTableFrom1to2($refConfig);
-		self::upgradeRefTableFrom4to5($refConfig);
+		// self::upgradeRefTableFrom4to5($refConfig);
+		// self::upgradeRefTableFrom5to6($refConfig);
 	}
 	static function upgradeRefTableFrom1to2(Type_RefConfig $refConfig) { // TODO: rm ACL::upgradeRefConfigFrom1to2
 		if (1 == $refConfig->version) {
@@ -227,23 +254,35 @@ class RefConfig {
 				'VERSION' => 2
 			]);
 		}
-		// TODO: return array_merge($refConfig, [ 'VERSION' => 2 ]);
-	}
-	static function upgradeRefTableFrom4to5(Type_RefConfig $refConfig) { // TODO: rm ACL::upgradeRefConfigFrom1to2
-		if ($refConfig->version < 5) {
-			if ('table' === $refConfig->source && 'NORMAL' == $refConfig->status) {
-				try {
-					DB::getPDO()->execSql(" ALTER TABLE `{$refConfig->tableName}` ADD `REF_PARAMS` varchar(1024) DEFAULT '' ");
-				} catch (Exception $e) {
-					DBG::log($e);
-				}
-			}
-			$affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
-				'VERSION' => 5
-			]);
-		}
-		// TODO: return array_merge($refConfig, [ 'VERSION' => 2 ]);
 	}
+	// static function upgradeRefTableFrom4to5(Type_RefConfig $refConfig) { // TODO: rm ACL::upgradeRefConfigFrom1to2
+	// 	if ($refConfig->version < 5) {
+	// 		if ('table' === $refConfig->source && 'NORMAL' == $refConfig->status) {
+	// 			try {
+	// 				DB::getPDO()->execSql(" ALTER TABLE `{$refConfig->tableName}` ADD `REF_PARAMS` varchar(1024) DEFAULT '' ");
+	// 			} catch (Exception $e) {
+	// 				DBG::log($e);
+	// 			}
+	// 		}
+	// 		$affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
+	// 			'VERSION' => 5
+	// 		]);
+	// 	}
+	// }
+	// static function upgradeRefTableFrom5to6(Type_RefConfig $refConfig) { // TODO: rm ACL::upgradeRefConfigFrom1to2
+	// 	if ($refConfig->version < 6) {
+	// 		if ('table' === $refConfig->source && 'NORMAL' == $refConfig->status) {
+	// 			try {
+	// 				DB::getPDO()->execSql(" ALTER TABLE `{$refConfig->tableName}` DROP COLUMN `REF_PARAMS` ");
+	// 			} catch (Exception $e) {
+	// 				DBG::log($e);
+	// 			}
+	// 		}
+	// 	}
+	// 	$affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
+	// 		'VERSION' => 6
+	// 	]);
+	// }
 
 	static function installRefTable($objectNamespace, $childTypeName, Type_Field $newField, Type_RefConfig $refConfig = null) {
 		if (!$refConfig) $refConfig = self::fetch($objectNamespace, $childTypeName);
@@ -319,7 +358,6 @@ class RefConfig {
 					, backRef.A_STATUS as A_STATUS
 					, 0 as TRANSACTION_ID
 					, {$lastActionDateField} as A_LAST_ACTION_DATE
-					, backRef.REF_PARAMS as REF_PARAMS
 			from `{$backRefTable}` backRef
 		";
 		DBG::log($sql, 'sql', "generateRefSelectSqlByBackRef");
@@ -378,7 +416,7 @@ class RefConfig {
 				$appInfoRootFieldName = substr($appInfoXpath, strlen("{$childName}/"));
 				$appInfoChildFieldName = $appInfoName;
 			} else {
-				throw new Exception("TODO parse flat_relation_cache");
+				throw new Exception("TODO parse flat_relation_cache '{$rootObjectNamespace}' field '{$childName}'");
 			}
 		}
 		if (!$appInfoRootFieldName || !$appInfoChildFieldName) throw new Exception("Error Processing flat_relation_cache");
@@ -460,7 +498,6 @@ class RefConfig {
 					, 'WAITING' as A_STATUS
 					, 0 as TRANSACTION_ID
 					, {$lastActionDateField} as A_LAST_ACTION_DATE
-					, '' as REF_PARAMS
 					from `{$rootTableName}` root
 				join `{$childTableName}` child on(child.{$sqlChildFieldName} = root.{$appInfoChildFieldName})
 			where {$sqlWhereFromRestrictions}

+ 4 - 4
SE/se-lib/Route/Status.php

@@ -113,10 +113,10 @@ class Route_Status extends RouteBase {
 	public function viewStatusUsers() {
 		$nowMinus3Months = date("Y-m-d", mktime(0,0,0, date('m') - 1, date('d'), date('Y')));
 		$sesUsers = DB::getPDO()->fetchAll("
-		select c.ID, c.CONF_KEY, c.CONF_VAL
-		from CRM_CONFIG c
-		where c.CONF_KEY like 'acl_user_%_%_cache_update'
-		and c.CONF_VAL > '{$nowMinus3Months}'
+			select c.ID, c.CONF_KEY, c.CONF_VAL
+			from CRM_CONFIG c
+			where c.CONF_KEY like 'acl_user_%_%_cache_update'
+			and c.CONF_VAL > '{$nowMinus3Months}'
 		");
 		$sesUsers = array_reduce( $sesUsers, function ($ret, $record) {
 			// $format = "acl_user_{ID_USERS}_{ID_PROCES}_cache_update";