Obsolescence: fixed the case when an external field points to an external key that is obsoletable (or archivable), causing an error during the setup (view could not be created)

SVN:trunk[4776]
This commit is contained in:
Romain Quetiez
2017-06-29 15:17:17 +00:00
parent 7cbdfaa5d4
commit cbf2919dcd

View File

@@ -1953,7 +1953,7 @@ abstract class MetaModel
{
// Create the friendly name attribute
$sFriendlyNameAttCode = $sAttCode.'_friendlyname';
$oFriendlyName = new AttributeExternalField($sFriendlyNameAttCode, array('magic' => true, 'allowed_values'=>null, 'extkey_attcode'=>$sAttCode, "target_attcode"=>'friendlyname', 'depends_on'=>array()));
$oFriendlyName = new AttributeExternalField($sFriendlyNameAttCode, array('allowed_values'=>null, 'extkey_attcode'=>$sAttCode, "target_attcode"=>'friendlyname', 'depends_on'=>array()));
self::AddMagicAttribute($oFriendlyName, $sClass, self::$m_aAttribOrigins[$sClass][$sAttCode]);
if (self::HasChildrenClasses($sRemoteClass))
@@ -1996,21 +1996,42 @@ abstract class MetaModel
}
}
// Get the real external key attribute
// It will be our reference to determine the other ext fields related to the same ext key
$oFinalKeyAttDef = $oAttDef->GetKeyAttDef(EXTKEY_ABSOLUTE);
if (self::IsArchivable($sRemoteClass))
{
$sArchiveRemote = $sAttCode.'_archive_flag';
$oArchiveRemote = new AttributeExternalField($sArchiveRemote, array("allowed_values"=>null, "extkey_attcode"=>$sAttCode, "target_attcode"=>'archive_flag', "depends_on"=>array()));
self::AddMagicAttribute($oArchiveRemote, $sClass, self::$m_aAttribOrigins[$sClass][$sAttCode]);
$sCode = $sAttCode.'_archive_flag';
if ($oAttDef->IsExternalField())
{
// This is a key, but the value comes from elsewhere
// Create an external field pointing to the remote attribute
$sKeyAttCode = $oAttDef->GetKeyAttCode();
$sRemoteAttCode = $oAttDef->GetExtAttCode().'_archive_flag';
}
else
{
$sKeyAttCode = $sAttCode;
$sRemoteAttCode = 'archive_flag';
}
$oMagic = new AttributeExternalField($sCode, array("allowed_values"=>null, "extkey_attcode"=>$sKeyAttCode, "target_attcode"=>$sRemoteAttCode, "depends_on"=>array()));
self::AddMagicAttribute($oMagic, $sClass, self::$m_aAttribOrigins[$sClass][$sKeyAttCode]);
}
if (self::IsObsoletable($sRemoteClass))
{
$sObsoleteRemote = $sAttCode.'_obsolescence_flag';
$oObsoleteRemote = new AttributeExternalField($sObsoleteRemote, array("allowed_values"=>null, "extkey_attcode"=>$sAttCode, "target_attcode"=>'obsolescence_flag', "depends_on"=>array()));
self::AddMagicAttribute($oObsoleteRemote, $sClass, self::$m_aAttribOrigins[$sClass][$sAttCode]);
$sCode = $sAttCode.'_obsolescence_flag';
if ($oAttDef->IsExternalField())
{
// This is a key, but the value comes from elsewhere
// Create an external field pointing to the remote attribute
$sKeyAttCode = $oAttDef->GetKeyAttCode();
$sRemoteAttCode = $oAttDef->GetExtAttCode().'_obsolescence_flag';
}
else
{
$sKeyAttCode = $sAttCode;
$sRemoteAttCode = 'obsolescence_flag';
}
$oMagic = new AttributeExternalField($sCode, array("allowed_values"=>null, "extkey_attcode"=>$sKeyAttCode, "target_attcode"=>$sRemoteAttCode, "depends_on"=>array()));
self::AddMagicAttribute($oMagic, $sClass, self::$m_aAttribOrigins[$sClass][$sKeyAttCode]);
}
}
if ($oAttDef instanceof AttributeMetaEnum)