diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 373635d66..eeee0e3ab 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -2142,28 +2142,23 @@ abstract class DBObject implements iDisplay } if ($oAttDef->DuplicatesAllowed()) { - return true; + return; } + // To control duplicates go through all the entries and check if the remote has been seen /** @var \ormLinkSet $value */ - $aModifiedLnk = $value->ListModifiedLinks(); $sExtKeyToRemote = $oAttDef->GetExtKeyToRemote(); - $aExistingRemotesId = $value->GetColumnAsArray($sExtKeyToRemote, true); - $aExistingRemotesFriendlyName = $value->GetColumnAsArray($sExtKeyToRemote.'_friendlyname', true); + $aCurrentRemoteIds = []; $aDuplicatesFields = []; - foreach ($aModifiedLnk as $oModifiedLnk) { - $iModifiedLnkId = $oModifiedLnk->GetKey(); - $iModifiedLnkRemoteId = $oModifiedLnk->Get($sExtKeyToRemote); - $aExistingRemotesIdToCheck = array_filter($aExistingRemotesId, function ($iLnkKey) use ($iModifiedLnkId) { - return ($iLnkKey != $iModifiedLnkId); - }, ARRAY_FILTER_USE_KEY); - - if (!in_array($iModifiedLnkRemoteId, $aExistingRemotesIdToCheck, true)) { - continue; + $value->rewind(); + while ($oCurrentLnk = $value->current()) { + $iExtKeyToRemote = $oCurrentLnk->Get($sExtKeyToRemote); + if (isset($aCurrentRemoteIds[$iExtKeyToRemote])) { + $aDuplicatesFields[] = $oCurrentLnk->Get($sExtKeyToRemote.'_friendlyname'); + } else { + $aCurrentRemoteIds[$iExtKeyToRemote] = true; } - - $iLnkId = $oModifiedLnk->GetKey(); - $aDuplicatesFields[] = $aExistingRemotesFriendlyName[$iLnkId]; + $value->next(); } if (!empty($aDuplicatesFields)) { diff --git a/test/core/ormLinkSetTest.php b/test/core/ormLinkSetTest.php index cad1c02ea..ff4bf3f29 100644 --- a/test/core/ormLinkSetTest.php +++ b/test/core/ormLinkSetTest.php @@ -183,8 +183,6 @@ class ormLinkSetTest extends ItopDataTestCase */ public function testRemoveThenAdd() { - self::markTestSkipped('Throws a undefined offset PHP notice in core\dbobject.class.php:2151, to be fixed in N°4047'); - $oServer = $this->CreateServer(1); $aPersons = array(); for ($i = 0; $i < 3; $i++) { diff --git a/test/itop-tickets/itopTicketTest.php b/test/itop-tickets/itopTicketTest.php index 0bf766764..7990da693 100644 --- a/test/itop-tickets/itopTicketTest.php +++ b/test/itop-tickets/itopTicketTest.php @@ -111,8 +111,6 @@ class ItopTicketTest extends ItopDataTestCase */ public function testUpdateImpactedItems_Basic2() { - self::markTestSkipped('Throws a undefined offset PHP notice in core\dbobject.class.php:2151, to be fixed in N°4047'); - $oTicket = $this->CreateTicket(1); $oServer1 = $this->CreateServer(1); $oHypervisor1 = $this->CreateHypervisor(1, $oServer1);