N°4047 - Fix undefined offset in core\dbobject.class.php - rewrite duplicate check

This commit is contained in:
Eric Espie
2021-09-14 16:13:43 +02:00
parent 45dc79f5af
commit 4433cdb21b
3 changed files with 11 additions and 20 deletions

View File

@@ -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)) {

View File

@@ -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++) {

View File

@@ -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);