From 9999b05a8c8284d71857f296be4ff4b3b552f124 Mon Sep 17 00:00:00 2001 From: Romain B <8530352+Rom1-B@users.noreply.github.com> Date: Mon, 10 Jun 2024 10:11:16 +0200 Subject: [PATCH] fix(replace): error with infocom (#106) --- inc/replace.class.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/inc/replace.class.php b/inc/replace.class.php index 0b237f6..c060282 100644 --- a/inc/replace.class.php +++ b/inc/replace.class.php @@ -251,15 +251,19 @@ public static function replace($type, $model_id, $tab_ids, $location) } } - // Update current Infocoms of old item - if ($infocom->getFromDBforDevice($type, $olditem_id)) { - $infocom->update( - ['id' => $infocom->getID(), - 'itemtype' => $type, - 'items_id' => $newitem_id - ], - false - ); + // Checks that the itemtype/items_id key doesn't already exist to avoid duplication + if (!$infocom->getFromDBforDevice($type, $newitem_id)) { + // Update current Infocoms of old item + if ($infocom->getFromDBforDevice($type, $olditem_id)) { + $infocom->update( + [ + 'id' => $infocom->getID(), + 'itemtype' => $type, + 'items_id' => $newitem_id + ], + false + ); + } } } @@ -932,8 +936,7 @@ public static function getAssociatedContracts(CommonDBTM $item) 'WHERE' => [ 'glpi_contracts_items.items_id' => $item->getField('id'), 'glpi_contracts_items.itemtype' => $item->getType(), - getEntitiesRestrictCriteria('glpi_contracts', '', '', true) - ] + ] + getEntitiesRestrictCriteria('glpi_contracts', '', '', true) ]; $it = $DB->request($criteria); foreach ($it as $data) { @@ -974,8 +977,7 @@ public static function getAssociatedTickets($itemtype, $items_id) 'WHERE' => [ 'itemtype' => $itemtype, 'items_id' => $items_id, - getEntitiesRestrictCriteria('glpi_tickets') - ] + ] + getEntitiesRestrictCriteria('glpi_tickets') ]); foreach ($it as $data) { $tickets[] = $data;