Fixed bug #231: distinguish between external key (id) and external key (name) for loading fields that are external keys pointing to externla keys! Example: Connected To->Device is to be mapped to the Connected Interface's device NAME whereas Connected To->Device->id is to be mapped to the connected interface's device id

SVN:trunk[747]
This commit is contained in:
Denis Flaven
2010-09-02 15:57:08 +00:00
parent 66c7d99c46
commit b1f877f845
2 changed files with 25 additions and 6 deletions

View File

@@ -661,7 +661,14 @@ abstract class cmdbAbstractObject extends CMDBObject
{
$sExtKeyLabel = MetaModel::GetLabel($sClassName, $oAttDef->GetKeyAttCode());
$sRemoteAttLabel = MetaModel::GetLabel($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
$aHeader[] = $sExtKeyLabel.'->'.$sRemoteAttLabel;
$oTargetAttDef = MetaModel::GetAttributeDef($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
$sSuffix = '';
if ($oTargetAttDef->IsExternalKey())
{
$sSuffix = '->id';
}
$aHeader[] = $sExtKeyLabel.'->'.$sRemoteAttLabel.$sSuffix;
}
else
{

View File

@@ -70,10 +70,16 @@ function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef, $bA
{
if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode))
{
if ($bAdvanced || !$oTargetAttDef->IsExternalKey())
$bExtKey = $oTargetAttDef->IsExternalKey();
$sSuffix = '';
if ($bExtKey)
{
$sSuffix = '->id';
}
if ($bAdvanced || !$bExtKey)
{
// When not in advanced mode do not allow to use reconciliation keys (on external keys) if they are themselves external keys !
$aResult[$sAttCode.'->'.$sTargetAttCode] = $oExtKeyAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
$aResult[$sAttCode.'->'.$sTargetAttCode] = $oExtKeyAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel().$sSuffix;
}
}
}
@@ -124,12 +130,18 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo
{
if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode))
{
if ($bAdvancedMode || (!$oTargetAttDef->IsExternalKey()))
$bExtKey = $oTargetAttDef->IsExternalKey();
$sSuffix = '';
if ($bExtKey)
{
$sSuffix = '->id';
}
if ($bAdvancedMode || !$bExtKey)
{
// When not in advanced mode do not allow to use reconciliation keys (on external keys) if they are themselves external keys !
$aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
if ((strcasecmp($sFieldName, $aChoices[$sAttCode.'->'.$sTargetAttCode]) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode)) == 0) )
$aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel().$sSuffix;
if ((strcasecmp($sFieldName, $aChoices[$sAttCode.'->'.$sTargetAttCode]) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode.$sSuffix)) == 0) )
{
$sFieldCode = $sAttCode.'->'.$sTargetAttCode;
}