diff --git a/src/Server.php b/src/Server.php index f8bb646..cf41231 100644 --- a/src/Server.php +++ b/src/Server.php @@ -1122,7 +1122,7 @@ class Server extends CommonDBTM $locationName = self::getCachedLocationName($assetLocationId, $cacheLocation); $stateName = self::getCachedName('State', (int) ($assetRow['states_id'] ?? 0), $cacheState); $userName = self::getCachedName('User', (int) ($assetRow['users_id'] ?? 0), $cacheUser); - $groupName = self::getCachedName('Group', (int) ($assetRow['groups_id'] ?? 0), $cacheGroup); + $groupName = self::getAssetGroupName($itemtype, $assetId, $cacheGroup); $ip = self::getAssetIp($itemtype, $assetId); @@ -1209,6 +1209,30 @@ class Server extends CommonDBTM return $cache[$id]; } + private static function getAssetGroupName(string $itemtype, int $items_id, array &$cache): string + { + global $DB; + + $iterator = $DB->request([ + 'FROM' => 'glpi_groups_items', + 'WHERE' => [ + 'itemtype' => $itemtype, + 'items_id' => $items_id, + 'type' => \Group_Item::GROUP_TYPE_NORMAL, + ], + 'LIMIT' => 1, + ]); + + foreach ($iterator as $row) { + $groupId = (int) ($row['groups_id'] ?? 0); + if ($groupId > 0) { + return self::getCachedName('Group', $groupId, $cache); + } + } + + return ''; + } + private static function getCachedLocationName(int $id, array &$cache): string { if ($id <= 0) {