mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°4047 - Fix undefined offset in core\dbobject.class.php - rewrite duplicate check
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user