From f26bcd812cabfe35bcd8f3697b99d545e9eea7a1 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Fri, 11 Sep 2015 12:03:22 +0000 Subject: [PATCH] Could not add more than one link between a given server and a given network device. This is a regression in 2.2.0 beta. This issue affect N-N links where duplicates are allowed. One single link is being affected in the standard datamodel. SVN:trunk[3745] --- core/attributedef.class.inc.php | 14 ++++++++++++-- core/dbobject.class.php | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index f1e47dd65..ef62d87b0 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -1135,8 +1135,18 @@ class AttributeLinkedSet extends AttributeDefinition return false; } - // Both values are Object sets - return $val1->HasSameContents($val2); + // Note: maintain this algorithm so as to make sure it is strictly equivalent to the one used within DBObject::DBWriteLinks() + $sExtKeyToMe = $this->GetExtKeyToMe(); + $sAdditionalKey = null; + if ($this->IsIndirect() && !$this->DuplicatesAllowed()) + { + $sAdditionalKey = $this->GetExtKeyToRemote(); + } + $oComparator = new DBObjectSetComparator($val1, $val2, array($sExtKeyToMe), $sAdditionalKey); + $aChanges = $oComparator->GetDifferences(); + + $bAreEquivalent = (count($aChanges['added']) == 0) && (count($aChanges['removed']) == 0) && (count($aChanges['modified']) == 0); + return $bAreEquivalent; } /** diff --git a/core/dbobject.class.php b/core/dbobject.class.php index b4889da34..24fc4bc1e 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -1366,9 +1366,10 @@ abstract class DBObject implements iDisplay if (!array_key_exists($sAttCode, $this->m_aTouchedAtt)) continue; if (array_key_exists($sAttCode, $this->m_aModifiedAtt) && ($this->m_aModifiedAtt[$sAttCode] == false)) continue; + // Note: any change to this algorithm must be reproduced into the implementation of AttributeLinkSet::Equals() $sExtKeyToMe = $oAttDef->GetExtKeyToMe(); $sAdditionalKey = null; - if ($oAttDef->IsIndirect()) + if ($oAttDef->IsIndirect() && !$oAttDef->DuplicatesAllowed()) { $sAdditionalKey = $oAttDef->GetExtKeyToRemote(); }