|
|
@@ -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}
|