/** * @param $itemtype * @param $items_id * @param $main_items_id * @param $main_itemtype * @param $entities_id * @param $IP **/ function createNetworkNameFromItem($itemtype, $items_id, $main_items_id, $main_itemtype, $entities_id, $IP) { global $migration; // Using gethostbyaddr() allows us to define its reald internet name according to its IP. // But each gethostbyaddr() may reach several milliseconds. With very large number of // Networkports or NetworkeEquipment, the migration may take several minutes or hours ... //$computerName = gethostbyaddr($IP); $computerName = $IP; if ($computerName != $IP) { $position = strpos($computerName, "."); $name = substr($computerName, 0, $position); $domain = substr($computerName, $position + 1); $query = "SELECT `id`\n FROM `glpi_fqdns`\n WHERE `fqdn` = '{$domain}'"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $data = $DB->fetch_assoc($result); $domainID = $data['id']; } } else { $name = "migration-" . str_replace('.', '-', $computerName); $domainID = 0; } $IPaddress = new IPAddress(); if ($IPaddress->setAddressFromString($IP)) { $input = array('name' => $name, 'fqdns_id' => $domainID, 'entities_id' => $entities_id, 'items_id' => $items_id, 'itemtype' => $itemtype); $networknames_id = $migration->insertInTable('glpi_networknames', $input); $input = $IPaddress->setArrayFromAddress(array('entities_id' => $entities_id, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id), "version", "name", "binary"); $migration->insertInTable($IPaddress->getTable(), $input); } else { // Don't add the NetworkName if the address is not valid addNetworkPortMigrationError($items_id, 'invalid_address'); logNetworkPortError('invalid IP address', $items_id, $main_itemtype, $main_items_id, "{$IP}"); } unset($IPaddress); }