represent the internet name of an element. It is compose of the name itself, its domain and one or several IP addresses (IPv4 and/or IPv6). An address can be affected to an item, or can be "free" to be reuse by another item (for instance, in case of maintenance, when you change the network card of a computer, but not its network information)
Inheritance: extends FQDNLabel
 /**
  * @test
  */
 public function ImportNetworkEquipment()
 {
     global $DB;
     self::restore_database();
     // Load session rights
     $_SESSION['glpidefault_entity'] = 0;
     Session::initEntityProfiles(2);
     Session::changeProfile(4);
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $networkEquipment = new NetworkEquipment();
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $input = array('name' => 'switch', 'entities_id' => 0, 'item_type' => 'NetworkEquipment', 'sysdescr' => 'Cisco machin chose', 'locations_id' => 1, 'is_dynamic' => 1, 'serial' => 'XXS6BEF3', 'comment' => 'this is a comment', 'plugin_fusioninventory_configsecurities_id' => 1);
     $unmanageds_id = $pfUnmanaged->add($input);
     // * Add networkport
     $input = array();
     $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
     $input['items_id'] = $unmanageds_id;
     $input['instantiation_type'] = 'NetworkPortEthernet';
     $input['name'] = 'general';
     $input['mac'] = '00:00:00:43:ae:0f';
     $input['is_dynamic'] = 1;
     $networkports_id = $networkPort->add($input);
     $input = array();
     $input['items_id'] = $networkports_id;
     $input['itemtype'] = 'NetworkPort';
     $input['name'] = '';
     $input['is_dynamic'] = 1;
     $networknames_id = $networkName->add($input);
     $input = array();
     $input['entities_id'] = 0;
     $input['itemtype'] = 'NetworkName';
     $input['items_id'] = $networknames_id;
     $input['name'] = '192.168.20.1';
     $input['is_dynamic'] = 1;
     $iPAddress->add($input);
     $pfUnmanaged->import($unmanageds_id);
     $cnt = countElementsInTable("glpi_networkequipments");
     $this->assertEquals(1, $cnt, "May have network equipment added");
     $cnt = countElementsInTable("glpi_plugin_fusioninventory_unmanageds");
     $this->assertEquals(0, $cnt, "Unknown device may be deleted");
     $networkEquipment->getFromDB(1);
     $this->assertEquals('XXS6BEF3', $networkEquipment->fields['serial'], "Serial");
     $this->assertEquals('switch', $networkEquipment->fields['name'], "Name");
     $this->assertEquals(1, $networkEquipment->fields['is_dynamic'], "is_dynamic");
     $this->assertEquals(1, $networkEquipment->fields['locations_id'], "locations_id");
     $this->assertEquals('this is a comment', $networkEquipment->fields['comment'], "comment");
     $networkPort->getFromDB(1);
     $a_reference = array('name' => 'general', 'id' => '1', 'items_id' => '1', 'itemtype' => 'NetworkEquipment', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => '00:00:00:43:ae:0f', 'comment' => '', 'is_deleted' => '0', 'is_dynamic' => '1');
     $this->assertEquals($a_reference, $networkPort->fields, "Networkport");
     $networkName->getFromDB(1);
     $a_reference = array('id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkPort', 'comment' => NULL, 'fqdns_id' => '0', 'is_deleted' => '0', 'is_dynamic' => '1', 'name' => '');
     $this->assertEquals($a_reference, $networkName->fields, "Networkname");
     $iPAddress->getFromDB(1);
     $a_reference = array('name' => '192.168.20.1', 'id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkName', 'version' => '4', 'binary_0' => '0', 'binary_1' => '0', 'binary_2' => '65535', 'binary_3' => '3232240641', 'is_deleted' => '0', 'is_dynamic' => '1', 'mainitems_id' => '1', 'mainitemtype' => 'NetworkEquipment');
     $this->assertEquals($a_reference, $iPAddress->fields, "IPAddress");
 }
Ejemplo n.º 2
0
based on GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2014 by the INDEPNET Development Team.

-------------------------------------------------------------------------

LICENSE

This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkRight("internet", READ);
Html::header(NetworkName::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], 'config', 'commondropdown', 'NetworkName');
Search::show('NetworkName');
Html::footer();
 /**
  * @param $mac
  * @param $name
  * @param $computers_id
  * @param $instantiation_type
  * @param $inst_input
  * @param $ips
  * @param $check_name
  * @param $dohistory
  * @param $already_known_ports
  * @return ID
  */
 private static function updateNetworkPort($mac, $name, $computers_id, $instantiation_type, $inst_input, $ips, $check_name, $dohistory, $already_known_ports)
 {
     global $DB;
     $network_port = new NetworkPort();
     // Then, find or create the base NetworkPort
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networkports`\n                WHERE `itemtype` = 'Computer'\n                   AND `items_id` = '{$computers_id}'\n                   AND `mac` = '{$mac}'";
     // If there is virtual ports, then, filter by port's name
     if ($check_name) {
         $query .= " AND `name` = '{$name}'";
     }
     if (count($already_known_ports) > 0) {
         $query .= " AND `id` NOT IN (" . implode(',', $already_known_ports) . ")";
     }
     // We order by is_dynamic to be sure to get the static ones first !
     $query .= " ORDER BY `is_dynamic`, `id`";
     $ports = $DB->request($query);
     if ($ports->numrows() == 0) {
         $port_input = array('name' => $name, 'mac' => $mac, 'items_id' => $computers_id, 'itemtype' => 'Computer', '_no_history' => !$dohistory, 'instantiation_type' => $instantiation_type, '_create_children' => 1, 'is_dynamic' => 1, 'is_deleted' => 0);
         $networkports_id = $network_port->add($port_input, array(), $dohistory);
         if ($networkports_id === false) {
             return -1;
         }
         $inst_input['networkports_id'] = $networkports_id;
         $instantiation = $network_port->getInstantiation();
         $instantiation->update($inst_input);
         unset($instantiation);
     } else {
         $line = $ports->next();
         $networkports_id = $line['id'];
         $network_port->getFromDB($networkports_id);
         if (!$check_name && $network_port->fields['name'] != $name) {
             $port_input = array('id' => $network_port->getID(), 'name' => $name, 'is_dynamic' => 1);
             $network_port->update($port_input);
         }
         if ($network_port->fields['instantiation_type'] != $instantiation_type && $network_port->fields['is_dynamic'] == 1) {
             $network_port->switchInstantiationType($instantiation_type);
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation = $network_port->getInstantiation();
             $instantiation->add($inst_input);
             unset($instantiation);
         }
         if ($network_port->fields['instantiation_type'] == $instantiation_type) {
             $instantiation = $network_port->getInstantiation();
             $inst_input['id'] = $instantiation->getID();
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation->update($inst_input);
             unset($instantiation);
         }
     }
     if ($network_port->isNewItem()) {
         return -1;
     }
     $network_name = new NetworkName();
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networknames`\n                WHERE `itemtype` = 'NetworkPort'\n                   AND `items_id` = '{$networkports_id}'\n                ORDER BY `is_dynamic`";
     if (!$ips || count($ips) == 0) {
         foreach ($DB->request($query) as $line) {
             if ($line['is_dynamic']) {
                 $network_name->delete($line, true, $dohistory);
             }
         }
     } else {
         $names = $DB->request($query);
         if ($names->numrows() == 0) {
             $name_input = array('itemtype' => 'NetworkPort', 'items_id' => $networkports_id, 'is_dynamic' => 1, 'is_deleted' => 0, '_no_history' => !$dohistory, 'name' => 'OCS-INVENTORY-NG');
             $networknames_id = $network_name->add($name_input);
         } else {
             $line = $names->next();
             $networknames_id = $line['id'];
             foreach ($names as $line) {
                 if ($line['is_dynamic'] == 1 && $line['id'] != $networknames_id) {
                     $network_port->delete($line, true, $dohistory);
                 }
             }
         }
         $ip_address = new IPAddress();
         $already_known_addresses = array();
         $query = "SELECT `id`, `name`, `is_dynamic`, `mainitems_id`\n                   FROM `glpi_ipaddresses`\n                   WHERE `itemtype` = 'NetworkName'\n                     AND `items_id` = '{$networknames_id}'\n                   ORDER BY `is_dynamic`";
         foreach ($DB->request($query) as $line) {
             if (in_array($line['name'], $ips) && !empty($line['mainitems_id'])) {
                 $already_known_addresses[] = $line['id'];
                 $ips = array_diff($ips, array($line['name']));
             } elseif ($line['is_dynamic'] == 1) {
                 $ip_address->delete($line, true, $dohistory);
             }
         }
     }
     if ($ips) {
         foreach ($ips as $ip) {
             $ip_input = array('name' => $ip, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id, '_no_history' => !$dohistory, 'is_dynamic' => 1, 'is_deleted' => 0);
             $ip_address->add($ip_input);
         }
     }
     return $network_port->getID();
 }
 /**
  * Display detail networkport based on glpi core networkport and fusioninventory
  * networkport
  *
  * @param array $data with id ant fusionid
  * @param boolean $monitoring true if monitoring installed && actived
  * @param boolean $aggrega true if this port is aggregate port
  *
  * @return nothing
  */
 function showNetworkPortDetail($data, $monitoring, $aggrega = 0)
 {
     global $CFG_GLPI, $DB;
     $nw = new NetworkPort_NetworkPort();
     $networkName = new NetworkName();
     $networkPort = new NetworkPort();
     $pfNetworkPort = new PluginFusioninventoryNetworkPort();
     $iPAddress = new IPAddress();
     $networkPort->getFromDB($data['id']);
     $pfNetworkPort->getFromDB($data['fusionid']);
     $background_img = "";
     if ($pfNetworkPort->fields["trunk"] == "1" && (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1)) {
         $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/port_trunk.png\"); '";
     } else {
         if (PluginFusioninventoryNetworkPort::isPortHasMultipleMac($data['id']) && (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1)) {
             $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/multiple_mac_addresses.png\"); '";
         } else {
             if (strstr($pfNetworkPort->fields["ifstatus"], "up") || $pfNetworkPort->fields["ifstatus"] == 1) {
                 $background_img = " style='background-image: url(\"" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/connected_trunk.png\"); '";
             }
         }
     }
     echo "<tr class='tab_bg_1 center' height='40'" . $background_img . ">";
     if ($aggrega) {
         echo "<td style='background-color: #f2f2f2;'></td><td>";
     }
     if (!$aggrega) {
         if ($networkPort->fields['instantiation_type'] == 'NetworkPortAggregate') {
             echo "<td>";
         } else {
             echo "<td colspan='2'>";
         }
     }
     echo "<a href='networkport.form.php?id=" . $networkPort->fields["id"] . "'>" . $networkPort->fields["name"] . "</a>";
     Html::showToolTip($pfNetworkPort->fields['ifdescr']);
     if (!$aggrega) {
         if ($networkPort->fields['instantiation_type'] == 'NetworkPortAggregate') {
             echo "<td><i><font style='color: grey'>" . __('Aggregation port') . "</font></i></td>";
         }
     }
     if ($monitoring == '1') {
         echo "<td>";
         $state = PluginMonitoringNetworkport::isMonitoredNetworkport($data['id']);
         if (Session::haveRight("plugin_monitoring_componentscatalog", UPDATE)) {
             $checked = '';
             if ($state) {
                 $checked = 'checked';
             }
             echo "<input type='checkbox' name='networkports_id[]' value='" . $data['id'] . "' " . $checked . "/>";
         } else {
             if (Session::haveRight("plugin_monitoring_componentscatalog", READ)) {
                 echo Dropdown::getYesNo($state);
             }
         }
         echo "</td>";
     }
     $a_pref = DisplayPreference::getForTypeUser('PluginFusioninventoryNetworkport', Session::getLoginUserID());
     foreach ($a_pref as $data_array) {
         switch ($data_array) {
             case 3:
                 echo "<td>" . $pfNetworkPort->fields["ifmtu"] . "</td>";
                 break;
             case 5:
                 echo "<td>" . $this->byteSize($pfNetworkPort->fields["ifspeed"], 1000) . "bps</td>";
                 break;
             case 6:
                 echo "<td>";
                 if (strstr($pfNetworkPort->fields["ifstatus"], "up") || strstr($pfNetworkPort->fields["ifinternalstatus"], "1")) {
                     echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png'/>";
                 } else {
                     if (strstr($pfNetworkPort->fields["ifstatus"], "down") || strstr($pfNetworkPort->fields["ifinternalstatus"], "2")) {
                         echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'/>";
                     } else {
                         if (strstr($pfNetworkPort->fields["ifstatus"], "testing") || strstr($pfNetworkPort->fields["ifinternalstatus"], "3")) {
                             echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/yellowbutton.png'/>";
                         }
                     }
                 }
                 echo "</td>";
                 break;
             case 7:
                 echo "<td>" . $pfNetworkPort->fields["iflastchange"] . "</td>";
                 break;
             case 8:
                 echo "<td>";
                 if ($pfNetworkPort->fields["ifinoctets"] == "0") {
                     echo "-";
                 } else {
                     echo $this->byteSize($pfNetworkPort->fields["ifinoctets"], 1000) . "o";
                 }
                 echo " / ";
                 if ($pfNetworkPort->fields["ifinoctets"] == "0") {
                     echo "-";
                 } else {
                     echo $this->byteSize($pfNetworkPort->fields["ifoutoctets"], 1000) . "o";
                 }
                 echo "</td>";
                 break;
             case 9:
                 $color = '';
                 if ($pfNetworkPort->fields["ifinerrors"] != "0" || $pfNetworkPort->fields["ifouterrors"] != "0") {
                     $color = "background='#cf9b9b' class='tab_bg_1_2'";
                 }
                 if ($pfNetworkPort->fields["ifinerrors"] == "0") {
                     echo "<td " . $color . ">-";
                 } else {
                     echo "<td " . $color . ">";
                     echo $pfNetworkPort->fields["ifinerrors"];
                 }
                 echo " / ";
                 if ($pfNetworkPort->fields["ifouterrors"] == "0") {
                     echo "-";
                 } else {
                     echo $pfNetworkPort->fields["ifouterrors"];
                 }
                 echo "</td>";
                 break;
             case 10:
                 if ($pfNetworkPort->fields["portduplex"] == 2) {
                     echo "<td background='#cf9b9b' class='tab_bg_1_2'>";
                     echo __('Half', 'fusioninventory');
                     echo '</td>';
                 } else {
                     if ($pfNetworkPort->fields["portduplex"] == 3) {
                         echo '<td>';
                         echo __('Full', 'fusioninventory');
                         echo '</td>';
                     } else {
                         echo "<td></td>";
                     }
                 }
                 break;
             case 11:
                 // ** internal mac
                 echo "<td>" . $networkPort->fields["mac"] . "</td>";
                 break;
             case 13:
                 // ** Mac address and link to device which are connected to this port
                 $opposite_port = $nw->getOppositeContact($data["id"]);
                 if ($opposite_port != "" && $opposite_port != 0) {
                     $networkPortOpposite = new NetworkPort();
                     if ($networkPortOpposite->getFromDB($opposite_port)) {
                         $data_device = $networkPortOpposite->fields;
                         $item = new $data_device["itemtype"]();
                         $item->getFromDB($data_device["items_id"]);
                         $link1 = $item->getLink(1);
                         $link = str_replace($item->getName(0), $data_device["mac"], $item->getLink());
                         // * GetIP
                         $a_networknames = current($networkName->find("`itemtype`='NetworkPort'\n                                          AND `items_id`='" . $item->getID() . "'", "", 1));
                         $a_ipaddresses = current($iPAddress->find("`itemtype`='NetworkName'\n                                          AND `items_id`='" . $a_networknames['id'] . "'", "", 1));
                         $link2 = str_replace($item->getName(0), $a_ipaddresses['name'], $item->getLink());
                         if ($data_device["itemtype"] == 'PluginFusioninventoryUnmanaged') {
                             $icon = $this->getItemtypeIcon($item->fields["item_type"]);
                             if ($item->getField("accepted") == "1") {
                                 echo "<td style='background:#bfec75'\n                                     class='tab_bg_1_2'>" . $icon . $link1;
                             } else {
                                 echo "<td background='#cf9b9b'\n                                     class='tab_bg_1_2'>" . $icon . $link1;
                             }
                             if (!empty($link)) {
                                 echo "<br/>" . $link;
                             }
                             if (!empty($link2)) {
                                 echo "<br/>" . $link2;
                             }
                             if ($item->getField("hub") == "1") {
                                 $this->displayHubConnections($data_device["items_id"], $background_img);
                             }
                             echo "</td>";
                         } else {
                             $icon = $this->getItemtypeIcon($data_device["itemtype"]);
                             echo "<td>" . $icon . $link1;
                             if (!empty($link)) {
                                 echo "<br/>" . $link;
                             }
                             if (!empty($link2)) {
                                 echo "<br/>" . $link2;
                             }
                             if ($data_device["itemtype"] == 'Phone') {
                                 $query_devicephone = "SELECT *\n                                   FROM `glpi_networkports`\n                                   WHERE `itemtype`='Phone'\n                                       AND `items_id`='" . $data_device["items_id"] . "'\n                                       AND `id`!='" . $data_device["id"] . "'\n                                   LIMIT 1";
                                 $result_devicephone = $DB->query($query_devicephone);
                                 if ($DB->numrows($result_devicephone) > 0) {
                                     $data_devicephone = $DB->fetch_assoc($result_devicephone);
                                     $computer_ports_id = $nw->getOppositeContact($data_devicephone["id"]);
                                     if ($computer_ports_id) {
                                         $networkport = new NetworkPort();
                                         $networkport->getFromDB($computer_ports_id);
                                         if ($networkport->fields['itemtype'] == 'Computer') {
                                             echo "<hr/>";
                                             echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/computer_icon.png' " . "style='float:left'/> ";
                                             $computer = new Computer();
                                             $computer->getFromDB($networkport->fields["items_id"]);
                                             $link1 = $computer->getLink(1);
                                             $link = str_replace($computer->getName(0), $networkport->fields["mac"], $computer->getLink());
                                             $link2 = str_replace($computer->getName(0), $networkport->fields["ip"], $computer->getLink());
                                             echo $icon . $link1;
                                             if (!empty($link)) {
                                                 echo "<br/>" . $link;
                                             }
                                             if (!empty($link2)) {
                                                 echo "<br/>" . $link2;
                                             }
                                         }
                                     }
                                 }
                             }
                             echo "</td>";
                         }
                     } else {
                         echo "<td></td>";
                     }
                 } else {
                     echo "<td></td>";
                 }
                 break;
             case 14:
                 // ** Connection status
                 echo "<td>";
                 if (strstr($pfNetworkPort->fields["ifstatus"], "up") || strstr($pfNetworkPort->fields["ifstatus"], "1")) {
                     echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/wired_on.png'/>";
                 } else {
                     if (strstr($pfNetworkPort->fields["ifstatus"], "down") || strstr($pfNetworkPort->fields["ifstatus"], "2")) {
                         echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/wired_off.png'/>";
                     } else {
                         if (strstr($pfNetworkPort->fields["ifstatus"], "testing") || strstr($pfNetworkPort->fields["ifstatus"], "3")) {
                             echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/yellowbutton.png'/>";
                         } else {
                             if (strstr($pfNetworkPort->fields["ifstatus"], "dormant") || strstr($pfNetworkPort->fields["ifstatus"], "5")) {
                                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/orangebutton.png'/>";
                             }
                         }
                     }
                 }
                 echo "</td>";
                 break;
             case 12:
                 echo "<td>";
                 $canedit = Session::haveRight('networking', UPDATE);
                 $used = array();
                 $query_vlan = "SELECT * FROM glpi_networkports_vlans\n                              WHERE networkports_id='" . $data["id"] . "'";
                 $result_vlan = $DB->query($query_vlan);
                 if ($DB->numrows($result_vlan) > 0) {
                     echo "<table cellpadding='0' cellspacing='0'>";
                     while ($line = $DB->fetch_array($result_vlan)) {
                         $used[] = $line["vlans_id"];
                         $vlan = new Vlan();
                         $vlan->getFromDB($line["vlans_id"]);
                         if ($line['tagged'] == '1') {
                             $state = 'T';
                         } else {
                             $state = 'U';
                         }
                         echo "<tr><td>" . $vlan->fields['name'] . " [" . $vlan->fields['tag'] . "] " . $state;
                         echo "</td><td>";
                         if ($canedit) {
                             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?unassign_vlan=unassigned&amp;id=" . $line["id"] . "'>";
                             echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/delete.png\" alt='" . __('Delete', 'fusioninventory') . "' title='" . __('Delete', 'fusioninventory') . "'></a>";
                         } else {
                             echo "&nbsp;";
                         }
                         echo "</td>";
                         echo "</tr>";
                     }
                     echo "</table>";
                 } else {
                     echo "&nbsp;";
                 }
                 echo "</td>";
                 break;
             case 15:
                 echo "<td align='center'>";
                 if ($pfNetworkPort->fields['ifstatus'] == 1) {
                     echo __('Connected');
                 } else {
                     if ($pfNetworkPort->fields['lastup'] == "0000-00-00 00:00:00") {
                         echo '-';
                     } else {
                         $time = strtotime(date('Y-m-d H:i:s')) - strtotime($pfNetworkPort->fields['lastup']);
                         echo Html::timestampToString($time, FALSE);
                     }
                 }
                 echo "</td>";
                 break;
             case 16:
                 echo "<td>" . $pfNetworkPort->fields["ifalias"] . "</td>";
                 break;
         }
     }
     echo "</tr>";
 }
 function _updateNetworkInfo($arrayinventory, $item_type, $id, $instanciation_type, $check_addresses)
 {
     $NetworkPort = new NetworkPort();
     $port = current($NetworkPort->find("`itemtype`='{$item_type}' AND `items_id`='{$id}'" . " AND `instantiation_type`='{$instanciation_type}'", "", 1));
     $port_id = 0;
     if (isset($port['id'])) {
         if (isset($arrayinventory['MAC']) and !empty($arrayinventory['MAC'])) {
             $input = array();
             $input['id'] = $port['id'];
             $input['mac'] = $arrayinventory['MAC'];
             $NetworkPort->update($input);
         }
         $port_id = $port['id'];
     } else {
         $input = array();
         $input['itemtype'] = $item_type;
         $input['items_id'] = $id;
         $input['instantiation_type'] = $instanciation_type;
         $input['name'] = "management";
         if (isset($arrayinventory['MAC']) && !empty($arrayinventory['MAC'])) {
             $input['mac'] = $arrayinventory['MAC'];
         }
         $port_id = $NetworkPort->add($input);
     }
     $NetworkName = new NetworkName();
     $name = current($NetworkName->find("`itemtype`='NetworkPort' AND `items_id`='" . $port_id . "'", "", 1));
     $name_id = 0;
     if (isset($name['id'])) {
         $name_id = $name['id'];
     } else {
         $input = array();
         $input['itemtype'] = 'NetworkPort';
         $input['items_id'] = $port_id;
         $name_id = $NetworkName->add($input);
     }
     if (isset($arrayinventory['IP'])) {
         $IPAddress = new IPAddress();
         if ($check_addresses) {
             $addresses = $IPAddress->find("`itemtype`='NetworkName'\n               AND `items_id`='" . $name_id . "'", '', 1);
         } else {
             // Case of NetworkEquipment
             $a_ips = $IPAddress->find("`itemtype`='NetworkName'\n               AND `items_id`='" . $name_id . "'\n               AND `name`='" . $arrayinventory['IP'] . "'", '', 1);
             if (count($a_ips) > 0) {
                 $addresses = $a_ips;
             } else {
                 $addresses = array();
             }
         }
         if (count($addresses) == 0) {
             $input = array();
             $input['itemtype'] = 'NetworkName';
             $input['items_id'] = $name_id;
             $input['name'] = $arrayinventory['IP'];
             $IPAddress->add($input);
         } else {
             $address = current($addresses);
             if ($address['name'] != $arrayinventory['IP']) {
                 $input = array();
                 $input['id'] = $address['id'];
                 $input['name'] = $arrayinventory['IP'];
                 $IPAddress->update($input);
             }
         }
     }
 }
Ejemplo n.º 6
0
 function getSearchOptions()
 {
     $tab = parent::getSearchOptions();
     $tab[12]['table'] = 'glpi_fqdns';
     $tab[12]['field'] = 'fqdn';
     $tab[12]['name'] = FQDN::getTypeName(1);
     $tab[12]['datatype'] = 'string';
     $tab[20]['table'] = 'glpi_networknames';
     $tab[20]['field'] = 'name';
     $tab[20]['name'] = NetworkName::getTypeName(1);
     $tab[20]['massiveaction'] = false;
     $tab[20]['datatype'] = 'dropdown';
     return $tab;
 }
Ejemplo n.º 7
0
 /**
  * @param $row                HTMLTableRow object (default NULL)
  * @param $item               CommonDBTM object (default NULL)
  * @param $father             HTMLTableCell object (default NULL)
  * @param $options   array
  **/
 static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array())
 {
     global $DB, $CFG_GLPI;
     if ($item !== NULL && $item->getType() == 'IPNetwork') {
         $queries = array();
         foreach ($CFG_GLPI["networkport_types"] as $itemtype) {
             $table = getTableForItemType($itemtype);
             $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n                                  ADDR.`binary_1` AS binary_1,\n                                  ADDR.`binary_2` AS binary_2,\n                                  ADDR.`binary_3` AS binary_3,\n                                  ADDR.`name`     AS ip,\n                                  ADDR.`id`       AS id,\n                                  ADDR.`itemtype` AS addr_item_type,\n                                  ADDR.`items_id` AS addr_item_id,\n                                  `glpi_entities`.`completename` AS entity,\n                                  NAME.`id`       AS name_id,\n                                  PORT.`id`       AS port_id,\n                                  ITEM.`id`       AS item_id,\n                                  '{$itemtype}'     AS item_type\n                           FROM `glpi_ipaddresses_ipnetworks` AS LINK\n                           JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n                                                               AND ADDR.`itemtype` = 'NetworkName'\n                                                               AND ADDR.`is_deleted` = '0')\n                           LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n                           JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n                                                                AND NAME.`itemtype` = 'NetworkPort')\n                           JOIN `glpi_networkports` AS PORT ON (NAME.`items_id` = PORT.`id`\n                                                                AND PORT.`itemtype` = '{$itemtype}')\n                           JOIN `{$table}` AS ITEM ON (ITEM.`id` = PORT.`items_id`)\n                           WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')";
         }
         $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n                               ADDR.`binary_1` AS binary_1,\n                               ADDR.`binary_2` AS binary_2,\n                               ADDR.`binary_3` AS binary_3,\n                               ADDR.`name`     AS ip,\n                               ADDR.`id`       AS id,\n                               ADDR.`itemtype` AS addr_item_type,\n                               ADDR.`items_id` AS addr_item_id,\n                               `glpi_entities`.`completename` AS entity,\n                               NAME.`id`       AS name_id,\n                               PORT.`id`       AS port_id,\n                               NULL            AS item_id,\n                               NULL            AS item_type\n                        FROM `glpi_ipaddresses_ipnetworks` AS LINK\n                        JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n                                                            AND ADDR.`itemtype` = 'NetworkName'\n                                                            AND ADDR.`is_deleted` = '0')\n                        LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n                        JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n                                                             AND NAME.`itemtype` = 'NetworkPort')\n                        JOIN `glpi_networkports` AS PORT\n                           ON (NAME.`items_id` = PORT.`id`\n                               AND PORT.`itemtype`\n                                    NOT IN ('" . implode("', '", $CFG_GLPI["networkport_types"]) . "'))\n                        WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')";
         $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n                               ADDR.`binary_1` AS binary_1,\n                               ADDR.`binary_2` AS binary_2,\n                               ADDR.`binary_3` AS binary_3,\n                               ADDR.`name`     AS ip,\n                               ADDR.`id`       AS id,\n                               ADDR.`itemtype` AS addr_item_type,\n                               ADDR.`items_id` AS addr_item_id,\n                               `glpi_entities`.`completename` AS entity,\n                               NAME.`id`       AS name_id,\n                               NULL            AS port_id,\n                               NULL            AS item_id,\n                               NULL            AS item_type\n                        FROM `glpi_ipaddresses_ipnetworks` AS LINK\n                        JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n                                                            AND ADDR.`itemtype` = 'NetworkName'\n                                                            AND ADDR.`is_deleted` = '0')\n                        LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n                        JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n                                                             AND NAME.`itemtype` != 'NetworkPort')\n                        WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')";
         $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n                               ADDR.`binary_1` AS binary_1,\n                               ADDR.`binary_2` AS binary_2,\n                               ADDR.`binary_3` AS binary_3,\n                               ADDR.`name`     AS ip,\n                               ADDR.`id`       AS id,\n                               ADDR.`itemtype` AS addr_item_type,\n                               ADDR.`items_id` AS addr_item_id,\n                               `glpi_entities`.`completename` AS entity,\n                               NULL            AS name_id,\n                               NULL            AS port_id,\n                               NULL            AS item_id,\n                               NULL            AS item_type\n                        FROM `glpi_ipaddresses_ipnetworks` AS LINK\n                        JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n                                                            AND ADDR.`itemtype` != 'NetworkName'\n                                                            AND ADDR.`is_deleted` = '0')\n                        LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n                        WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')";
         $query = implode('UNION ', $queries);
         if ($options['order'] == 'ip' || $options['order'] == 'itemtype') {
             $query .= " ORDER BY binary_0, binary_1, binary_2, binary_3";
         }
         if (isset($options['SQL_options'])) {
             $query .= "\n" . $options['SQL_options'];
         }
         $canedit = isset($options['canedit']) && $options['canedit'];
         $options['createRow'] = false;
         $address = new self();
         $ipaddress = new self();
         $networkname = new NetworkName();
         $networkport = new NetworkPort();
         $item = NULL;
         foreach ($DB->request($query) as $line) {
             unset($row);
             if ($options['order'] == 'itemtype' && !empty($line['item_type'])) {
                 $row = $options['group_' . $line['item_type']]->createRow();
             }
             if (!isset($row)) {
                 $row = $options['group_None']->createRow();
             }
             $ip_header = $row->getGroup()->getSuperHeaderByName('IP Address');
             $item_header = $row->getGroup()->getHeaderByName('Item', 'Item');
             $port_header = $row->getGroup()->getHeaderByName('Item', 'NetworkPort');
             $name_header = $row->getGroup()->getHeaderByName('Item', 'NetworkName');
             $entity_header = $row->getGroup()->getHeaderByName('Item', 'Entity');
             $row->addCell($ip_header, $line['ip'], $father);
             if (!empty($line['name_id'])) {
                 $networkname->getFromDB($line['name_id']);
                 $row->addCell($name_header, $networkname->getLink(), $father);
                 if (!empty($line['port_id'])) {
                     $networkport->getFromDB($line['port_id']);
                     $row->addCell($port_header, $networkport->getLink(), $father);
                     if (!empty($line['item_id']) && !empty($line['item_type'])) {
                         $itemtype = $line['item_type'];
                         $item = new $itemtype();
                         $item->getFromDB($line['item_id']);
                         $row->addCell($item_header, $item->getLink(), $father);
                     }
                 }
                 $row->addCell($entity_header, $line['entity'], $father);
             } else {
                 if (!empty($line['addr_item_id']) && !empty($line['addr_item_type'])) {
                     $itemtype = $line['addr_item_type'];
                     $item = new $itemtype();
                     $item->getFromDB($line['addr_item_id']);
                     if ($item instanceof CommonDBChild) {
                         $items = $item->recursivelyGetItems();
                         $elements = array($item->getLink());
                         foreach ($items as $item_) {
                             $elements[] = $item_->getLink();
                         }
                         $row->addCell($item_header, implode(' > ', $elements), $father);
                     } else {
                         $row->addCell($item_header, $item->getLink(), $father);
                     }
                     $row->addCell($entity_header, $line['entity'], $father);
                 }
             }
         }
     } else {
         if (isset($options['dont_display']['IPAddress'])) {
             return;
         }
         $header = $row->getGroup()->getHeaderByName('Internet', __CLASS__);
         if (!$header) {
             return;
         }
         if (empty($item)) {
             if (empty($father)) {
                 return;
             }
             $item = $father->getItem();
         }
         $query = "SELECT `id`\n                                  FROM `glpi_ipaddresses`\n                                  WHERE `items_id` = '" . $item->getID() . "'\n                                        AND `itemtype` = '" . $item->getType() . "'\n                                        AND `is_deleted` = '0'";
         $canedit = isset($options['canedit']) && $options['canedit'];
         $createRow = isset($options['createRow']) && $options['createRow'];
         $options['createRow'] = false;
         $address = new self();
         foreach ($DB->request($query) as $ipaddress) {
             if ($address->getFromDB($ipaddress['id'])) {
                 if ($createRow) {
                     $row = $row->createRow();
                 }
                 $content = $address->fields['name'];
                 $this_cell = $row->addCell($header, $content, $father);
                 if (isset($options['display_isDynamic']) && $options['display_isDynamic']) {
                     $dyn_header = $row->getGroup()->getHeaderByName('Internet', __CLASS__ . '_dynamic');
                     $this_cell = $row->addCell($dyn_header, Dropdown::getYesNo($address->fields['is_dynamic']), $this_cell);
                 }
                 IPNetwork::getHTMLTableCellsForItem($row, $address, $this_cell, $options);
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Display form to unlock fields and links
  *
  * @param CommonDBTM $item the source item
  **/
 static function showForItem(CommonDBTM $item)
 {
     global $DB;
     $ID = $item->getID();
     $itemtype = $item->getType();
     $header = false;
     //If user doesn't have write right on the item, lock form must not be displayed
     if (!$item->canCreate()) {
         return false;
     }
     echo "<div width='50%'>";
     echo "<form method='post' id='lock_form'\n             name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<input type='hidden' name='id' value='{$ID}'>\n";
     echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>";
     //Use a hook to allow external inventory tools to manage per field lock
     $results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header));
     $header |= $results['header'];
     //Special locks for computers only
     if ($itemtype == 'Computer') {
         //Locks for items recorded in glpi_computers_items table
         $types = array('Monitor', 'Peripheral', 'Printer');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type);
             $params['FIELDS'] = array('id', 'items_id');
             $first = true;
             foreach ($DB->request('glpi_computers_items', $params) as $line) {
                 $tmp = new $type();
                 $tmp->getFromDB($line['items_id']);
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>";
                 echo "</tr>\n";
             }
         }
         $types = array('ComputerDisk', 'ComputerVirtualMachine');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
             $params['FIELDS'] = array('id', 'name');
             $first = true;
             foreach ($DB->request(getTableForItemType($type), $params) as $line) {
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $line['name'] . "</td>";
                 echo "</tr>\n";
             }
         }
         //Software versions
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwareversions` AS csv\n                    LEFT JOIN `glpi_softwareversions` AS sv\n                       ON (`csv`.`softwareversions_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
         //Software licenses
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwarelicenses` AS csv\n                    LEFT JOIN `glpi_softwarelicenses` AS sv\n                       ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
     }
     $first = true;
     $item = new NetworkPort();
     $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype);
     $params['FIELDS'] = array('id');
     foreach ($DB->request('glpi_networkports', $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new NetworkName();
     $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_networknames' => 'id');
     foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new IPAddress();
     $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_ipaddresses' => 'id');
     foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $types = Item_Devices::getDeviceTypes();
     $nb = 0;
     foreach ($types as $old => $type) {
         $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n                                         AND `itemtype`='{$itemtype}'\n                                         AND `is_dynamic`='1'\n                                         AND `is_deleted`='1'");
     }
     if ($nb) {
         $header = true;
         echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n";
         foreach ($types as $old => $type) {
             $associated_type = str_replace('Item_', '', $type);
             $associated_table = getTableForItemType($associated_type);
             $fk = getForeignKeyFieldForTable($associated_table);
             $query = "SELECT `i`.`id`,\n                             `t`.`designation` AS `name`\n                      FROM `" . getTableForItemType($type) . "` AS i\n                      LEFT JOIN `{$associated_table}` AS t\n                         ON (`t`.`id` = `i`.`{$fk}`)\n                      WHERE `itemtype` = '{$itemtype}'\n                            AND `items_id` = '{$ID}'\n                            AND `is_dynamic` = '1'\n                            AND `is_deleted` = '1'";
             foreach ($DB->request($query) as $data) {
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>";
                 printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']);
                 echo "</td></tr>\n";
             }
         }
     }
     if ($header) {
         echo "</table>";
         Html::openArrowMassives('lock_form', true);
         Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock')));
     } else {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>";
         echo "</table>";
     }
     Html::closeForm();
     echo "</div>\n";
 }
 /**
  * @test
  */
 public function updatePrinterFromNetdiscovery()
 {
     global $DB;
     $DB->connect();
     $pfCNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery();
     $GLPIlog = new GLPIlogs();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $_SESSION['SOURCE_XMLDEVICE'] = array('AUTHSNMP' => '1', 'DESCRIPTION' => 'Photosmart D7200 series', 'ENTITY' => '0', 'FIRMWARE' => '', 'IP' => '192.168.20.102', 'MAC' => '00:21:5a:0b:bb:c4', 'MANUFACTURER' => 'Hewlett-Packard', 'MODEL' => '', 'MODELSNMP' => 'Printer0093', 'NETBIOSNAME' => 'HP00215A0BBBC4', 'SERIAL' => 'MY89AQG0V9050N', 'SNMPHOSTNAME' => 'HP0BBBC4new', 'TYPE' => 'PRINTER');
     $printer = new Printer();
     $a_printers = $printer->find("`serial`='MY89AQG0V9050N'");
     $a_printer = current($a_printers);
     $printers_id = $a_printer['id'];
     $printer->getFromDB($printers_id);
     $pfCNetworkDiscovery->importDevice($printer);
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
     $printer->getFromDB($printers_id);
     $this->assertEquals('HP0BBBC4new', $printer->fields['name'], 'Name must be updated');
     $a_printerextends = getAllDatasFromTable('glpi_plugin_fusioninventory_printers', "`printers_id`='" . $printers_id . "'");
     $this->assertEquals('1', count($a_printerextends), 'May have one printer extend line for this printer');
     $a_printerextend = current($a_printerextends);
     $this->assertEquals('1', $a_printerextend['plugin_fusioninventory_configsecurities_id'], 'SNMPauth may be with id 1');
     $this->assertEquals('Photosmart D7200 series', $a_printerextend['sysdescr'], 'Sysdescr not updated correctly');
     // Check mac
     $networkPort = new NetworkPort();
     $a_ports = $networkPort->find("`itemtype`='Printer' AND `items_id`='" . $printers_id . "'");
     $this->assertEquals('1', count($a_ports), 'May have one network port');
     $a_port = current($a_ports);
     $this->assertEquals('00:21:5a:0b:bb:c4', $a_port['mac'], 'Mac address');
     // check ip
     $a_networknames = $networkName->find("`itemtype`='NetworkPort'\n         AND `items_id`='" . $a_port['id'] . "'");
     $this->assertEquals('1', count($a_networknames), 'May have one networkname');
     $a_networkname = current($a_networknames);
     $a_ipaddresses = $iPAddress->find("`itemtype`='NetworkName'\n         AND `items_id`='" . $a_networkname['id'] . "'");
     $this->assertEquals('1', count($a_ipaddresses), 'May have one IP address');
     $a_ipaddress = current($a_ipaddresses);
     $this->assertEquals('192.168.20.102', $a_ipaddress['name'], 'IP address');
 }
 static function getIp($items_id, $itemtype, $hostname)
 {
     global $DB;
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $pmHostaddress = new PluginMonitoringHostaddress();
     $ip = '';
     $networkports_id = 0;
     $query = "SELECT * FROM `" . $pmHostaddress->getTable() . "`\n      WHERE `items_id`='" . $items_id . "'\n         AND `itemtype`='" . $itemtype . "'\n      LIMIT 1";
     $result = $DB->query($query);
     if ($DB->numrows($result) == '1') {
         $data = $DB->fetch_assoc($result);
         if ($data['ipaddresses_id'] > 0) {
             $iPAddress->getFromDB($data['ipaddresses_id']);
             return $iPAddress->fields['name'];
         } else {
             $networkports_id = $data['networkports_id'];
         }
     }
     if ($ip == '') {
         if ($networkports_id > 0) {
             $a_listnetwork = $networkPort->find("`id`='" . $networkports_id . "'");
         } else {
             $a_listnetwork = $networkPort->find("`itemtype`='" . $itemtype . "'\n               AND `items_id`='" . $items_id . "'", "`id`");
         }
         foreach ($a_listnetwork as $networkports_id => $datanetwork) {
             $a_networknames_find = current($networkName->find("`items_id`='" . $networkports_id . "'\n                                                               AND `itemtype`='NetworkPort'", "", 1));
             if (isset($a_networknames_find['id'])) {
                 $networknames_id = $a_networknames_find['id'];
                 $a_ips_fromDB = $iPAddress->find("`itemtype`='NetworkName'\n                                                 AND `items_id`='" . $networknames_id . "'");
                 foreach ($a_ips_fromDB as $data) {
                     if ($data['name'] != '' && $data['name'] != '127.0.0.1' && $data['name'] != '::1') {
                         return $data['name'];
                     }
                 }
             }
         }
     }
     return $hostname;
 }
 function manageNetworkPort($inventory_networkports, $computers_id, $no_history)
 {
     global $DB;
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $iPNetwork = new IPNetwork();
     $networkPortEthernet = new NetworkPortEthernet();
     $item_DeviceNetworkCard = new Item_DeviceNetworkCard();
     foreach ($inventory_networkports as $a_networkport) {
         if ($a_networkport['mac'] != '') {
             $a_networkports = $networkPort->find("`mac`='" . $a_networkport['mac'] . "'\n               AND `itemtype`='PluginFusioninventoryUnmanaged'", "", 1);
             if (count($a_networkports) > 0) {
                 $input = current($a_networkports);
                 $unmanageds_id = $input['items_id'];
                 $input['logical_number'] = $a_networkport['logical_number'];
                 $input['itemtype'] = 'Computer';
                 $input['items_id'] = $computers_id;
                 $input['is_dynamic'] = 1;
                 $input['name'] = $a_networkport['name'];
                 $networkPort->update($input, !$no_history);
                 $pfUnmanaged = new PluginFusioninventoryUnmanaged();
                 $pfUnmanaged->delete(array('id' => $unmanageds_id), 1);
             }
         }
     }
     // end get port from unknwon device
     $db_networkport = array();
     if ($no_history === FALSE) {
         $query = "SELECT `id`, `name`, `mac`, `instantiation_type`, `logical_number`\n             FROM `glpi_networkports`\n             WHERE `items_id` = '{$computers_id}'\n               AND `itemtype`='Computer'\n               AND `is_dynamic`='1'";
         $result = $DB->query($query);
         while ($data = $DB->fetch_assoc($result)) {
             $idtmp = $data['id'];
             unset($data['id']);
             if (is_null($data['mac'])) {
                 $data['mac'] = '';
             }
             if (preg_match("/[^a-zA-Z0-9 \\-_\\(\\)]+/", $data['name'])) {
                 $data['name'] = Toolbox::addslashes_deep($data['name']);
             }
             $db_networkport[$idtmp] = array_map('strtolower', $data);
         }
     }
     $simplenetworkport = array();
     foreach ($inventory_networkports as $key => $a_networkport) {
         // Add ipnetwork if not exist
         if ($a_networkport['gateway'] != '' && $a_networkport['netmask'] != '' && $a_networkport['subnet'] != '') {
             if (countElementsInTable('glpi_ipnetworks', "`address`='" . $a_networkport['subnet'] . "'\n                                     AND `netmask`='" . $a_networkport['netmask'] . "'\n                                     AND `gateway`='" . $a_networkport['gateway'] . "'\n                                     AND `entities_id`='" . $_SESSION["plugin_fusioninventory_entity"] . "'") == 0) {
                 $input_ipanetwork = array('name' => $a_networkport['subnet'] . '/' . $a_networkport['netmask'] . ' - ' . $a_networkport['gateway'], 'network' => $a_networkport['subnet'] . ' / ' . $a_networkport['netmask'], 'gateway' => $a_networkport['gateway'], 'entities_id' => $_SESSION["plugin_fusioninventory_entity"]);
                 $iPNetwork->add($input_ipanetwork, array(), !$no_history);
             }
         }
         // End add ipnetwork
         $a_field = array('name', 'mac', 'instantiation_type');
         foreach ($a_field as $field) {
             if (isset($a_networkport[$field])) {
                 $simplenetworkport[$key][$field] = $a_networkport[$field];
             }
         }
     }
     foreach ($simplenetworkport as $key => $arrays) {
         $arrayslower = array_map('strtolower', $arrays);
         foreach ($db_networkport as $keydb => $arraydb) {
             $logical_number = $arraydb['logical_number'];
             unset($arraydb['logical_number']);
             if ($arrayslower == $arraydb) {
                 if ($inventory_networkports[$key]['logical_number'] != $logical_number) {
                     $input = array();
                     $input['id'] = $keydb;
                     $input['logical_number'] = $inventory_networkports[$key]['logical_number'];
                     $networkPort->update($input, !$no_history);
                 }
                 // Add / update instantiation_type
                 if (isset($inventory_networkports[$key]['instantiation_type'])) {
                     if ($inventory_networkports[$key]['instantiation_type'] == 'NetworkPortEthernet') {
                         $portsethernet = $networkPortEthernet->find("`networkports_id`='" . $keydb . "'", '', 1);
                         if (count($portsethernet) == 1) {
                             $portethernet = current($portsethernet);
                             $input = $portethernet;
                         } else {
                             $input = array('networkports_id' => $keydb);
                         }
                         if (isset($inventory_networkports[$key]['speed'])) {
                             $input['speed'] = $inventory_networkports[$key]['speed'];
                             $input['speed_other_value'] = $inventory_networkports[$key]['speed'];
                         }
                         if (isset($inventory_networkports[$key]['mac'])) {
                             $networkcards = $item_DeviceNetworkCard->find("`mac`='" . $inventory_networkports[$key]['mac'] . "' " . " AND `itemtype`='Computer'" . " AND `items_id`='" . $computers_id . "'", '', 1);
                             if (count($networkcards) == 1) {
                                 $networkcard = current($networkcards);
                                 $input['items_devicenetworkcards_id'] = $networkcard['id'];
                             }
                         }
                         $input['_no_history'] = $no_history;
                         if (isset($input['id'])) {
                             $networkPortEthernet->update($input);
                         } else {
                             $networkPortEthernet->add($input);
                         }
                     }
                 }
                 // Get networkname
                 $a_networknames_find = current($networkName->find("`items_id`='" . $keydb . "'\n                                                    AND `itemtype`='NetworkPort'", "", 1));
                 if (!isset($a_networknames_find['id'])) {
                     $a_networkport['entities_id'] = $_SESSION["plugin_fusioninventory_entity"];
                     $a_networkport['items_id'] = $computers_id;
                     $a_networkport['itemtype'] = "Computer";
                     $a_networkport['is_dynamic'] = 1;
                     $a_networkport['_no_history'] = $no_history;
                     $a_networkport['items_id'] = $keydb;
                     unset($a_networkport['_no_history']);
                     $a_networkport['is_recursive'] = 0;
                     $a_networkport['itemtype'] = 'NetworkPort';
                     unset($a_networkport['name']);
                     $a_networkport['_no_history'] = $no_history;
                     $a_networknames_id = $networkName->add($a_networkport, array(), !$no_history);
                     $a_networknames_find['id'] = $a_networknames_id;
                 }
                 // Same networkport, verify ipaddresses
                 $db_addresses = array();
                 $query = "SELECT `id`, `name` FROM `glpi_ipaddresses`\n                   WHERE `items_id` = '" . $a_networknames_find['id'] . "'\n                     AND `itemtype`='NetworkName'";
                 $result = $DB->query($query);
                 while ($data = $DB->fetch_assoc($result)) {
                     $db_addresses[$data['id']] = $data['name'];
                 }
                 $a_computerinventory_ipaddress = $inventory_networkports[$key]['ipaddress'];
                 foreach ($a_computerinventory_ipaddress as $key2 => $arrays2) {
                     foreach ($db_addresses as $keydb2 => $arraydb2) {
                         if ($arrays2 == $arraydb2) {
                             unset($a_computerinventory_ipaddress[$key2]);
                             unset($db_addresses[$keydb2]);
                             break;
                         }
                     }
                 }
                 if (count($a_computerinventory_ipaddress) == 0 and count($db_addresses) == 0) {
                     // Nothing to do
                 } else {
                     if (count($db_addresses) != 0) {
                         // Delete ip address in DB
                         foreach (array_keys($db_addresses) as $idtmp) {
                             $iPAddress->delete(array('id' => $idtmp), 1);
                         }
                     }
                     if (count($a_computerinventory_ipaddress) != 0) {
                         foreach ($a_computerinventory_ipaddress as $ip) {
                             $input = array();
                             $input['items_id'] = $a_networknames_find['id'];
                             $input['itemtype'] = 'NetworkName';
                             $input['name'] = $ip;
                             $input['is_dynamic'] = 1;
                             $iPAddress->add($input, array(), !$no_history);
                         }
                     }
                 }
                 unset($db_networkport[$keydb]);
                 unset($simplenetworkport[$key]);
                 unset($inventory_networkports[$key]);
                 break;
             }
         }
     }
     if (count($inventory_networkports) == 0 and count($db_networkport) == 0) {
         // Nothing to do
     } else {
         if (count($db_networkport) != 0) {
             // Delete networkport in DB
             foreach ($db_networkport as $idtmp => $data) {
                 $networkPort->delete(array('id' => $idtmp), 1);
             }
         }
         if (count($inventory_networkports) != 0) {
             foreach ($inventory_networkports as $a_networkport) {
                 $a_networkport['entities_id'] = $_SESSION["plugin_fusioninventory_entity"];
                 $a_networkport['items_id'] = $computers_id;
                 $a_networkport['itemtype'] = "Computer";
                 $a_networkport['is_dynamic'] = 1;
                 $a_networkport['_no_history'] = $no_history;
                 $a_networkport['items_id'] = $networkPort->add($a_networkport, array(), !$no_history);
                 unset($a_networkport['_no_history']);
                 $a_networkport['is_recursive'] = 0;
                 $a_networkport['itemtype'] = 'NetworkPort';
                 unset($a_networkport['name']);
                 $a_networkport['_no_history'] = $no_history;
                 $a_networknames_id = $networkName->add($a_networkport, array(), !$no_history);
                 foreach ($a_networkport['ipaddress'] as $ip) {
                     $input = array();
                     $input['items_id'] = $a_networknames_id;
                     $input['itemtype'] = 'NetworkName';
                     $input['name'] = $ip;
                     $input['is_dynamic'] = 1;
                     $input['_no_history'] = $no_history;
                     $iPAddress->add($input, array(), !$no_history);
                 }
                 if (isset($a_networkport['instantiation_type'])) {
                     if ($a_networkport['instantiation_type'] == 'NetworkPortEthernet') {
                         $input = array('networkports_id' => $a_networkport['items_id']);
                         if (isset($a_networkport['speed'])) {
                             $input['speed'] = $a_networkport['speed'];
                             $input['speed_other_value'] = $a_networkport['speed'];
                         }
                         if (isset($a_networkport['mac'])) {
                             $networkcards = $item_DeviceNetworkCard->find("`mac`='" . $a_networkport['mac'] . "' " . " AND `itemtype`='Computer'" . " AND `items_id`='" . $computers_id . "'", '', 1);
                             if (count($networkcards) == 1) {
                                 $networkcard = current($networkcards);
                                 $input['items_devicenetworkcards_id'] = $networkcard['id'];
                             }
                         }
                         $input['_no_history'] = $no_history;
                         $networkPortEthernet->add($input);
                     }
                 }
             }
         }
     }
 }
 /**
  * @test
  */
 public function NetworkEquipmentInternalPorts()
 {
     global $DB;
     $DB->connect();
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $a_networkports = $networkPort->find("`instantiation_type`='NetworkPortAggregate'\n         AND `itemtype`='NetworkEquipment'\n         AND `items_id`='1'\n         AND `logical_number`='0'");
     $this->assertEquals(1, count($a_networkports), 'Number internal ports');
     $a_networkport = current($a_networkports);
     $this->assertEquals('6c:50:4d:39:59:80', $a_networkport['mac']);
     // May have 3 IP
     $a_networkname = current($networkName->find("`items_id`='" . $a_networkport['id'] . "'\n                                                         AND `itemtype`='NetworkPort'", "", 1));
     $a_ips_fromDB = $iPAddress->find("`itemtype`='NetworkName'\n                                     AND `items_id`='" . $a_networkname['id'] . "'", "`name`");
     $a_ips = array();
     foreach ($a_ips_fromDB as $data) {
         $a_ips[] = $data['name'];
     }
     $this->assertEquals(array('192.168.30.67', '192.168.40.67', '192.168.50.67'), $a_ips);
 }
Ejemplo n.º 13
0
 (at your option) any later version.

 GLPI is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with GLPI. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
$nn = new NetworkName();
if (isset($_POST["add"])) {
    $nn->check(-1, 'w', $_POST);
    $newID = $nn->add($_POST);
    Event::log($newID, "networkname", 5, "inventory", sprintf(__('%s adds an item'), $_SESSION["glpiname"]));
    Html::back();
} else {
    if (isset($_POST["delete"])) {
        $nn->check($_POST['id'], 'd');
        $nn->delete($_POST);
        Event::log($_POST["id"], "networkname", 5, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
        if ($node = getItemForItemtype($nn->fields["itemtype"])) {
            if ($node->can($nn->fields["items_id"], 'r')) {
                Html::redirect($node->getLinkURL());
            }
        }
Ejemplo n.º 14
0
 /**
  * Get HTMLTable row for a given item
  *
  * @param $netport         NetworkPort object (contains item)
  * @param $row             HTMLTableRow object
  * @param $father          HTMLTableHeader object (default NULL)
  * @param $options   array of possible options:
  *       - 'dont_display' : array of the elements that must not be display
  *       - 'withtemplate' : integer withtemplate param
  *
  * @return the father cell for the Internet Informations ...
  **/
 function getInstantiationHTMLTable(NetworkPort $netport, HTMLTableRow $row, HTMLTableCell $father = NULL, array $options = array())
 {
     global $DB;
     $display_options = $options['display_options'];
     if ($this->canHaveVirtualPort && $display_options['virtual_ports']) {
         $virtual_header = $row->getHeaderByName('Instantiation', 'VirtualPorts');
         $query = "(SELECT `networkports_id`\n                    FROM `glpi_networkportaliases`\n                    WHERE `networkports_id_alias`='" . $netport->getID() . "')\n                   UNION\n                   (SELECT `networkports_id`\n                    FROM `glpi_networkportaggregates`\n                    WHERE `networkports_id_list` LIKE '%\"" . $netport->getID() . "\"%')";
         $iterator = $DB->request($query);
         if ($iterator->numrows() > 0) {
             $new_father = $row->addCell($virtual_header, __('this port'), $father);
         } else {
             $new_father = $row->addCell($virtual_header, '', $father);
         }
         foreach ($iterator as $networkports_ids) {
             $virtualPort = new NetworkPort();
             if ($virtualPort->getFromDB($networkports_ids['networkports_id'])) {
                 $cell_value = '<i>' . $virtualPort->getLink() . '</i>';
                 $virtual_cell = $row->addCell($virtual_header, $cell_value, $father);
                 $virtual_cell->setAttributForTheRow(array('class' => 'htmltable_upper_separation_cell'));
                 if ($this->canHaveVLAN && $display_options['vlans']) {
                     NetworkPort_Vlan::getHTMLTableCellsForItem($row, $virtualPort, $virtual_cell, $options);
                 }
                 if ($display_options['internet']) {
                     NetworkName::getHTMLTableCellsForItem($row, $virtualPort, $virtual_cell, $options);
                 }
             }
             unset($virtualPort);
         }
         $father = $new_father;
     }
     if ($this->canHaveVLAN && $display_options['vlans']) {
         NetworkPort_Vlan::getHTMLTableCellsForItem($row, $netport, $father, $options);
     }
     if ($this->haveMAC && $display_options['mac'] && !empty($netport->fields["mac"])) {
         $row->addCell($row->getHeaderByName('Instantiation', 'MAC'), $netport->fields["mac"], $father);
     }
     if ($display_options['internet']) {
         NetworkName::getHTMLTableCellsForItem($row, $netport, $father, $options);
     }
     return NULL;
 }
 function getPortIDfromDeviceIP($IP, $ifDescr, $sysdescr, $sysname, $model)
 {
     global $DB;
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $NetworkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $PortID = "";
     // search port have ifdescr + ip (in most cases not find it)
     $queryPort = "SELECT `glpi_networkports`.`id`\n                    FROM `glpi_plugin_fusioninventory_networkports`\n                    LEFT JOIN `glpi_networkports`\n                       ON `glpi_plugin_fusioninventory_networkports`.`networkports_id`=\n                          `glpi_networkports`.`id`\n                    LEFT JOIN `glpi_networknames`\n                       ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                          AND `glpi_networknames`.`itemtype`='NetworkPort'\n                    LEFT JOIN `glpi_ipaddresses`\n                       ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                          AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                    WHERE (`ifdescr`='" . $ifDescr . "'\n                             OR `glpi_networkports`.`name`='" . $ifDescr . "')\n                          AND `glpi_networkports`.`itemtype`='NetworkEquipment'\n                          AND `glpi_ipaddresses`.`name`='" . $IP . "'";
     $resultPort = $DB->query($queryPort);
     if ($DB->numrows($resultPort) == 0) {
         // Search a management port of networkequipment have this IP
         $queryManagement = "SELECT `glpi_networkports`.`itemtype`,\n                        `glpi_networkports`.`items_id` FROM `glpi_networkports`\n                       LEFT JOIN `glpi_networknames`\n                          ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                             AND `glpi_networknames`.`itemtype`='NetworkPort'\n                       LEFT JOIN `glpi_ipaddresses`\n                          ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                             AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                       WHERE `glpi_ipaddresses`.`name`='" . $IP . "'\n                          AND `instantiation_type`='NetworkPortAggregate'\n                       LIMIT 1";
         $resultManagement = $DB->query($queryManagement);
         if ($DB->numrows($resultManagement) == 1) {
             $dataManagement = $DB->fetch_assoc($resultManagement);
             // Seach a port have this ifdescr for this same networkequipment
             $queryPort = "SELECT `glpi_networkports`.`id`\n                          FROM `glpi_plugin_fusioninventory_networkports`\n                          LEFT JOIN `glpi_networkports`\n                             ON `glpi_plugin_fusioninventory_networkports`.`networkports_id`=\n                                `glpi_networkports`.`id`\n                          WHERE `glpi_networkports`.`itemtype`='" . $dataManagement['itemtype'] . "'\n                              AND `glpi_networkports`.`items_id`='" . $dataManagement['items_id'] . "'\n                              AND (`ifdescr`='" . $ifDescr . "'\n                                   OR `glpi_networkports`.`name`='" . $ifDescr . "')\n                          LIMIT 1";
             $resultPort = $DB->query($queryPort);
             if ($DB->numrows($resultPort) == 1) {
                 $dataPort = $DB->fetch_assoc($resultPort);
                 $PortID = $dataPort["id"];
             }
         }
     } else {
         $dataPort = $DB->fetch_assoc($resultPort);
         $PortID = $dataPort['id'];
     }
     // Detect IP Phone
     if ($PortID == "") {
         if (strstr($model, "Phone") || $model == '') {
             $queryPort = "SELECT glpi_networkports.* FROM `glpi_phones`\n                          LEFT JOIN `glpi_networkports`\n                             ON `glpi_phones`.`id`=`glpi_networkports`.`items_id`\n                          LEFT JOIN `glpi_networknames`\n                             ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                                AND `glpi_networknames`.`itemtype`='NetworkPort'\n                          LEFT JOIN `glpi_ipaddresses`\n                             ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                                AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                          WHERE `glpi_ipaddresses`.`name`='" . $IP . "'\n                                AND `glpi_networkports`.`itemtype`='Phone'\n                                AND `glpi_phones`.`name`='" . $sysname . "'\n                          LIMIT 1";
             $resultPort = $DB->query($queryPort);
             if ($DB->numrows($resultPort) == 1) {
                 $dataPort = $DB->fetch_assoc($resultPort);
                 if (isset($dataPort['id'])) {
                     $PortID = $dataPort["id"];
                 }
             }
         }
     }
     if ($PortID == "") {
         $query = "SELECT * FROM `glpi_plugin_fusioninventory_unmanageds`\n            WHERE `ip`='" . $IP . "'\n            LIMIT 1";
         $result = $DB->query($query);
         if ($DB->numrows($result) == "1") {
             $data = $DB->fetch_assoc($result);
             // Search port and add if required
             $query1 = "SELECT *\n                FROM `glpi_networkports`\n                WHERE `itemtype`='PluginFusioninventoryUnmanaged'\n                   AND `items_id`='" . $data['id'] . "'\n                   AND `name`='" . $ifDescr . "'\n                LIMIT 1";
             $result1 = $DB->query($query1);
             if ($DB->numrows($result1) == "1") {
                 $data1 = $DB->fetch_assoc($result1);
                 $PortID = $data1['id'];
             } else {
                 // Add port
                 $input = array();
                 $input['items_id'] = $data['id'];
                 $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
                 $input['ip'] = $IP;
                 $input['name'] = $ifDescr;
                 $input['instantiation_type'] = 'NetworkPortEthernet';
                 $PortID = $NetworkPort->add($input);
             }
             // Update unmanaged device
             $input = array();
             $input['id'] = $data['id'];
             $input['ip'] = $IP;
             if (strstr($model, "Phone")) {
                 $input['item_type'] = 'Phone';
             }
             if ($sysname != '') {
                 $input['name'] = $sysname;
             }
             if ($sysdescr != '') {
                 $input['sysdescr'] = $sysdescr;
             }
             $pfUnmanaged->update($input);
             return $PortID;
         }
         $query0 = "SELECT `glpi_networkports`.* FROM `glpi_networkports`\n             LEFT JOIN `glpi_networknames`\n                 ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                    AND `glpi_networknames`.`itemtype`='NetworkPort'\n            LEFT JOIN `glpi_ipaddresses`\n                 ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                    AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n             WHERE `glpi_networkports`.`itemtype`='PluginFusioninventoryUnmanaged'\n               AND `glpi_ipaddresses`.`name`='" . $IP . "'\n             LIMIT 1";
         $result0 = $DB->query($query0);
         if ($DB->numrows($result0) == 1) {
             $data0 = $DB->fetch_assoc($result0);
             // Search port and add if required
             $query1 = "SELECT *\n                FROM `glpi_networkports`\n                WHERE `itemtype`='PluginFusioninventoryUnmanaged'\n                   AND `items_id`='" . $data0['items_id'] . "'\n                   AND `name`='" . $ifDescr . "'\n                LIMIT 1";
             $result1 = $DB->query($query1);
             if ($DB->numrows($result1) == "1") {
                 $data1 = $DB->fetch_assoc($result1);
                 $PortID = $data1['id'];
             } else {
                 // Add port
                 $input = array();
                 $input['items_id'] = $data0['items_id'];
                 $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
                 $input['name'] = $ifDescr;
                 $input['instantiation_type'] = 'NetworkPortEthernet';
                 $PortID = $NetworkPort->add($input);
                 $input = array();
                 $input['itemtype'] = 'NetworkPort';
                 $input['items_id'] = $PortID;
                 $networknames_id = $networkName->add($input);
                 $input = array();
                 $input['itemtype'] = 'NetworkName';
                 $input['items_id'] = $networknames_id;
                 $input['name'] = $IP;
                 $iPAddress->add($input);
             }
             return $PortID;
         }
         // Add unmanaged device
         $input = array();
         $input['ip'] = $IP;
         if (strstr($model, "Phone")) {
             $input['item_type'] = 'Phone';
         }
         if ($sysname != '') {
             $input['name'] = $sysname;
         }
         if ($model != '') {
             $input['comment'] = $model;
         }
         if (isset($_SESSION["plugin_fusioninventory_entity"])) {
             $input['entities_id'] = $_SESSION["plugin_fusioninventory_entity"];
         }
         if ($sysdescr != '') {
             $input['sysdescr'] = $sysdescr;
         }
         $unkonwn_id = $pfUnmanaged->add($input);
         // Add port
         $input = array();
         $input['items_id'] = $unkonwn_id;
         $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
         $input['name'] = $ifDescr;
         $input['instantiation_type'] = 'NetworkPortEthernet';
         $PortID = $NetworkPort->add($input);
         $input = array();
         $input['itemtype'] = 'NetworkPort';
         $input['items_id'] = $PortID;
         $networknames_id = $networkName->add($input);
         $input = array();
         $input['itemtype'] = 'NetworkName';
         $input['items_id'] = $networknames_id;
         $input['name'] = $IP;
         $iPAddress->add($input);
         return $PortID;
     }
     return $PortID;
 }
Ejemplo n.º 16
0
 (at your option) any later version.

 GLPI is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with GLPI. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
$nn = new NetworkName();
if (isset($_POST["add"])) {
    $nn->check(-1, CREATE, $_POST);
    if ($newID = $nn->add($_POST)) {
        Event::log($newID, "networkname", 5, "inventory", sprintf(__('%s adds an item'), $_SESSION["glpiname"]));
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($nn->getFormURL() . "?id=" . $newID);
        }
    }
    Html::back();
} else {
    if (isset($_POST["purge"])) {
        $nn->check($_POST['id'], PURGE);
        $nn->delete($_POST, 1);
        Event::log($_POST["id"], "networkname", 5, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
        if ($node = getItemForItemtype($nn->fields["itemtype"])) {
Ejemplo n.º 17
0
Copyright (C) 2003-2014 by the INDEPNET Development Team.

http://indepnet.net/   http://glpi-project.org
-------------------------------------------------------------------------

LICENSE

This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkRight("internet", "r");
Html::header(NetworkName::getTypeName(2), $_SERVER['PHP_SELF'], 'config', 'dropdowns', 'NetworkName');
Search::show('NetworkName');
Html::footer();
Ejemplo n.º 18
0
 /**
  * @param $type
  * @param $items_id
  **/
 static function razPortInfos($type, $items_id)
 {
     global $DB;
     $nn = new NetworkName();
     $conn = new NetworkPort_NetworkPort();
     $vlan = new NetworkPort_Vlan();
     $crit = array('items_id' => $items_id, 'itemtype' => $type);
     foreach ($DB->request('glpi_networkports', $crit) as $data) {
         $nn->unaffectAddressesOfItem($data['id'], 'NetworkPort');
         if ($conn->getFromDBForNetworkPort($data['id'])) {
             $conn->dohistory = false;
             $conn->delete(array('id' => $conn->fields['id']));
         }
         //Delete vlan to port connection
         $crit = array('networkports_id' => $data['id']);
         $vlan->deleteByCriteria($crit);
     }
 }
 public function Cisco1Unmanaged()
 {
     global $DB;
     $DB->connect();
     self::restore_database();
     $a_lldp = array('ifdescr' => 'GigabitEthernet0/10', 'logical_number' => '', 'sysdescr' => '', 'model' => '', 'ip' => '192.168.200.124', 'mac' => '', 'name' => '');
     $pfINetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib();
     $networkEquipment = new NetworkEquipment();
     $networkport = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $pfNetworkPort = new PluginFusioninventoryNetworkPort();
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     // Nortel switch
     $networkequipments_id = $networkEquipment->add(array('name' => 'cisco1', 'entities_id' => 0));
     $networkports_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_id, 'entities_id' => 0));
     // Unmanaged
     $unmanageds_id = $pfUnmanaged->add(array('name' => 'otherswitch', 'entities_id' => 0));
     $networkports_unknown_id = $networkport->add(array('itemtype' => 'PluginFusioninventoryUnmanaged', 'items_id' => $unmanageds_id, 'entities_id' => 0));
     $networknames_id = $networkName->add(array('entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_unknown_id));
     $iPAddress->add(array('entities_id' => 0, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id, 'name' => '192.168.200.124'));
     $pfINetworkEquipmentLib->importConnectionLLDP($a_lldp, $networkports_id);
     $a_portslinks = getAllDatasFromTable('glpi_networkports_networkports');
     $this->assertEquals(1, count($a_portslinks), 'May have 1 connection between 2 network ports');
     $a_networkports = getAllDatasFromTable('glpi_networkports');
     $this->assertEquals(3, count($a_networkports), 'May have 3 network ports (' . print_r($a_networkports, TRUE) . ')');
     $a_unkowns = getAllDatasFromTable('glpi_plugin_fusioninventory_unmanageds');
     $this->assertEquals(1, count($a_unkowns), 'May have only one unknown device (' . print_r($a_unkowns, TRUE) . ')');
     $a_networkport_ref = array('id' => '3', 'items_id' => $unmanageds_id, 'itemtype' => 'PluginFusioninventoryUnmanaged', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'name' => 'GigabitEthernet0/10', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => NULL, 'comment' => NULL, 'is_deleted' => '0', 'is_dynamic' => '0');
     $networkport->getFromDB(3);
     $this->assertEquals($a_networkport_ref, $networkport->fields, 'New unknown port created');
     $a_ref = array('id' => 1, 'networkports_id_1' => $networkports_id, 'networkports_id_2' => 3);
     $this->assertEquals($a_ref, current($a_portslinks), 'Link port');
 }
Ejemplo n.º 20
0
 /**
  * @see CommonDBTM::doSpecificMassiveActions()
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case 'unaffect':
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($this->can($key, 'w')) {
                         if (NetworkName::unaffectAddressByID($key)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     } else {
                         $res['noright']++;
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
 /**
  * @test
  */
 public function PrinterToInventoryWithoutIP()
 {
     self::restore_database();
     $printer = new Printer();
     $networkport = new NetworkPort();
     $networkName = new NetworkName();
     $pfPrinter = new PluginFusioninventoryPrinter();
     $pfTask = new PluginFusioninventoryTask();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $computer = new Computer();
     $pfAgent = new PluginFusioninventoryAgent();
     $communication = new PluginFusioninventoryCommunication();
     // Create computers + agents
     $input = array('entities_id' => 0, 'name' => 'computer1');
     $computers_id = $computer->add($input);
     $input = array('entities_id' => 0, 'name' => 'computer1', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer1', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id);
     $pfAgent->add($input);
     // Create printer
     $input = array('name' => 'printer 001', 'entities_id' => 0);
     $printers_id = $printer->add($input);
     // Add port
     $networkports_id = $networkport->add(array('itemtype' => 'Printer', 'instantiation_type' => 'NetworkPortEthernet', 'items_id' => $printers_id, 'entities_id' => 0));
     $networknames_id = $networkName->add(array('entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_id));
     $input = array('printers_id' => 1, 'plugin_fusioninventory_configsecurities_id' => 2);
     $pfPrinter->add($input);
     // Add task
     // create task
     $input = array('entities_id' => 0, 'name' => 'network inventory', 'is_active' => 1);
     $tasks_id = $pfTask->add($input);
     // create taskjob
     $input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'inventory', 'method' => 'networkinventory', 'targets' => '[{"Printer":"' . $printers_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"1"}]');
     $pfTaskjob->add($input);
     PluginFusioninventoryTask::cronTaskscheduler();
     $data = $pfTask->getJoblogs(array(1));
     // Task is prepared
     // Agent will get data
     $communication->getTaskAgent(1);
     $message = $communication->getMessage();
     $json = json_encode($message);
     $array = json_decode($json, TRUE);
     $ref = array();
     $this->assertEquals($ref, $array, 'XML of SNMP inventory task');
 }
Ejemplo n.º 22
0
 /**
  * @param $itemtype
  **/
 static function getSearchOptionsToAdd($itemtype)
 {
     $tab = array();
     $tab['network'] = __('Networking');
     $joinparams = array('jointype' => 'itemtype_item');
     if ($itemtype == 'Computer') {
         $joinparams['beforejoin'] = array('table' => 'glpi_items_devicenetworkcards', 'joinparams' => array('jointype' => 'itemtype_item', 'specific_itemtype' => 'Computer', 'nolink' => true));
     }
     $tab[21]['table'] = 'glpi_networkports';
     $tab[21]['field'] = 'mac';
     $tab[21]['name'] = __('MAC address');
     $tab[21]['datatype'] = 'mac';
     $tab[21]['forcegroupby'] = true;
     $tab[21]['massiveaction'] = false;
     $tab[21]['joinparams'] = $joinparams;
     $tab[87]['table'] = 'glpi_networkports';
     $tab[87]['field'] = 'instantiation_type';
     $tab[87]['name'] = __('Network port type');
     $tab[87]['datatype'] = 'itemtypename';
     $tab[87]['itemtype_list'] = 'networkport_instantiations';
     $tab[87]['massiveaction'] = false;
     $tab[87]['joinparams'] = $joinparams;
     $networkNameJoin = array('jointype' => 'itemtype_item', 'specific_itemtype' => 'NetworkPort', 'beforejoin' => array('table' => 'glpi_networkports', 'joinparams' => $joinparams));
     NetworkName::getSearchOptionsToAdd($tab, $networkNameJoin, $itemtype);
     $instantjoin = array('jointype' => 'child', 'beforejoin' => array('table' => 'glpi_networkports', 'joinparams' => $joinparams));
     foreach (self::getNetworkPortInstantiations() as $instantiationType) {
         $instantiationType::getSearchOptionsToAddForInstantiation($tab, $instantjoin, $itemtype);
     }
     $netportjoin = array(array('table' => 'glpi_networkports', 'joinparams' => array('jointype' => 'itemtype_item')), array('table' => 'glpi_networkports_vlans', 'joinparams' => array('jointype' => 'child')));
     $tab[88]['table'] = 'glpi_vlans';
     $tab[88]['field'] = 'name';
     $tab[88]['name'] = __('VLAN');
     $tab[88]['datatype'] = 'dropdown';
     $tab[88]['forcegroupby'] = true;
     $tab[88]['massiveaction'] = false;
     $tab[88]['joinparams'] = array('beforejoin' => $netportjoin);
     return $tab;
 }
 static function getIPforDevice($itemtype, $items_id)
 {
     $NetworkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $a_ips = array();
     $a_ports = $NetworkPort->find("`itemtype`='" . $itemtype . "'\n                                       AND `items_id`='" . $items_id . "'\n                                          AND `instantiation_type` != 'NetworkPortLocal'");
     foreach ($a_ports as $a_port) {
         $a_networknames = $networkName->find("`itemtype`='NetworkPort'\n                                              AND `items_id`='" . $a_port['id'] . "'");
         foreach ($a_networknames as $a_networkname) {
             $a_ipaddresses = $iPAddress->find("`itemtype`='NetworkName'\n                                              AND `items_id`='" . $a_networkname['id'] . "'");
             foreach ($a_ipaddresses as $data) {
                 if ($data['name'] != '127.0.0.1' && $data['name'] != '::1') {
                     $a_ips[$data['name']] = $data['name'];
                 }
             }
         }
     }
     return array_unique($a_ips);
 }
Ejemplo n.º 24
0
function pluginFusioninventoryUpdate($current_version, $migrationname = 'Migration')
{
    global $DB;
    ini_set("max_execution_time", "0");
    ini_set("memory_limit", "-1");
    foreach (glob(GLPI_ROOT . '/plugins/fusioninventory/inc/*.php') as $file) {
        require_once $file;
    }
    $migration = new $migrationname($current_version);
    $prepare_task = array();
    $prepare_rangeip = array();
    $prepare_Config = array();
    $a_plugin = plugin_version_fusioninventory();
    $plugins_id = PluginFusioninventoryModule::getModuleId($a_plugin['shortname']);
    $migration->displayMessage("Migration Classname : " . $migrationname);
    $migration->displayMessage("Update of plugin FusionInventory");
    /*
     * Check if folders are correctly created
     */
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels');
    }
    /*
     * Deploy folders
     */
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/files')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/files', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files');
    }
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/repository')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/repository', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/repository');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export');
    }
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/upload')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/upload', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload');
    }
    /*
     * Rename fileparts without .gz extension (cf #1999)
     */
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) {
        $gzfiles = pluginFusioninventoryFindFiles(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files', '/\\.gz$/');
        foreach ($gzfiles as $file) {
            $fileWithoutExt = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME);
            rename($file, $fileWithoutExt);
        }
    }
    unset($gzfiles);
    /*
     *  Rename tables from old version of FuionInventory (2.2.1 for example)
     */
    $migration->renameTable("glpi_plugin_fusioninventory_rangeip", "glpi_plugin_fusioninventory_ipranges");
    $migration->renameTable("glpi_plugin_fusioninventory_lock", "glpi_plugin_fusioninventory_locks");
    $migration->renameTable("glpi_plugin_fusioninventory_unknown_device", "glpi_plugin_fusioninventory_unknowndevices");
    $migration->renameTable("glpi_plugin_fusioninventory_config", "glpi_plugin_fusioninventory_configs");
    $migration->renameTable("glpi_plugin_fusioninventory_networking_ports", "glpi_plugin_fusinvsnmp_networkports");
    $migration->renameTable("glpi_plugin_fusioninventory_construct_device", "glpi_plugin_fusinvsnmp_constructdevices");
    $migration->renameTable("glpi_plugin_fusioninventory_construct_mibs", "glpi_plugin_fusioninventory_snmpmodelconstructdevice_miboids");
    $migration->renameTable("glpi_plugin_fusioninventory_networking", "glpi_plugin_fusioninventory_networkequipments");
    $migration->renameTable("glpi_plugin_fusioninventory_networking_ifaddr", "glpi_plugin_fusinvsnmp_networkequipmentips");
    $migration->renameTable("glpi_plugin_fusioninventory_printers", "glpi_plugin_fusinvsnmp_printers");
    $migration->renameTable("glpi_plugin_fusioninventory_printers_cartridges", "glpi_plugin_fusinvsnmp_printercartridges");
    $migration->renameTable("glpi_plugin_fusioninventory_printers_history", "glpi_plugin_fusinvsnmp_printerlogs");
    $migration->renameTable("glpi_plugin_fusioninventory_model_infos", "glpi_plugin_fusioninventory_snmpmodels");
    $migration->renameTable("glpi_plugin_fusioninventory_mib_networking", "glpi_plugin_fusinvsnmp_modelmibs");
    $migration->renameTable("glpi_plugin_fusioninventory_snmp_connection", "glpi_plugin_fusinvsnmp_configsecurities");
    $migration->renameTable("glpi_plugin_fusioninventory_snmp_history", "glpi_plugin_fusinvsnmp_networkportlogs");
    $migration->renameTable("glpi_plugin_fusioninventory_snmp_history_connections", "glpi_plugin_fusinvsnmp_networkportconnectionlogs");
    $a_droptable = array('glpi_plugin_fusioninventory_agents_inventory_state', 'glpi_plugin_fusioninventory_config_modules', 'glpi_plugin_fusioninventory_connection_stats', 'glpi_plugin_fusioninventory_discovery', 'glpi_plugin_fusioninventory_errors', 'glpi_plugin_fusioninventory_lockable', 'glpi_plugin_fusioninventory_connection_history', 'glpi_plugin_fusioninventory_walks', 'glpi_plugin_fusioninventory_config_snmp_history', 'glpi_plugin_fusioninventory_config_snmp_networking', 'glpi_plugin_fusioninventory_task', 'glpi_plugin_fusinvinventory_pcidevices', 'glpi_plugin_fusinvinventory_pcivendors', 'glpi_plugin_fusinvinventory_usbdevices', 'glpi_plugin_fusinvinventory_usbvendors', 'glpi_plugin_fusinvsnmp_constructdevicewalks', 'glpi_plugin_fusioninventory_snmpmodelmiblabels', 'glpi_plugin_fusioninventory_snmpmodelmibobjects', 'glpi_plugin_fusioninventory_snmpmodelmiboids', 'glpi_plugin_fusioninventory_snmpmodelconstructdevices', 'glpi_plugin_fusioninventory_snmpmodelconstructdevicewalks' . 'glpi_plugin_fusioninventory_snmpmodelconstructdevices_users', 'glpi_plugin_fusioninventory_snmpmodelconstructdevice_miboids', 'glpi_plugin_fusioninventory_snmpmodelmibs', 'glpi_plugin_fusioninventory_snmpmodels', 'glpi_plugin_fusioninventory_snmpmodeldevices', 'glpi_plugin_fusinvsnmp_constructdevice_miboids', 'glpi_plugin_fusinvsnmp_constructdevices', 'glpi_plugin_fusinvsnmp_constructdevices_users', 'glpi_plugin_fusinvsnmp_miblabels', 'glpi_plugin_fusinvsnmp_mibobjects', 'glpi_plugin_fusinvsnmp_miboids', 'glpi_plugin_fusinvsnmp_modeldevices', 'glpi_plugin_fusinvsnmp_modelmibs', 'glpi_plugin_fusinvsnmp_models', 'glpi_plugin_fusioninventory_construct_walks');
    foreach ($a_droptable as $newTable) {
        $migration->dropTable($newTable);
    }
    /*
       $a_table = array();
    
       //table name
       $a_table['name'] = '';
       $a_table['oldname'] = array(
       );
    
       // fields : fields that are new, have changed type or just stay the same
       //    array(
       //        <fieldname> = array(
       //            'type' => <type>, 'value' => <value>)
       //    );
       $a_table['fields'] = array(
    
       );
    
       // oldfields = fields that need to be removed
       //    array( 'field0', 'field1', ...);
       $a_table['oldfields'] = array(
       );
    
       // renamefields = fields that need to be renamed
       //    array('oldname' = 'newname', ...)
       $a_table['renamefields'] = array(
       );
    
       // keys : new, changed or not
       //    array( 'field' => <fields>, 'name' => <keyname> , 'type' => <keytype>)
       // <fields> : fieldnames needed by the key
       //            ex : array('field0' , 'field1' ...)
       //            ex : 'fieldname'
       // <keyname> : the name of the key (if blank, the fieldname is used)
       // <type> : the type of key (ex: INDEX, ...)
       $a_table['keys'] = array(
       );
    
       // oldkeys : keys that need to be removed
       //    array( 'key0', 'key1', ... )
       $a_table['oldkeys'] = array(
       );
    */
    //Push task functionnality
    $migration->addField('glpi_plugin_fusioninventory_tasks', 'last_agent_wakeup', 'datetime');
    $migration->addField('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_counter', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_time', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_counter');
    $migration->migrationOneTable('glpi_plugin_fusioninventory_tasks');
    /*
     *  Table glpi_plugin_fusioninventory_agents
     */
    $newTable = "glpi_plugin_fusioninventory_agents";
    $prepare_agentConfig = array();
    if (TableExists("glpi_plugin_tracker_agents") and FieldExists("glpi_plugin_tracker_agents", "ifaddr_start")) {
        $query = "SELECT * FROM `glpi_plugin_tracker_agents`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $prepare_rangeip[] = array("ip_start" => $data['ifaddr_start'], "ip_end" => $data['ifaddr_end'], "name" => $data['name']);
            $prepare_agentConfig[] = array("name" => $data["name"], "lock" => $data['lock'], "threads_networkinventory" => $data['nb_process_query'], "threads_networkdiscovery" => $data['nb_process_discovery']);
        }
    } else {
        if (TableExists("glpi_plugin_tracker_agents") and FieldExists("glpi_plugin_tracker_agents", "core_discovery")) {
            $query = "SELECT * FROM `glpi_plugin_tracker_agents`";
            $result = $DB->query($query);
            while ($data = $DB->fetch_array($result)) {
                $prepare_agentConfig[] = array("name" => $data["name"], "lock" => $data['lock'], "threads_networkinventory" => $data['threads_query'], "threads_networkdiscovery" => $data['threads_discovery']);
            }
        } else {
            if (TableExists("glpi_plugin_fusioninventory_agents")) {
                if (FieldExists($newTable, "module_snmpquery")) {
                    $query = "SELECT * FROM `glpi_plugin_fusioninventory_agents`";
                    $result = $DB->query($query);
                    while ($data = $DB->fetch_array($result)) {
                        $prepare_agentConfig[] = array("id" => $data["ID"], "threads_networkinventory" => $data['threads_query'], "threads_networkdiscovery" => $data['threads_discovery'], "NETORKINVENTORY" => $data['module_snmpquery'], "NETWORKDISCOVERY" => $data['module_netdiscovery'], "INVENTORY" => $data['module_inventory'], "WAKEONLAN" => $data['module_wakeonlan']);
                    }
                }
            }
        }
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_agents';
    $a_table['oldname'] = array('glpi_plugin_tracker_agents');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '1');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['last_contact'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['version'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['lock'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['device_id'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['token'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['useragent'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['tag'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['threads_networkdiscovery'] = array('type' => "int(4) NOT NULL DEFAULT '1' COMMENT 'array(xmltag=>value)'", 'value' => NULL);
    $a_table['fields']['threads_networkinventory'] = array('type' => "int(4) NOT NULL DEFAULT '1' COMMENT 'array(xmltag=>value)'", 'value' => NULL);
    $a_table['fields']['senddico'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['timeout_networkdiscovery'] = array('type' => "int(4) NOT NULL DEFAULT '0' COMMENT 'Network Discovery task timeout'", 'value' => NULL);
    $a_table['fields']['timeout_networkinventory'] = array('type' => "int(4) NOT NULL DEFAULT '0' COMMENT 'Network Inventory task timeout'", 'value' => NULL);
    $a_table['fields']['agent_port'] = array('type' => 'varchar(6)', 'value' => NULL);
    $a_table['oldfields'] = array('module_snmpquery', 'module_netdiscovery', 'module_inventory', 'module_wakeonlan', 'core_discovery', 'threads_discovery', 'core_query', 'threads_query', 'tracker_agent_version', 'logs', 'fragment', 'itemtype', 'device_type');
    $a_table['renamefields'] = array();
    $a_table['renamefields']['ID'] = 'id';
    $a_table['renamefields']['last_agent_update'] = 'last_contact';
    $a_table['renamefields']['fusioninventory_agent_version'] = 'version';
    $a_table['renamefields']['key'] = 'device_id';
    $a_table['renamefields']['on_device'] = 'computers_id';
    $a_table['renamefields']['items_id'] = 'computers_id';
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'device_id', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array('key');
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_agentmodules
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_agentmodules';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['modulename'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['is_active'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['exceptions'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['oldfields'][] = 'plugins_id';
    $a_table['oldfields'][] = 'entities_id';
    $a_table['oldfields'][] = 'url';
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'modulename', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array('unicity', 'entities_id');
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Add Deploy module
     */
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='DEPLOY'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_agentmodules`\n            (`modulename`, `is_active`, `exceptions`)\n         VALUES ('DEPLOY', '0', '" . exportArrayToDB(array()) . "')";
        $DB->query($query_ins);
    }
    /*
     * Add WakeOnLan module appear in version 2.3.0
     */
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='WAKEONLAN'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_agentmodules`\n            (`modulename`, `is_active`, `exceptions`)\n         VALUES ('WAKEONLAN', '0', '" . exportArrayToDB(array()) . "')";
        $DB->query($query_ins);
    }
    /*
     * Add SNMPQUERY module if not present
     */
    $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules`\n      SET `modulename`='NETWORKINVENTORY'\n      WHERE `modulename`='SNMPQUERY'";
    $DB->query($query);
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='NETWORKINVENTORY'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $agentmodule = new PluginFusioninventoryAgentmodule();
        $input = array();
        $input['modulename'] = "NETWORKINVENTORY";
        $input['is_active'] = 0;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Add NETDISCOVERY module if not present
     */
    $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules`\n      SET `modulename`='NETWORKDISCOVERY'\n      WHERE `modulename`='NETDISCOVERY'";
    $DB->query($query);
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='NETWORKDISCOVERY'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $agentmodule = new PluginFusioninventoryAgentmodule();
        $input = array();
        $input['modulename'] = "NETWORKDISCOVERY";
        $input['is_active'] = 0;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Add INVENTORY module if not present
     */
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='INVENTORY'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $agentmodule = new PluginFusioninventoryAgentmodule();
        $input = array();
        $input['modulename'] = "INVENTORY";
        $input['is_active'] = 1;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Table glpi_plugin_fusioninventory_configs
     */
    $newTable = "glpi_plugin_fusioninventory_configs";
    if (TableExists('glpi_plugin_tracker_config')) {
        if (FieldExists('glpi_plugin_tracker_config', 'ssl_only')) {
            $query = "SELECT * FROM `glpi_plugin_tracker_config`\n               LIMIT 1";
            $result = $DB->query($query);
            if ($DB->numrows($result) > 0) {
                $data = $DB->fetch_assoc($result);
                $prepare_Config['ssl_only'] = $data['ssl_only'];
            }
        }
        //         $query = "SELECT *  FROM `glpi_plugin_tracker_config`
        //            WHERE `type`='version'
        //            LIMIT 1, 10";
        //         $result=$DB->query($query);
        //         while ($data=$DB->fetch_array($result)) {
        //            $DB->query("DELETE FROM `glpi_plugin_tracker_config`
        //               WHERE `ID`='".$data['ID']."'");
        //         }
    }
    if (TableExists('glpi_plugin_fusioninventory_configs')) {
        $id = 'id';
        if (FieldExists('glpi_plugin_fusioninventory_configs', 'ID')) {
            $id = 'ID';
        }
        $query = "SELECT *  FROM `glpi_plugin_fusioninventory_configs`\n            WHERE `type`='version'\n            LIMIT 1, 10";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $DB->query("DELETE FROM `glpi_plugin_fusioninventory_configs`\n               WHERE `" . $id . "`='" . $data[$id] . "'");
        }
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_configs';
    $a_table['oldname'] = array('glpi_plugin_tracker_config');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['type'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['oldfields'][] = 'version';
    $a_table['oldfields'][] = 'URL_agent_conf';
    $a_table['oldfields'][] = 'ssl_only';
    $a_table['oldfields'][] = 'authsnmp';
    $a_table['oldfields'][] = 'inventory_frequence';
    $a_table['oldfields'][] = 'criteria1_ip';
    $a_table['oldfields'][] = 'criteria1_name';
    $a_table['oldfields'][] = 'criteria1_serial';
    $a_table['oldfields'][] = 'criteria1_macaddr';
    $a_table['oldfields'][] = 'criteria2_ip';
    $a_table['oldfields'][] = 'criteria2_name';
    $a_table['oldfields'][] = 'criteria2_serial';
    $a_table['oldfields'][] = 'criteria2_macaddr';
    $a_table['oldfields'][] = 'delete_agent_process';
    $a_table['oldfields'][] = 'activation_history';
    $a_table['oldfields'][] = 'activation_connection';
    $a_table['oldfields'][] = 'activation_snmp_computer';
    $a_table['oldfields'][] = 'activation_snmp_networking';
    $a_table['oldfields'][] = 'activation_snmp_peripheral';
    $a_table['oldfields'][] = 'activation_snmp_phone';
    $a_table['oldfields'][] = 'activation_snmp_printer';
    $a_table['oldfields'][] = 'plugins_id';
    $a_table['oldfields'][] = 'module';
    $a_table['renamefields'] = array();
    $a_table['renamefields']['ID'] = 'id';
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => array("type"), 'name' => 'unicity', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_entities
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_entities';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['transfers_id_auto'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['agent_base_url'] = array('type' => 'string', 'value' => '');
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => array('entities_id', 'transfers_id_auto'), 'name' => 'entities_id', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    if (countElementsInTable($a_table['name']) == 0) {
        $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='transfers_id_auto'");
        $transfers_id_auto = 0;
        if (count($a_configs) > 0) {
            $a_config = current($a_configs);
            $transfers_id_auto = $a_config['value'];
        }
        $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='agent_base_url'");
        $agent_base_url = '';
        if (count($a_configs) > 0) {
            $a_config = current($a_configs);
            $agent_base_url = $a_config['value'];
        }
        $DB->query("INSERT INTO `glpi_plugin_fusioninventory_entities`\n               (`entities_id`, `transfers_id_auto`, `agent_base_url`)\n            VALUES ('0', '" . $transfers_id_auto . "', '" . $agent_base_url . "');");
    } else {
        if (countElementsInTable($a_table['name']) > 0) {
            $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='agent_base_url'");
            $agent_base_url = '';
            if (count($a_configs) > 0) {
                $a_config = current($a_configs);
                $agent_base_url = $a_config['value'];
                $DB->query("UPDATE `glpi_plugin_fusioninventory_entities`\n                  SET `agent_base_url` = '" . $agent_base_url . "'\n                  ;");
            }
        }
    }
    /*
     * Table glpi_plugin_fusioninventory_credentials
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_credentials';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['name'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['username'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['password'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['itemtype'] = array('type' => 'string', 'value' => "");
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    // Fix itemtype changed in 0.84
    $DB->query("UPDATE `glpi_plugin_fusioninventory_credentials`\n         SET `itemtype`='PluginFusioninventoryInventoryComputerESX'\n         WHERE `itemtype`='PluginFusinvinventoryVmwareESX'");
    /*
     * Table glpi_plugin_fusioninventory_credentialips
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_credentialips';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_credentials_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['name'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['ip'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_ipranges
     */
    $newTable = "glpi_plugin_fusioninventory_ipranges";
    if (TableExists("glpi_plugin_tracker_rangeip")) {
        // Get all data to create task
        $query = "SELECT * FROM `glpi_plugin_tracker_rangeip`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            if ($data['discover'] == '1') {
                $prepare_task[] = array("agents_id" => $data['FK_tracker_agents'], "ipranges_id" => $data['ID'], "netdiscovery" => "1");
            }
            if ($data['query'] == '1') {
                $prepare_task[] = array("agents_id" => $data['FK_tracker_agents'], "ipranges_id" => $data['ID'], "snmpquery" => "1");
            }
        }
    }
    if (TableExists("glpi_plugin_fusioninventory_rangeip") and FieldExists("glpi_plugin_fusioninventory_rangeip", "FK_fusioninventory_agents_discover")) {
        // Get all data to create task
        $query = "SELECT * FROM `glpi_plugin_fusioninventory_rangeip`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            if ($data['discover'] == '1') {
                $prepare_task[] = array("agents_id" => $data['FK_fusioninventory_agents_discover'], "ipranges_id" => $data['ID'], "netdiscovery" => "1");
            }
            if ($data['query'] == '1') {
                $prepare_task[] = array("agents_id" => $data['FK_fusioninventory_agents_query'], "ipranges_id" => $data['ID'], "snmpquery" => "1");
            }
        }
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_ipranges';
    $a_table['oldname'] = array('glpi_plugin_tracker_rangeip', 'glpi_plugin_fusinvsnmp_ipranges');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'name' => array('type' => 'string', 'value' => NULL), 'entities_id' => array('type' => 'integer', 'value' => NULL), 'ip_start' => array('type' => 'string', 'value' => NULL), 'ip_end' => array('type' => 'string', 'value' => NULL));
    $a_table['oldfields'] = array('FK_tracker_agents', 'discover', 'query', 'FK_fusioninventory_agents_discover', 'FK_fusioninventory_agents_query', 'construct_device_id', 'log', 'comment');
    $a_table['renamefields'] = array('ID' => 'id', 'ifaddr_start' => 'ip_start', 'ifaddr_end' => 'ip_end', 'FK_entities' => 'entities_id');
    $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'INDEX'));
    $a_table['oldkeys'] = array('FK_tracker_agents', 'FK_tracker_agents_2');
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_locks
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_locks';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['tablename'] = array('type' => "varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT ''", 'value' => NULL);
    $a_table['fields']['items_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['tablefields'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array('itemtype');
    $a_table['renamefields'] = array();
    $a_table['renamefields']['fields'] = 'tablefields';
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'tablename', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'items_id', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_ipranges_configsecurities
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_ipranges_configsecurities';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['plugin_fusioninventory_ipranges_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_configsecurities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['rank'] = array('type' => 'integer', 'value' => '1');
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_mappings
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_mappings';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['itemtype'] = array('type' => "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL", 'value' => NULL);
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['table'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['tablefield'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['locale'] = array('type' => "int(4) NOT NULL DEFAULT '0'", 'value' => NULL);
    $a_table['fields']['shortlocale'] = array('type' => 'int(4) DEFAULT NULL', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'itemtype', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'table', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'tablefield', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    pluginFusioninventoryUpdatemapping();
    if (TableExists('glpi_plugin_fusioninventory_profiles')) {
        /*
         * Table glpi_plugin_fusioninventory_profiles
         */
        $a_table = array();
        $a_table['name'] = 'glpi_plugin_fusioninventory_profiles';
        $a_table['oldname'] = array();
        $a_table['fields'] = array();
        $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
        $a_table['fields']['type'] = array('type' => 'string', 'value' => '');
        $a_table['fields']['right'] = array('type' => 'char', 'value' => NULL);
        $a_table['fields']['plugins_id'] = array('type' => 'integer', 'value' => NULL);
        $a_table['fields']['profiles_id'] = array('type' => 'integer', 'value' => NULL);
        $a_table['oldfields'] = array('name', 'interface', 'is_default', 'snmp_networking', 'snmp_printers', 'snmp_models', 'snmp_authentification', 'rangeip', 'agents', 'remotecontrol', 'agentsprocesses', 'unknowndevices', 'reports', 'deviceinventory', 'netdiscovery', 'snmp_query', 'wol', 'configuration');
        $a_table['renamefields'] = array();
        $a_table['renamefields']['ID'] = 'id';
        $a_table['keys'] = array();
        $a_table['oldkeys'] = array();
        migrateTablesFusionInventory($migration, $a_table);
        // Remove multiple lines can have problem with unicity
        $query = "SELECT * , count(`id`) AS cnt\n               FROM `glpi_plugin_fusioninventory_profiles`\n               GROUP BY `type`,`plugins_id`,`profiles_id`\n               HAVING cnt >1\n               ORDER BY cnt";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $queryd = "DELETE FROM `glpi_plugin_fusioninventory_profiles`\n                  WHERE `type`='" . $data['type'] . "'\n                     AND `plugins_id`='" . $data['plugins_id'] . "'\n                     AND `profiles_id`='" . $data['profiles_id'] . "'\n                  ORDER BY `id` DESC\n                  LIMIT " . ($data['cnt'] - 1) . " ";
            $DB->query($queryd);
        }
        $a_table = array();
        $a_table['name'] = 'glpi_plugin_fusioninventory_profiles';
        $a_table['oldname'] = array();
        $a_table['fields'] = array();
        $a_table['oldfields'] = array();
        $a_table['renamefields'] = array();
        $a_table['keys'] = array();
        $a_table['keys'][] = array('field' => array("type", "plugins_id", "profiles_id"), 'name' => 'unicity', 'type' => 'UNIQUE');
        $a_table['oldkeys'] = array();
        migrateTablesFusionInventory($migration, $a_table);
    }
    /*
     * Update tasks related database tables
     */
    pluginFusioninventoryUpdateTasks($migration, $plugins_id);
    /*
     * Table glpi_plugin_fusioninventory_timeslots
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_timeslots';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '0');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_timeslotentries
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_timeslotentries';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['plugin_fusioninventory_timeslots_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '0');
    $a_table['fields']['day'] = array('type' => 'bool', 'value' => 1);
    $a_table['fields']['begin'] = array('type' => 'int(11) DEFAULT NULL', 'value' => NULL);
    $a_table['fields']['end'] = array('type' => 'int(11) DEFAULT NULL', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_unmanageds
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_unmanageds';
    $a_table['oldname'] = array('glpi_plugin_fusioninventory_unknowndevices', 'glpi_plugin_tracker_unknown_device');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['locations_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_deleted'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['users_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['otherserial'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['contact'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['domain'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['item_type'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['accepted'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_agents_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['ip'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['hub'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['states_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['sysdescr'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_configsecurities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_dynamic'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['serialized_inventory'] = array('type' => 'longblob', 'value' => NULL);
    $a_table['oldfields'] = array('dnsname', 'snmp', 'FK_model_infos', 'FK_snmp_connection', 'FK_agent', 'mac', 'ifmac', 'plugin_fusinvsnmp_models_id', 'plugin_fusioninventory_snmpmodels_id', 'is_template');
    $a_table['renamefields'] = array('ID' => 'id', 'comments' => 'comment', 'type' => 'item_type', 'ifaddr' => 'ip', 'FK_entities' => 'entities_id', 'location' => 'locations_id', 'deleted' => 'is_deleted', 'plugin_fusinvsnmp_configsecurities_id' => 'plugin_fusioninventory_configsecurities_id');
    $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'plugin_fusioninventory_agents_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'is_deleted', 'name' => '', 'type' => 'INDEX'), array('field' => 'date_mod', 'name' => '', 'type' => 'INDEX'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    if (TableExists('glpi_plugin_fusinvsnmp_unknowndevices')) {
        $query = "SELECT * FROM `glpi_plugin_fusinvsnmp_unknowndevices`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $DB->query("UPDATE `glpi_plugin_fusioninventory_unmanageds`\n               SET `sysdescr`='" . $data['sysdescr'] . "',\n                   `plugin_fusioninventory_configsecurities_id`='" . $data['plugin_fusinvsnmp_configsecurities_id'] . "'\n               WHERE `id`='" . $data['plugin_fusioninventory_unknowndevices_id'] . "'");
        }
        $migration->dropTable('glpi_plugin_fusinvsnmp_unknowndevices');
    }
    /*
     * Table glpi_plugin_fusioninventory_ignoredimportdevices
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_ignoredimportdevices';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['itemtype'] = array('type' => "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL", 'value' => NULL);
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['ip'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['mac'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['rules_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['method'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['uuid'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputercriterias
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputercriterias';
    $a_table['oldname'] = array('glpi_plugin_fusinvinventory_criterias');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_rulematchedlogs
     */
    $newTable = "glpi_plugin_fusioninventory_rulematchedlogs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "date", "datetime DEFAULT NULL");
    $migration->addField($newTable, "items_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "itemtype", "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "rules_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "method", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerblacklists
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputerblacklists';
    $a_table['oldname'] = array('glpi_plugin_fusinvinventory_blacklists');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['plugin_fusioninventory_criterium_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'plugin_fusioninventory_criterium_id', 'name' => '', 'type' => 'KEY');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    $DB->list_fields($newTable, FALSE);
    pluginFusioninventorychangeDisplayPreference("5153", "PluginFusioninventoryUnknownDevice");
    pluginFusioninventorychangeDisplayPreference("5158", "PluginFusioninventoryAgent");
    /*
     *  Udpate criteria for blacklist
     */
    $a_criteria = array();
    $a_criteria['Serial number'] = 'ssn';
    $a_criteria['uuid'] = 'uuid';
    $a_criteria['Mac address'] = 'macAddress';
    $a_criteria['Windows product key'] = 'winProdKey';
    $a_criteria['Model'] = 'smodel';
    $a_criteria['storage serial'] = 'storagesSerial';
    $a_criteria['drives serial'] = 'drivesSerial';
    $a_criteria['Asset Tag'] = 'assetTag';
    $a_criteria['Computer name'] = 'name';
    $a_criteria['Manufacturer'] = 'manufacturer';
    foreach ($a_criteria as $name => $comment) {
        $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`\n            WHERE `name`='" . $name . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_inventorycomputercriterias`\n               (`name`, `comment`)\n               VALUES ('" . $name . "', '" . $comment . "')";
            $DB->query($query_ins);
        }
    }
    $a_criteria = array();
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $a_criteria[$data['comment']] = $data['id'];
    }
    /*
     * Update blacklist
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerblacklists";
    // * ssn
    $a_input = array('N/A', '(null string)', 'INVALID', 'SYS-1234567890', 'SYS-9876543210', 'SN-12345', 'SN-1234567890', '1111111111', '1111111', '1', '0123456789', '12345', '123456', '1234567', '12345678', '123456789', '1234567890', '123456789000', '12345678901234567', '0000000000', '000000000', '00000000', '0000000', '0000000', 'NNNNNNN', 'xxxxxxxxxxx', 'EVAL', 'IATPASS', 'none', 'To Be Filled By O.E.M.', 'Tulip Computers', 'Serial Number xxxxxx', 'SN-123456fvgv3i0b8o5n6n7k', 'Unknow', 'System Serial Number', 'MB-1234567890', '0', 'empty', 'Not Specified');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['ssn'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['ssn'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * uuid
    $a_input = array('FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF', '03000200-0400-0500-0006-000700080009', '6AB5B300-538D-1014-9FB5-B0684D007B53', '01010101-0101-0101-0101-010101010101');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['uuid'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['uuid'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * macAddress
    $a_input = array('20:41:53:59:4e:ff', '02:00:4e:43:50:49', 'e2:e6:16:20:0a:35', 'd2:0a:2d:a0:04:be', '00:a0:c6:00:00:00', 'd2:6b:25:2f:2c:e7', '33:50:6f:45:30:30', '0a:00:27:00:00:00', '00:50:56:C0:00:01', '00:50:56:C0:00:08', '02:80:37:EC:02:00', '50:50:54:50:30:30', '24:b6:20:52:41:53');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['macAddress'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['macAddress'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * smodel
    $a_input = array('Unknow', 'To Be Filled By O.E.M.', '*', 'System Product Name', 'Product Name', 'System Name');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['smodel'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['smodel'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * manufacturer
    $a_input = array('System manufacturer');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['manufacturer'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['manufacturer'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * ip
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`\n            WHERE `name`='IP'";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $DB->query("INSERT INTO `glpi_plugin_fusioninventory_inventorycomputercriterias`\n               (`id`, `name`, `comment`) VALUES\n               (11, 'IP', 'IP')");
    }
    $a_criteria = array();
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $a_criteria[$data['comment']] = $data['id'];
    }
    $a_input = array('0.0.0.0');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['IP'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['IP'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerantiviruses
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerantiviruses";
    $migration->renameTable("glpi_plugin_fusinvinventory_antivirus", $newTable);
    if (!TableExists($newTable)) {
        $DB->query("CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1");
    }
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "manufacturers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "version", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "is_active", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "uptodate", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "name");
    $migration->addKey($newTable, "version");
    $migration->addKey($newTable, "is_active");
    $migration->addKey($newTable, "uptodate");
    $migration->addKey($newTable, "computers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerbatteries
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerbatteries";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "computers_id", "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "manufacturers_id", "manufacturers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "serial", "serial", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "capacity", "capacity", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "date", "date", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerchemistries_id", "plugin_fusioninventory_inventorycomputerchemistries_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "voltage", "voltage", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "manufacturers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "serial", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "capacity", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "date", "datetime DEFAULT NULL");
    $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerchemistries_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "voltage", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "computers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerchemistries
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerchemistries";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "name");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputercomputers
     */
    if (TableExists("glpi_plugin_fusinvinventory_computers") and FieldExists("glpi_plugin_fusinvinventory_computers", "uuid")) {
        $Computer = new Computer();
        $sql = "SELECT * FROM `glpi_plugin_fusinvinventory_computers`";
        $result = $DB->query($sql);
        while ($data = $DB->fetch_array($result)) {
            if ($Computer->getFromDB($data['items_id'])) {
                $input = array();
                $input['id'] = $data['items_id'];
                $input['uuid'] = $data['uuid'];
                $Computer->update($input);
            }
        }
        $sql = "DROP TABLE `glpi_plugin_fusinvinventory_computers`";
        $DB->query($sql);
    }
    if (TableExists("glpi_plugin_fusinvinventory_tmp_agents")) {
        $sql = "DROP TABLE `glpi_plugin_fusinvinventory_tmp_agents`";
        $DB->query($sql);
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
    $a_table['oldname'] = array('glpi_plugin_fusinvinventory_computers');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['bios_date'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['bios_version'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['bios_assettag'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['bios_manufacturers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['operatingsystem_installationdate'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['winowner'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['wincompany'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['last_fusioninventory_update'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['remote_addr'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_computerarchs_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['serialized_inventory'] = array('type' => 'longblob', 'value' => "");
    $a_table['fields']['is_entitylocked'] = array('type' => 'bool', 'value' => "0");
    $a_table['fields']['oscomment'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'last_fusioninventory_update', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    // Migrate libserialization
    require_once GLPI_ROOT . "/plugins/fusioninventory/inc/inventorycomputercomputer.class.php";
    $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
    if (TableExists('glpi_plugin_fusinvinventory_libserialization')) {
        $query = "SELECT * FROM `glpi_plugin_fusinvinventory_libserialization`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $a_pfcomputer = array();
            $a_pfcomputer = current($pfInventoryComputerComputer->find("`computers_id`='" . $data['computers_id'] . "'", "", 1));
            if (empty($a_pfcomputer)) {
                // Add
                if (countElementsInTable("glpi_computers", "`id`='" . $data['computers_id'] . "'") > 0) {
                    $input = array();
                    $input['computers_id'] = $data['computers_id'];
                    $input['last_fusioninventory_update'] = $data['last_fusioninventory_update'];
                    $pfInventoryComputerComputer->add($input);
                }
            } else {
                // Update
                $a_pfcomputer['last_fusioninventory_update'] = $data['last_fusioninventory_update'];
                $pfInventoryComputerComputer->update($a_pfcomputer);
            }
        }
    }
    $migration->dropTable('glpi_plugin_fusinvinventory_libserialization');
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerstats
     */
    if (!TableExists("glpi_plugin_fusioninventory_inventorycomputerstats")) {
        $a_table = array();
        $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputerstats';
        $a_table['oldname'] = array();
        $a_table['fields'] = array();
        $a_table['fields']['id'] = array('type' => "smallint(3) NOT NULL AUTO_INCREMENT", 'value' => '');
        $a_table['fields']['day'] = array('type' => "smallint(3) NOT NULL DEFAULT '0'", 'value' => '');
        $a_table['fields']['hour'] = array('type' => "tinyint(2) NOT NULL DEFAULT '0'", 'value' => '');
        $a_table['fields']['counter'] = array('type' => 'integer', 'value' => NULL);
        $a_table['oldfields'] = array();
        $a_table['renamefields'] = array();
        $a_table['keys'] = array();
        $a_table['oldkeys'] = array();
        migrateTablesFusionInventory($migration, $a_table);
        require_once GLPI_ROOT . "/plugins/fusioninventory/inc/inventorycomputerstat.class.php";
        PluginFusioninventoryInventoryComputerStat::init();
    }
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerstorages
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerstorages";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "uuid", "uuid", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "totalsize", "totalsize", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "freesize", "freesize", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstoragetypes_id", "plugin_fusioninventory_inventorycomputerstoragetypes_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "computers_id", "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "uuid", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "totalsize", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "freesize", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstoragetypes_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "uuid");
    $migration->addKey($newTable, "computers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerstoragetypes
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerstoragetypes";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "level", "level", "tinyint(2) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "level", "tinyint(2) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "level");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerstorages_storages
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerstorages_storages";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1", "plugin_fusioninventory_inventorycomputerstorages_id_1", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2", "plugin_fusioninventory_inventorycomputerstorages_id_2", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1");
    $migration->addKey($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * glpi_plugin_fusioninventory_configlogfields
     */
    $newTable = "glpi_plugin_fusioninventory_configlogfields";
    $migration->renameTable("glpi_plugin_fusioninventory_config_snmp_history", $newTable);
    $migration->renameTable("glpi_plugin_fusinvsnmp_configlogfields", $newTable);
    if (TableExists($newTable)) {
        if (FieldExists($newTable, "field")) {
            $query = "SELECT * FROM `" . $newTable . "`";
            $result = $DB->query($query);
            while ($data = $DB->fetch_array($result)) {
                $pfMapping = new PluginFusioninventoryMapping();
                $mapping = 0;
                if ($mapping = $pfMapping->get("NetworkEquipment", $data['field'])) {
                    $queryu = "UPDATE `" . $newTable . "`\n                     SET `field`='" . $mapping['id'] . "'\n                     WHERE `field`='" . $data['field'] . "'";
                    $DB->query($queryu);
                }
            }
        }
    }
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(8) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "id", "id", "int(8) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "days", "days", "int(255) NOT NULL DEFAULT '-1'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(8) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "field", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(8) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "days", "int(255) NOT NULL DEFAULT '-1'");
    $migration->addKey($newTable, "plugin_fusioninventory_mappings_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    $configLogField = new PluginFusioninventoryConfigLogField();
    $configLogField->initConfig();
    /*
     * Table glpi_plugin_fusioninventory_networkportconnectionlogs
     */
    $newTable = "glpi_plugin_fusioninventory_networkportconnectionlogs";
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkportconnectionlogs", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "date", "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "date_mod", "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "creation", "creation", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_port_source", "networkports_id_source", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "networkports_id_source", "networkports_id_source", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_port_destination", "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "networkports_id_destination", "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_agentprocesses_id", "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->dropField($newTable, "process_number");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addField($newTable, "creation", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "networkports_id_source", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array("networkports_id_source", "networkports_id_destination", "plugin_fusioninventory_agentprocesses_id"), "networkports_id_source");
    $migration->addKey($newTable, "date_mod");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_networkporttypes
     */
    $newTable = "glpi_plugin_fusioninventory_networkporttypes";
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkporttypes", $newTable);
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "number", "number", "int(4) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "othername", "othername", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "import", "import", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "number", "int(4) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "othername", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "import", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_printers
     */
    $newTable = "glpi_plugin_fusioninventory_printers";
    $migration->renameTable("glpi_plugin_fusinvsnmp_printers", $newTable);
    $migration->renameTable("glpi_plugin_tracker_printers", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "sysdescr", "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusinvsnmp_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "frequence_days", "frequence_days", "int(5) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, "last_fusioninventory_update", "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_snmp_connection", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "last_tracker_update", "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->dropKey($newTable, "FK_printers");
    $migration->dropKey($newTable, "FK_snmp_connection");
    $migration->dropKey($newTable, "plugin_fusioninventory_snmpmodels_id");
    $migration->migrationOneTable($newTable);
    $migration->dropField($newTable, "plugin_fusinvsnmp_models_id");
    $migration->dropField($newTable, "plugin_fusioninventory_snmpmodels_id");
    $migration->dropField($newTable, "FK_model_infos");
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "frequence_days", "int(5) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->addField($newTable, "serialized_inventory", "longblob");
    $migration->addKey($newTable, "plugin_fusioninventory_configsecurities_id");
    $migration->addKey($newTable, "printers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_printerlogs
     */
    $newTable = "glpi_plugin_fusioninventory_printerlogs";
    $migration->renameTable("glpi_plugin_fusinvsnmp_printerlogs", $newTable);
    $migration->renameTable("glpi_plugin_tracker_printers_history", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "date", "date", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "pages_total", "pages_total", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_n_b", "pages_n_b", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_color", "pages_color", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_recto_verso", "pages_recto_verso", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "scanned", "scanned", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_total_print", "pages_total_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_n_b_print", "pages_n_b_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_color_print", "pages_color_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_total_copy", "pages_total_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_n_b_copy", "pages_n_b_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_color_copy", "pages_color_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_total_fax", "pages_total_fax", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "date", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addField($newTable, "pages_total", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_n_b", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_color", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_recto_verso", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "scanned", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_total_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_n_b_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_color_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_total_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_n_b_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_color_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_total_fax", "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array("printers_id", "date"), "printers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     *  glpi_plugin_fusioninventory_printercartridges
     */
    $newTable = "glpi_plugin_fusioninventory_printercartridges";
    $migration->renameTable("glpi_plugin_fusinvsnmp_printercartridges", $newTable);
    $migration->renameTable("glpi_plugin_tracker_printers_cartridges", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` bigint(100) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "bigint(100) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "cartridges_id", "cartridges_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "state", "state", "int(3) NOT NULL DEFAULT '100'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "bigint(100) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_cartridges", "cartridges_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    // Update with mapping
    if (FieldExists($newTable, "object_name")) {
        $query = "SELECT * FROM `" . $newTable . "`\n               GROUP BY `object_name`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $pfMapping = new PluginFusioninventoryMapping();
            $mapping = 0;
            if ($mapping = $pfMapping->get("Printer", $data['object_name'])) {
                $DB->query("UPDATE `" . $newTable . "`\n                     SET `plugin_fusioninventory_mappings_id`='" . $mapping['id'] . "'\n                        WHERE `object_name`='" . $data['object_name'] . "'");
            }
        }
    }
    $migration->dropField($newTable, "object_name");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "bigint(100) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "cartridges_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "state", "int(3) NOT NULL DEFAULT '100'");
    $migration->addKey($newTable, "printers_id");
    $migration->addKey($newTable, "plugin_fusioninventory_mappings_id");
    $migration->addKey($newTable, "cartridges_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * glpi_plugin_fusioninventory_networkports
     */
    $newTable = "glpi_plugin_fusioninventory_networkports";
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkports", $newTable);
    $migration->renameTable("glpi_plugin_tracker_networking_ports", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "networkports_id", "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifmtu", "ifmtu", "int(8) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifspeed", "ifspeed", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifinternalstatus", "ifinternalstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "ifconnectionstatus", "ifconnectionstatus", "int(8) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "iflastchange", "iflastchange", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "ifinoctets", "ifinoctets", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifinerrors", "ifinerrors", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifoutoctets", "ifoutoctets", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifouterrors", "ifouterrors", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifstatus", "ifstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "mac", "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "ifdescr", "ifdescr", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "portduplex", "portduplex", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "trunk", "trunk", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "lastup", "lastup", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_networking_ports", "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifmac", "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->dropKey($newTable, "FK_networking_ports");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifmtu", "int(8) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifspeed", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifinternalstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "ifconnectionstatus", "int(8) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "iflastchange", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "ifinoctets", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifinerrors", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifoutoctets", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifouterrors", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "ifdescr", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "ifalias", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "portduplex", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "trunk", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "lastup", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addKey($newTable, "networkports_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_networkequipments
     */
    $newTable = "glpi_plugin_fusioninventory_networkequipments";
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkequipments", $newTable);
    $migration->renameTable("glpi_plugin_tracker_networking", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "networkequipments_id", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "sysdescr", "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusioninventory_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "uptime", "uptime", "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "cpu", "cpu", "int(3) NOT NULL DEFAULT '0' COMMENT '%'");
    $migration->changeField($newTable, "memory", "memory", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "last_fusioninventory_update", "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "last_PID_update", "last_PID_update", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_networking", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_snmp_connection", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "last_tracker_update", "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusinvsnmp_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->dropKey($newTable, "FK_networking");
    $migration->dropKey($newTable, "FK_model_infos");
    $migration->dropKey($newTable, "plugin_fusioninventory_snmpmodels_id");
    $migration->migrationOneTable($newTable);
    $migration->dropField($newTable, "plugin_fusioninventory_snmpmodels_id");
    $migration->dropField($newTable, "plugin_fusinvsnmp_models_id");
    $migration->dropField($newTable, "FK_model_infos");
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "uptime", "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "cpu", "int(3) NOT NULL DEFAULT '0' COMMENT '%'");
    $migration->addField($newTable, "memory", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->addField($newTable, "last_PID_update", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "serialized_inventory", "longblob");
    $migration->addKey($newTable, "networkequipments_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * glpi_plugin_fusioninventory_networkequipmentips
     * Removed in 0.84, but required here for update, we drop in edn of this function
     */
    if (TableExists("glpi_plugin_fusioninventory_networkequipmentips") || TableExists("glpi_plugin_fusinvsnmp_networkequipmentips") || TableExists("glpi_plugin_tracker_networking_ifaddr")) {
        $newTable = "glpi_plugin_fusioninventory_networkequipmentips";
        $migration->renameTable("glpi_plugin_fusinvsnmp_networkequipmentips", $newTable);
        $migration->renameTable("glpi_plugin_tracker_networking_ifaddr", $newTable);
        if (!TableExists($newTable)) {
            $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
        }
        $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
        $migration->changeField($newTable, "networkequipments_id", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
        $migration->changeField($newTable, "ip", "ip", "varchar(255) DEFAULT NULL");
        $migration->migrationOneTable($newTable);
        $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
        $migration->changeField($newTable, "FK_networking", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
        $migration->changeField($newTable, "ifaddr", "ip", "varchar(255) DEFAULT NULL");
        $migration->dropKey($newTable, "ifaddr");
        $migration->migrationOneTable($newTable);
        $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
        $migration->addField($newTable, "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
        $migration->addField($newTable, "ip", "varchar(255) DEFAULT NULL");
        $migration->addKey($newTable, "ip");
        $migration->addKey($newTable, "networkequipments_id");
        $migration->migrationOneTable($newTable);
        $DB->list_fields($newTable, FALSE);
    }
    /*
     * Table glpi_plugin_fusioninventory_networkportlogs
     */
    $newTable = "glpi_plugin_fusioninventory_networkportlogs";
    if (TableExists("glpi_plugin_tracker_snmp_history")) {
        // **** Update history
        update213to220_ConvertField($migration);
        // **** Migration network history connections
        $query = "SELECT count(ID) FROM `glpi_plugin_tracker_snmp_history`\n                              WHERE `Field`='0'";
        $result = $DB->query($query);
        $datas = $DB->fetch_assoc($result);
        $nb = $datas['count(ID)'];
        //echo "Move Connections history to another table...";
        for ($i = 0; $i < $nb; $i = $i + 500) {
            $migration->displayMessage("{$i} / {$nb}");
            $sql_connection = "SELECT * FROM `glpi_plugin_tracker_snmp_history`\n                                 WHERE `Field`='0'\n                                 ORDER BY `FK_process` DESC, `date_mod` DESC\n                                 LIMIT 500";
            $result_connection = $DB->query($sql_connection);
            while ($thread_connection = $DB->fetch_array($result_connection)) {
                $input = array();
                $input['process_number'] = $thread_connection['FK_process'];
                $input['date'] = $thread_connection['date_mod'];
                if ($thread_connection["old_device_ID"] != "0" or $thread_connection["new_device_ID"] != "0") {
                    if ($thread_connection["old_device_ID"] != "0") {
                        // disconnection
                        $input['creation'] = '0';
                    } else {
                        if ($thread_connection["new_device_ID"] != "0") {
                            // connection
                            $input['creation'] = '1';
                        }
                    }
                    $input['FK_port_source'] = $thread_connection["FK_ports"];
                    $dataPort = array();
                    if ($thread_connection["old_device_ID"] != "0") {
                        $queryPort = "SELECT *\n                                      FROM `glpi_networkports`\n                                      WHERE `mac`='" . $thread_connection['old_value'] . "'\n                                      LIMIT 1";
                        $resultPort = $DB->query($queryPort);
                        $dataPort = $DB->fetch_assoc($resultPort);
                    } else {
                        if ($thread_connection["new_device_ID"] != "0") {
                            $queryPort = "SELECT *\n                                      FROM `glpi_networkports`\n                                      WHERE `mac`='" . $thread_connection['new_value'] . "'\n                                      LIMIT 1";
                            $resultPort = $DB->query($queryPort);
                            $dataPort = $DB->fetch_assoc($resultPort);
                        }
                    }
                    if (isset($dataPort['id'])) {
                        $input['FK_port_destination'] = $dataPort['id'];
                    } else {
                        $input['FK_port_destination'] = 0;
                    }
                    $query_ins = "INSERT INTO `glpi_plugin_fusinvsnmp_networkportconnectionlogs`\n                        (`date_mod`, `creation`, `networkports_id_source`,\n                         `networkports_id_destination`)\n                        VALUES ('" . $input['date'] . "',\n                                '" . $input['creation'] . "',\n                                '" . $input['FK_port_source'] . "',\n                                '" . $input['FK_port_destination'] . "')";
                    $DB->query($query_ins);
                }
            }
        }
        $query_del = "DELETE FROM `glpi_plugin_tracker_snmp_history`\n               WHERE `Field`='0'\n               AND (`old_device_ID`!='0' OR `new_device_ID`!='0')";
        $DB->query($query_del);
        $migration->displayMessage("{$nb} / {$nb}");
    }
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkportlogs", $newTable);
    $migration->renameTable("glpi_plugin_tracker_snmp_history", $newTable);
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "networkports_id", "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "date_mod", "date_mod", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "value_old", "value_old", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "value_new", "value_new", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusioninventory_agentprocesses_id", "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_ports", "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    // Update with mapping
    if (FieldExists($newTable, "Field")) {
        //            $pfNetworkPortLog = new PluginFusioninventoryNetworkPortLog();
        $pfMapping = new PluginFusioninventoryMapping();
        $query = "SELECT * FROM `" . $newTable . "`\n               GROUP BY `Field`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $mapping = 0;
            if ($mapping = $pfMapping->get("NetworkEquipment", $data['Field'])) {
                $DB->query("UPDATE `" . $newTable . "`\n                     SET `plugin_fusioninventory_mappings_id`='" . $mapping['id'] . "'\n                     WHERE `Field`='" . $data['Field'] . "'\n                        AND `plugin_fusioninventory_mappings_id`!='" . $mapping['id'] . "'");
            }
        }
    }
    $migration->dropField($newTable, "Field");
    $migration->changeField($newTable, "old_value", "value_old", "varchar(255) DEFAULT NULL");
    $migration->dropField($newTable, "old_device_type");
    $migration->dropField($newTable, "old_device_ID");
    $migration->changeField($newTable, "new_value", "value_new", "varchar(255) DEFAULT NULL");
    $migration->dropField($newTable, "new_device_type");
    $migration->dropField($newTable, "new_device_ID");
    $migration->dropField($newTable, "FK_process");
    $migration->dropKey($newTable, "FK_process");
    $migration->dropKey($newTable, "FK_ports");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "date_mod", "datetime DEFAULT NULL");
    $migration->addField($newTable, "value_old", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "value_new", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array("networkports_id", "date_mod"), "networkports_id");
    $migration->addKey($newTable, "plugin_fusioninventory_mappings_id");
    $migration->addKey($newTable, "plugin_fusioninventory_agentprocesses_id");
    $migration->addKey($newTable, "date_mod");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_configsecurities
     */
    // TODO get info to create SNMP authentification with old values of Tracker plugin
    $newTable = "glpi_plugin_fusioninventory_configsecurities";
    $migration->renameTable("glpi_plugin_fusinvsnmp_configsecurities", $newTable);
    $migration->renameTable("glpi_plugin_tracker_snmp_connection", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "snmpversion", "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, "community", "community", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "username", "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "authentication", "authentication", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "auth_passphrase", "auth_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "encryption", "encryption", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "priv_passphrase", "priv_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "is_deleted", "is_deleted", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_snmp_version", "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, "sec_name", "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->dropField($newTable, "sec_level");
    $migration->dropField($newTable, "auth_protocol");
    $migration->dropField($newTable, "priv_protocol");
    $migration->dropField($newTable, "deleted");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "name", "varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'");
    $migration->addField($newTable, "community", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "authentication", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "auth_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "encryption", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "priv_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "is_deleted", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "snmpversion");
    $migration->addKey($newTable, "is_deleted");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     *  glpi_plugin_fusioninventory_statediscoveries
     */
    $newTable = "glpi_plugin_fusioninventory_statediscoveries";
    $migration->renameTable("glpi_plugin_fusinvsnmp_statediscoveries", $newTable);
    if (!TableExists($newTable)) {
        $DB->query("CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1");
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "plugin_fusioninventory_taskjob_id", "plugin_fusioninventory_taskjob_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_agents_id", "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "start_time", "start_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "end_time", "end_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "date_mod", "date_mod", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "threads", "threads", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_ip", "nb_ip", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_found", "nb_found", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_error", "nb_error", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_exists", "nb_exists", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_import", "nb_import", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "plugin_fusioninventory_taskjob_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "start_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addField($newTable, "end_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addField($newTable, "date_mod", "datetime DEFAULT NULL");
    $migration->addField($newTable, "threads", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_ip", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_found", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_error", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_exists", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_import", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_computerlicenseinfos
     */
    if (TableExists("glpi_plugin_fusinvinventory_licenseinfos")) {
        $DB->query("UPDATE `glpi_plugin_fusinvinventory_licenseinfos`" . " SET `softwarelicenses_id`='0'" . " WHERE `softwarelicenses_id` IS NULL");
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_computerlicenseinfos';
    $a_table['oldname'] = array('glpi_plugin_fusinvinventory_licenseinfos');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['softwarelicenses_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['fullname'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['is_trial'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['is_update'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['is_oem'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['activation_date'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'fullname', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_computerarchs
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_computerarchs';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Deploy Update Begin
     */
    /*
     * glpi_plugin_fusioninventory_deployfiles
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_deployfiles';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) NOT NULL', 'value' => NULL), 'mimetype' => array('type' => 'varchar(255) NOT NULL', 'value' => NULL), 'filesize' => array('type' => 'bigint(20) NOT NULL', 'value' => NULL), 'comment' => array('type' => 'text DEFAULT NULL', 'value' => NULL), 'sha512' => array('type' => 'char(128) NOT NULL', 'value' => NULL), 'shortsha512' => array('type' => 'char(6) NOT NULL', 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => 0), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'id', 'name' => '', 'type' => 'KEY'), array('field' => 'shortsha512', 'name' => '', 'type' => 'KEY'), array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deployorders
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deployorders';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_orders');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'type' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'create_date' => array('type' => ' datetime NOT NULL', 'value' => NULL), 'plugin_fusioninventory_deploypackages_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'json' => array('type' => 'longtext DEFAULT NULL', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array('plugin_fusinvdeploy_packages_id' => 'plugin_fusioninventory_deploypackages_id');
    $a_table['keys'] = array(array('field' => 'type', 'name' => '', 'type' => 'KEY'), array('field' => 'create_date', 'name' => '', 'type' => 'KEY'), array('field' => 'plugin_fusioninventory_deploypackages_id', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array('plugin_fusinvdeploy_packages_id');
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploypackages
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploypackages';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_packages');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'comment' => array('type' => "text", 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => NULL), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL), 'uuid' => array('type' => 'string', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploymirrors
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploymirrors';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_mirrors');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => NULL), 'name' => array('type' => 'varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'url' => array('type' => "varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci" . " NOT NULL DEFAULT ''", 'value' => NULL), 'locations_id' => array('type' => 'int(11) NOT NULL', 'value' => 0), 'comment' => array('type' => "text", 'value' => NULL), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploygroups
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'comment' => array('type' => "text", 'value' => NULL), 'type' => array('type' => 'varchar(255) COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploygroups_staticdatas
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups_staticdatas';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups_staticdatas');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'groups_id' => array('type' => 'integer', 'value' => NULL), 'itemtype' => array('type' => 'varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL', 'value' => NULL), 'items_id' => array('type' => 'integer', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'groups_id', 'name' => '', 'type' => 'KEY'), array('field' => 'items_id', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploygroups_dynamicdatas
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups_dynamicdatas';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups_dynamicdatas');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'groups_id' => array('type' => 'integer', 'value' => NULL), 'fields_array' => array('type' => 'text', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'groups_id', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * import old datas as json in order table before migrate this table
     */
    migrateTablesFromFusinvDeploy($migration);
    /*
     * Deploy Update End
     */
    /*
     * Table glpi_plugin_fusioninventory_collects
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['type'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['is_active'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_registries
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_registries';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['hive'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['path'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['key'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_registries_contents
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_registries_contents';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_registries_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['key'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_wmis
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_wmis';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['moniker'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['class'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['properties'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_wmis_contents
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_wmis_contents';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_wmis_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['property'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_files
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_files';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['dir'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['limit'] = array('type' => "int(4) NOT NULL DEFAULT '50'", 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['filter_regex'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_sizeequals'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['filter_sizegreater'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['filter_sizelower'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['filter_checksumsha512'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_checksumsha2'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_iname'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_is_file'] = array('type' => 'bool', 'value' => '1');
    $a_table['fields']['filter_is_dir'] = array('type' => 'bool', 'value' => '0');
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_files_contents
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_files_contents';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_files_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['pathfile'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['size'] = array('type' => 'integer', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_dblockinventorynames
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_dblockinventorynames';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['value'] = array('type' => "varchar(100) NOT NULL DEFAULT ''", 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_dblockinventories
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_dblockinventories';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['value'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_dblocksoftwares
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_dblocksoftwares';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['value'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_dblocksoftwareversions
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_dblocksoftwareversions';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['value'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Add ESX module appear in version 2.4.0(0.80+1.0)
     */
    $DB->query("UPDATE `glpi_plugin_fusioninventory_agentmodules`\n         SET `modulename`='InventoryComputerESX'\n         WHERE `modulename`='ESX'");
    $agentmodule = new PluginFusioninventoryAgentmodule();
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n         WHERE `modulename`='InventoryComputerESX'\n         LIMIT 1";
    $result = $DB->query($query);
    if ($DB->numrows($result) == '0') {
        $input = array();
        $input['modulename'] = "InventoryComputerESX";
        $input['is_active'] = 0;
        $input['exceptions'] = exportArrayToDB(array());
        $url = '';
        if (isset($_SERVER['HTTP_REFERER'])) {
            $url = $_SERVER['HTTP_REFERER'];
        }
        $agentmodule->add($input);
    }
    /*
     * Add Collect module appear in version 0.84+2.0
     */
    $agentmodule = new PluginFusioninventoryAgentmodule();
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n         WHERE `modulename`='Collect'\n         LIMIT 1";
    $result = $DB->query($query);
    if ($DB->numrows($result) == '0') {
        $input = array();
        $input['modulename'] = "Collect";
        $input['is_active'] = 1;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Update pci and usb ids and oui
     */
    foreach (array('usbid.sql', 'pciid.sql', 'oui.sql') as $sql) {
        $DB_file = GLPI_ROOT . "/plugins/fusioninventory/install/mysql/{$sql}";
        $DBf_handle = fopen($DB_file, "rt");
        $sql_query = fread($DBf_handle, filesize($DB_file));
        fclose($DBf_handle);
        foreach (explode(";\n", "{$sql_query}") as $sql_line) {
            if (Toolbox::get_magic_quotes_runtime()) {
                $sql_line = Toolbox::stripslashes_deep($sql_line);
            }
            if (!empty($sql_line)) {
                $DB->query($sql_line);
            }
        }
    }
    /*
     * Migrate data of table glpi_plugin_fusinvsnmp_agentconfigs into
     * glpi_plugin_fusioninventory_agents
     */
    if (TableExists("glpi_plugin_fusinvsnmp_agentconfigs")) {
        $query = "SELECT * FROM `glpi_plugin_fusinvsnmp_agentconfigs`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $queryu = "UPDATE `glpi_plugin_fusioninventory_agents`\n            SET `threads_networkdiscovery`='" . $data['threads_netdiscovery'] . "',\n                `threads_networkinventory`='" . $data['threads_snmpquery'] . "',\n                `senddico`='" . $data['senddico'] . "'\n            WHERE `id`='" . $data['plugin_fusioninventory_agents_id'] . "'";
            $DB->query($queryu);
        }
    }
    // Update profiles
    if (TableExists("glpi_plugin_tracker_profiles")) {
        $profile = new Profile();
        $pfProfile = new PluginFusioninventoryProfile();
        $query = "SELECT * FROM `glpi_plugin_tracker_profiles`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $profiledata = current($profile->find("`name`='" . $data['name'] . "'", "", 1));
            if (!empty($profiledata)) {
                $newprofile = array();
                $newprofile['snmp_networking'] = "networkequipment";
                $newprofile['snmp_printers'] = "printer";
                $newprofile['snmp_models'] = "model";
                $newprofile['snmp_authentification'] = "configsecurity";
                $newprofile['general_config'] = "configuration";
                $newprofile['snmp_report'] = "reportprinter";
                foreach ($newprofile as $old => $new) {
                    if (isset($profiledata[$old])) {
                        //                  $pfProfile->addProfile($new,
                        //                                         $profiledata[$old],
                        //                                         $profiledata['id']);
                    }
                }
                if (isset($profiledata["snmp_report"])) {
                    //               $pfProfile->addProfile("reportnetworkequipment",
                    //                                      $profiledata["snmp_report"],
                    //                                      $profiledata['id']);
                }
            }
        }
        $DB->query("DROP TABLE `glpi_plugin_tracker_profiles`");
    }
    update213to220_ConvertField($migration);
    /*
     * Move networkequipment IPs to net system
     */
    if (TableExists("glpi_plugin_fusioninventory_networkequipmentips")) {
        $networkPort = new NetworkPort();
        $networkName = new NetworkName();
        $ipAddress = new IPAddress();
        $networkEquipment = new NetworkEquipment();
        $query = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipments`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            if ($networkEquipment->getFromDB($data['networkequipments_id'])) {
                $oldtableip = array();
                $queryIP = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipmentips`\n               WHERE `networkequipments_id`='" . $data['networkequipments_id'] . "'";
                $resultIP = $DB->query($queryIP);
                while ($dataIP = $DB->fetch_array($resultIP)) {
                    $oldtableip[$dataIP['ip']] = $dataIP['ip'];
                }
                // Get actual IP defined
                $networknames_id = 0;
                $a_ports = $networkPort->find("`itemtype`='NetworkEquipment'\n                  AND `items_id`='" . $data['networkequipments_id'] . "'\n                  AND `instantiation_type`='NetworkPortAggregate'\n                  AND `name`='management'", "", 1);
                foreach ($a_ports as $a_port) {
                    $a_networknames = $networkName->find("`itemtype`='NetworkPort'\n                  AND `items_id`='" . $a_port['id'] . "'");
                    foreach ($a_networknames as $a_networkname) {
                        $networknames_id = $a_networkname['id'];
                        $a_ipaddresses = $ipAddress->find("`itemtype`='NetworkName'\n                     AND `items_id`='" . $a_networkname['id'] . "'");
                        foreach ($a_ipaddresses as $a_ipaddress) {
                            if (isset($oldtableip[$a_ipaddress['name']])) {
                                unset($oldtableip[$a_ipaddress['name']]);
                            } else {
                                $ipAddress->delete($a_ipaddress, 1);
                            }
                        }
                    }
                }
                // Update
                foreach ($oldtableip as $ip) {
                    $input = array();
                    $input['itemtype'] = "NetworkName";
                    $input['items_id'] = $networknames_id;
                    $input['name'] = $ip;
                    $input['is_dynamic'] = 1;
                    $ipAddress->add($input);
                }
            }
        }
    }
    /*
     * Table Delete old table not used
     */
    $a_drop = array();
    $a_drop[] = 'glpi_plugin_tracker_computers';
    $a_drop[] = 'glpi_plugin_tracker_connection_history';
    $a_drop[] = 'glpi_plugin_tracker_agents_processes';
    $a_drop[] = 'glpi_plugin_tracker_config_snmp_history';
    $a_drop[] = 'glpi_plugin_tracker_config_snmp_networking';
    $a_drop[] = 'glpi_plugin_tracker_config_snmp_printer';
    $a_drop[] = 'glpi_plugin_tracker_config_snmp_script';
    $a_drop[] = 'glpi_plugin_tracker_connection_stats';
    $a_drop[] = 'glpi_plugin_tracker_discovery';
    $a_drop[] = 'glpi_plugin_tracker_errors';
    $a_drop[] = 'glpi_plugin_tracker_model_infos';
    $a_drop[] = 'glpi_plugin_tracker_processes';
    $a_drop[] = 'glpi_plugin_tracker_processes_values';
    $a_drop[] = 'glpi_plugin_fusioninventory_agents_errors';
    $a_drop[] = 'glpi_plugin_fusioninventory_agents_processes';
    $a_drop[] = 'glpi_plugin_fusioninventory_computers';
    $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_auth_protocol';
    $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_priv_protocol';
    $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_sec_level';
    $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_version';
    $a_drop[] = 'glpi_plugin_fusioninventory_config_snmp_networking';
    $a_drop[] = 'glpi_plugin_fusioninventory_config_snmp_history';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_agentconfigs';
    $a_drop[] = 'glpi_plugin_tracker_computers';
    $a_drop[] = 'glpi_plugin_tracker_config';
    $a_drop[] = 'glpi_plugin_tracker_config_discovery';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_label';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_object';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_oid';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_auth_auth_protocol';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_auth_priv_protocol';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_version';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_temp_profiles';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_agents';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_configs';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_tasks';
    $a_drop[] = 'glpi_plugin_tracker_tmp_connections';
    $a_drop[] = 'glpi_plugin_tracker_tmp_netports';
    $a_drop[] = 'glpi_plugin_tracker_walks';
    $a_drop[] = 'glpi_plugin_fusioninventory_networkequipmentips';
    foreach ($a_drop as $droptable) {
        if (TableExists($droptable)) {
            $DB->query("DROP TABLE `" . $droptable . "`");
        }
    }
    $migration->executeMigration();
    /*
     * Add WakeOnLan module appear in version 2.3.0
     */
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='WAKEONLAN'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $agentmodule = new PluginFusioninventoryAgentmodule();
        $input = array();
        $input['plugins_id'] = $plugins_id;
        $input['modulename'] = "WAKEONLAN";
        $input['is_active'] = 0;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Add storage type if not present
     */
    $a_storage = array();
    $a_storage['partition'] = 5;
    $a_storage['volume groups'] = 10;
    $a_storage['logical volumes'] = 20;
    $a_storage['hard disk'] = 1;
    $a_storage['mount'] = 25;
    foreach ($a_storage as $name => $level) {
        $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_inventorycomputerstoragetypes`\n         WHERE `name`='" . $name . "'";
        $result = $DB->query($query);
        if (!$DB->numrows($result)) {
            $DB->query("INSERT INTO `glpi_plugin_fusioninventory_inventorycomputerstoragetypes`\n            (`name`, `level`) VALUES\n            ('" . $name . "', '" . $level . "')");
        }
    }
    /*
     * Clean for port orphelin
     */
    //networkports with item_type = 0
    $NetworkPort = new NetworkPort();
    $NetworkPort_Vlan = new NetworkPort_Vlan();
    $NetworkPort_NetworkPort = new NetworkPort_NetworkPort();
    $a_networkports = $NetworkPort->find("`itemtype`=''");
    foreach ($a_networkports as $data) {
        if ($NetworkPort_NetworkPort->getFromDBForNetworkPort($data['id'])) {
            $NetworkPort_NetworkPort->delete($NetworkPort_NetworkPort->fields);
        }
        $a_vlans = $NetworkPort_Vlan->find("`networkports_id`='" . $data['id'] . "'");
        foreach ($a_vlans as $a_vlan) {
            $NetworkPort_Vlan->delete($a_vlan);
        }
        $NetworkPort->delete($data, 1);
    }
    /*
     *  Clean old ports deleted but have some informations in SNMP tables
     */
    //echo "Clean ports purged\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_networkports`.`id`\n                    FROM `glpi_plugin_fusioninventory_networkports`\n                          LEFT JOIN `glpi_networkports`\n                                    ON `glpi_networkports`.`id` = `networkports_id`\n                          LEFT JOIN `glpi_networkequipments`\n                              ON `glpi_networkequipments`.`id` = `glpi_networkports`.`items_id`\n                    WHERE `glpi_networkequipments`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_networkports`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     * Clean for switch more informations again in DB when switch is purged
     */
    //echo "Clean for switch more informations again in DB when switch is purged\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_networkequipments`.`id`\n                    FROM `glpi_plugin_fusioninventory_networkequipments`\n                    LEFT JOIN `glpi_networkequipments`\n                        ON `glpi_networkequipments`.`id` = `networkequipments_id`\n                    WHERE `glpi_networkequipments`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_networkequipments`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     * Clean for printer more informations again in DB when printer is purged
     */
    //echo "Clean for printer more informations again in DB when printer is purged\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_printers`.`id`\n                    FROM `glpi_plugin_fusioninventory_printers`\n                          LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n                    WHERE `glpi_printers`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printers`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     *  Clean printer cartridge not deleted with the printer associated
     */
    //echo "Clean printer cartridge not deleted with the printer associated\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_printercartridges`.`id`\n                    FROM `glpi_plugin_fusioninventory_printercartridges`\n                          LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n                    WHERE `glpi_printers`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printercartridges`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     *  Clean printer history not deleted with printer associated
     */
    //echo "Clean printer history not deleted with printer associated\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_printerlogs`.`id`\n                    FROM `glpi_plugin_fusioninventory_printerlogs`\n                          LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n                    WHERE `glpi_printers`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printerlogs`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     * Fix problem with mapping with many entries with same mapping
     */
    $a_mapping = array();
    $a_mappingdouble = array();
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_mappings`\n      ORDER BY `id`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        if (!isset($a_mapping[$data['itemtype'] . "." . $data['name']])) {
            $a_mapping[$data['itemtype'] . "." . $data['name']] = $data['id'];
        } else {
            $a_mappingdouble[$data['id']] = $data['itemtype'] . "." . $data['name'];
        }
    }
    foreach ($a_mappingdouble as $mapping_id => $mappingkey) {
        $query = "UPDATE `glpi_plugin_fusioninventory_printercartridges`\n         SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n         WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'";
        $DB->query($query);
        $query = "UPDATE `glpi_plugin_fusioninventory_networkportlogs`\n         SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n         WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'";
        $DB->query($query);
        $query = "UPDATE `glpi_plugin_fusioninventory_configlogfields`\n         SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n         WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'";
        $DB->query($query);
        $query = "DELETE FROM `glpi_plugin_fusioninventory_mappings`\n         WHERE `id` = '" . $mapping_id . "'";
        $DB->query($query);
    }
    /*
     * Update networports to convert itemtype 5153 to PluginFusioninventoryUnknownDevice
     */
    $sql = "UPDATE `glpi_networkports`\n      SET `itemtype`='PluginFusioninventoryUnknownDevice'\n      WHERE `itemtype`='5153'";
    $DB->query($sql);
    $sql = "UPDATE `glpi_networkports`\n      SET `itemtype`='PluginFusioninventoryTask'\n      WHERE `itemtype`='5166'";
    $DB->query($sql);
    /*
     * Clean display preferences not used
     */
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5150' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5160' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5161' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5163' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5165' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5190' ";
    $DB->query($sql);
    /*
     * Update display preferences
     */
    changeDisplayPreference("5153", "PluginFusioninventoryUnknownDevice");
    changeDisplayPreference("5158", "PluginFusioninventoryAgent");
    changeDisplayPreference("PluginFusinvinventoryBlacklist", "PluginFusioninventoryInventoryComputerBlacklist");
    changeDisplayPreference("5151", "PluginFusinvsnmpModel");
    changeDisplayPreference("PluginFusinvsnmpModel", "PluginFusioninventorySnmpmodel");
    changeDisplayPreference("5152", "PluginFusinvsnmpConfigSecurity");
    changeDisplayPreference("5156", "PluginFusinvsnmpPrinterCartridge");
    changeDisplayPreference("5157", "PluginFusinvsnmpNetworkEquipment");
    changeDisplayPreference("PluginFusinvsnmpNetworkEquipment", "PluginFusioninventoryNetworkEquipment");
    changeDisplayPreference("5159", "PluginFusinvsnmpIPRange");
    changeDisplayPreference("5162", "PluginFusinvsnmpNetworkPortLog");
    changeDisplayPreference("5167", "PluginFusioninventorySnmpmodelConstructDevice");
    changeDisplayPreference("PluginFusinvsnmpConstructDevice", "PluginFusioninventorySnmpmodelConstructDevice");
    changeDisplayPreference("5168", "PluginFusinvsnmpPrinterLog");
    changeDisplayPreference("PluginFusinvsnmpPrinterLogReport", "PluginFusioninventoryPrinterLogReport");
    changeDisplayPreference("PluginFusioninventoryUnknownDevice", "PluginFusioninventoryUnmanaged");
    /*
     * Delete IP and MAC of PluginFusioninventoryUnknownDevice in displaypreference
     */
    $queryd = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='PluginFusioninventoryUnknownDevice'\n            AND (`num`='11' OR `num`='12' OR `num`='16')";
    $DB->query($queryd);
    /*
     * Clean in displaypreference
     */
    $queryd = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='PluginFusioninventorysnmpModel'";
    $DB->query($queryd);
    /*
     * Modify displaypreference for PluginFusioninventoryPrinterLog
     */
    $pfPrinterLogReport = new PluginFusioninventoryPrinterLog();
    $a_searchoptions = $pfPrinterLogReport->getSearchOptions();
    $query = "SELECT * FROM `glpi_displaypreferences`\n      WHERE `itemtype` = 'PluginFusioninventoryPrinterLogReport'\n         AND `users_id`='0'";
    $result = $DB->query($query);
    if ($DB->numrows($result) == '0') {
        $query = "INSERT INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`,\n                        `users_id`)\n                     VALUES (NULL, 'PluginFusioninventoryPrinterLogReport', '2', '1', '0'),\n             (NULL, 'PluginFusioninventoryPrinterLogReport', '18', '2', '0'),\n             (NULL, 'PluginFusioninventoryPrinterLogReport', '20', '3', '0'),\n             (NULL, 'PluginFusioninventoryPrinterLogReport', '5', '4', '0'),\n             (NULL, 'PluginFusioninventoryPrinterLogReport', '6', '5', '0')";
        $DB->query($query);
    } else {
        while ($data = $DB->fetch_array($result)) {
            if (!isset($a_searchoptions[$data['num']])) {
                $queryd = "DELETE FROM `glpi_displaypreferences`\n                  WHERE `id`='" . $data['id'] . "'";
                $DB->query($queryd);
            }
        }
    }
    /*
     * Modify displaypreference for PluginFusinvsnmpNetworkEquipment
     */
    $a_check = array();
    $a_check["2"] = 1;
    $a_check["3"] = 2;
    $a_check["4"] = 3;
    $a_check["5"] = 4;
    $a_check["6"] = 5;
    $a_check["7"] = 6;
    $a_check["8"] = 7;
    $a_check["9"] = 8;
    $a_check["10"] = 9;
    $a_check["11"] = 10;
    $a_check["14"] = 11;
    $a_check["12"] = 12;
    $a_check["13"] = 13;
    foreach ($a_check as $num => $rank) {
        $query = "SELECT * FROM `glpi_displaypreferences`\n         WHERE `itemtype` = 'PluginFusioninventoryNetworkEquipment'\n         AND `num`='" . $num . "'\n            AND `users_id`='0'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`,\n                           `users_id`)\n                        VALUES (NULL, 'PluginFusioninventoryNetworkEquipment', '" . $num . "',\n                           '" . $rank . "', '0')";
            $DB->query($query);
        }
    }
    $query = "SELECT * FROM `glpi_displaypreferences`\n      WHERE `itemtype` = 'PluginFusioninventoryNetworkEquipment'\n         AND `users_id`='0'";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        if (!isset($a_check[$data['num']])) {
            $queryd = "DELETE FROM `glpi_displaypreferences`\n               WHERE `id`='" . $data['id'] . "'";
            $DB->query($queryd);
        }
    }
    // If no PluginFusioninventoryTaskjoblog in preferences, add them
    $query = "SELECT * FROM `glpi_displaypreferences`\n      WHERE `itemtype` = 'PluginFusioninventoryTaskjoblog'\n         AND `users_id`='0'";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $DB->query("INSERT INTO `glpi_displaypreferences`\n            (`id`, `itemtype`, `num`, `rank`, `users_id`)\n         VALUES (NULL,'PluginFusioninventoryTaskjoblog', '2', '1', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '3', '2', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '4', '3', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '5', '4', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '6', '5', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '7', '6', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '8', '7', '0')");
    }
    // If no PluginFusioninventoryNetworkPort in preferences, add them
    $query = "SELECT * FROM `glpi_displaypreferences`\n      WHERE `itemtype` = 'PluginFusioninventoryNetworkPort'\n         AND `users_id`='0'";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $DB->query("INSERT INTO `glpi_displaypreferences`\n            (`id`, `itemtype`, `num`, `rank`, `users_id`)\n         VALUES (NULL,'PluginFusioninventoryNetworkPort', '3', '1', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '5', '2', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '6', '3', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '7', '4', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '8', '5', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '9', '6', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '10', '7', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '11', '8', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '12', '9', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '13', '10', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '14', '11', '0')");
    }
    /*
     * Convert taskjob definition from PluginFusinvsnmpIPRange to PluginFusioninventoryIPRange
     * onvert taskjob definition from PluginFusinvdeployPackage to PluginFusioninventoryDeployPackage
     */
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_taskjobs`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $a_defs = importArrayFromDB($data['targets']);
        foreach ($a_defs as $num => $a_def) {
            if (key($a_def) == 'PluginFusinvsnmpIPRange') {
                $a_defs[$num] = array('PluginFusioninventoryIPRange' => current($a_def));
            } else {
                if (key($a_def) == 'PluginFusinvdeployPackage') {
                    $a_defs[$num] = array('PluginFusioninventoryDeployPackage' => current($a_def));
                }
            }
        }
        $queryu = "UPDATE `glpi_plugin_fusioninventory_taskjobs`\n         SET `targets`='" . exportArrayToDB($a_defs) . "'\n         WHERE `id`='" . $data['id'] . "'";
        $DB->query($queryu);
    }
    /*
     * Convert taskjoblogs itemtype from PluginFusinvdeployPackage to
     * PluginFusioninventoryDeployPackage
     */
    $query = "UPDATE `glpi_plugin_fusioninventory_taskjoblogs` " . "SET `itemtype`='PluginFusioninventoryDeployPackage'" . "WHERE `itemtype`='PluginFusinvdeployPackage'";
    $result = $DB->query($query);
    /*
     * Convert taskjobstates itemtype from PluginFusinvdeployPackage to
     * PluginFusioninventoryDeployPackage
     */
    $query = "UPDATE `glpi_plugin_fusioninventory_taskjobstates` " . "SET `itemtype`='PluginFusioninventoryDeployPackage'" . "WHERE `itemtype` = 'PluginFusinvdeployPackage'";
    $result = $DB->query($query);
    /*
     * Convert taskjob action from PluginFusinvdeployGroup to PluginFusioninventoryDeployGroup
     */
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_taskjobs`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $a_defs = importArrayFromDB($data['actors']);
        foreach ($a_defs as $num => $a_def) {
            if (key($a_def) == 'PluginFusinvdeployGroup') {
                $a_defs[$num] = array('PluginFusioninventoryDeployGroup' => current($a_def));
            }
        }
        $queryu = "UPDATE `glpi_plugin_fusioninventory_taskjobs`\n         SET `actors`='" . exportArrayToDB($a_defs) . "'\n         WHERE `id`='" . $data['id'] . "'";
        $DB->query($queryu);
    }
    /*
     * Convert itemtype from glpi_plugin_fusioninventory_unknowndevices to
     * PluginFusioninventoryUnmanaged
     */
    $tables = array('glpi_networkports', 'glpi_logs', 'glpi_plugin_fusioninventory_ignoredimportdevices');
    foreach ($tables as $table) {
        $query = "UPDATE `" . $table . "` " . "SET `itemtype`='PluginFusioninventoryUnmanaged'" . "WHERE `itemtype` = 'PluginFusioninventoryUnknowndevice'";
        $DB->query($query);
    }
    $query = "UPDATE `glpi_ipaddresses` " . "SET `mainitemtype`='PluginFusioninventoryUnmanaged'" . "WHERE `mainitemtype` = 'PluginFusioninventoryUnknowndevice'";
    $DB->query($query);
    /*
     * Update rules
     */
    $query = "UPDATE glpi_rules SET `sub_type`='PluginFusioninventoryInventoryRuleImport'\n      WHERE `sub_type`='PluginFusioninventoryRuleImportEquipment'";
    $DB->query($query);
    $query = "SELECT * FROM `glpi_rules`\n               WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport'";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $querya = "UPDATE glpi_ruleactions SET `value`='1'\n         WHERE `rules_id`='" . $data['id'] . "'\n            AND `value`='0'\n            AND `field`='_fusion'";
        $DB->query($querya);
    }
    $query = "UPDATE glpi_rules SET `sub_type`='PluginFusioninventoryInventoryRuleEntity'\n      WHERE `sub_type`='PluginFusinvinventoryRuleEntity'";
    $DB->query($query);
    /*
     *  Add default rules
     */
    if (TableExists("glpi_plugin_tracker_config_discovery")) {
        $migration->displayMessage("Create rules");
        $pfSetup = new PluginFusioninventorySetup();
        $pfSetup->initRules();
    }
    // If no rules, add them
    if (countElementsInTable('glpi_rules', "`sub_type`='PluginFusioninventoryInventoryRuleImport'") == 0) {
        $migration->displayMessage("Create rules");
        $pfSetup = new PluginFusioninventorySetup();
        $pfSetup->initRules();
    }
    // Add peripheral rules (in first in rule list) when use it since 0.85
    $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_peripheral' ";
    $DB->query($query);
    $query = "UPDATE `glpi_rules` " . " SET `ranking` = `ranking`+3" . " WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport' ";
    $ranking = 0;
    // Create rule for : Peripheral + serial
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Peripheral serial';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 10;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 8;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Peripheral';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_fusion';
    $input['value'] = '1';
    $ruleaction->add($input);
    $ranking++;
    // Create rule for : Peripheral import
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Peripheral import';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Peripheral';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 8;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_fusion';
    $input['value'] = '1';
    $ruleaction->add($input);
    $ranking++;
    // Create rule for : Peripheral ignore import
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Peripheral ignore import';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Peripheral';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_ignore_import';
    $input['value'] = '1';
    $ruleaction->add($input);
    // Add monitor rules (in first in rule list) when use it since 0.85
    $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_monitor' ";
    $DB->query($query);
    $query = "UPDATE `glpi_rules` " . " SET `ranking` = `ranking`+3" . " WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport' ";
    $ranking = 0;
    // Create rule for : Monitor + serial
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Monitor serial';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 10;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 8;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Monitor';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_fusion';
    $input['value'] = '1';
    $ruleaction->add($input);
    $ranking++;
    // Create rule for : Monitor import
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Monitor import';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Monitor';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 8;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_fusion';
    $input['value'] = '1';
    $ruleaction->add($input);
    $ranking++;
    // Create rule for : Monitor ignore import
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Monitor ignore import';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Monitor';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_ignore_import';
    $input['value'] = '1';
    $ruleaction->add($input);
    // Add printer rules (in first in rule list) when use it since 0.85
    $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_printer' ";
    /*
     *  Manage configuration of plugin
     */
    $config = new PluginFusioninventoryConfig();
    $pfSetup = new PluginFusioninventorySetup();
    $users_id = $pfSetup->createFusionInventoryUser();
    $a_input = array();
    $a_input['ssl_only'] = 0;
    $a_input['delete_task'] = 20;
    $a_input['inventory_frequence'] = 24;
    $a_input['agent_port'] = 62354;
    $a_input['extradebug'] = 0;
    $a_input['users_id'] = $users_id;
    $a_input['agents_old_days'] = 0;
    $config->addValues($a_input, FALSE);
    //      $DB->query("DELETE FROM `glpi_plugin_fusioninventory_configs`
    //        WHERE `plugins_id`='0'");
    //      $query = "SELECT * FROM `glpi_plugin_fusioninventory_configs`
    //           WHERE `type`='version'
    //           LIMIT 1, 10";
    //      $result = $DB->query($query);
    //      while ($data=$DB->fetch_array($result)) {
    //         $config->delete($data);
    //      }
    $a_input = array();
    $a_input['version'] = PLUGIN_FUSIONINVENTORY_VERSION;
    $config->addValues($a_input, TRUE);
    $a_input = array();
    $a_input['ssl_only'] = 0;
    if (isset($prepare_Config['ssl_only'])) {
        $a_input['ssl_only'] = $prepare_Config['ssl_only'];
    }
    $a_input['delete_task'] = 20;
    $a_input['inventory_frequence'] = 24;
    $a_input['agent_port'] = 62354;
    $a_input['extradebug'] = 0;
    $a_input['users_id'] = 0;
    //Deploy configuration options
    $a_input['server_upload_path'] = Toolbox::addslashes_deep(implode(DIRECTORY_SEPARATOR, array(GLPI_PLUGIN_DOC_DIR, 'fusioninventory', 'upload')));
    $a_input['alert_winpath'] = 1;
    $a_input['server_as_mirror'] = 1;
    $config->addValues($a_input, FALSE);
    $pfSetup = new PluginFusioninventorySetup();
    $users_id = $pfSetup->createFusionInventoryUser();
    $query = "UPDATE `glpi_plugin_fusioninventory_configs`\n                         SET `value`='" . $users_id . "'\n                  WHERE `type`='users_id'";
    $DB->query($query);
    // Update fusinvinventory _config values to this plugin
    $input = array();
    $input['import_software'] = 1;
    $input['import_volume'] = 1;
    $input['import_antivirus'] = 1;
    $input['import_registry'] = 1;
    $input['import_process'] = 1;
    $input['import_vm'] = 1;
    $input['component_processor'] = 1;
    $input['component_memory'] = 1;
    $input['component_harddrive'] = 1;
    $input['component_networkcard'] = 1;
    $input['component_graphiccard'] = 1;
    $input['component_soundcard'] = 1;
    $input['component_drive'] = 1;
    $input['component_networkdrive'] = 1;
    $input['component_control'] = 1;
    $input['states_id_default'] = 0;
    $input['location'] = 0;
    $input['group'] = 0;
    $input['component_networkcardvirtual'] = 1;
    $config->addValues($input, FALSE);
    // Add new config values if not added
    $input = $config->initConfigModule(TRUE);
    foreach ($input as $name => $value) {
        $a_conf = $config->find("`type`='" . $name . "'");
        if (count($a_conf) == 0) {
            $config->add(array('type' => $name, 'value' => $value));
        }
    }
    $migration->displayMessage("Clean printers");
    /*
     * Remove / at the end of printers (bugs in older versions of agents.
     */
    $printer = new Printer();
    $query = "SELECT * FROM `glpi_printers`\n         WHERE `serial` LIKE '%/' ";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $cleanSerial = preg_replace('/\\/$/', '', $data['serial']);
        $querynb = "SELECT * FROM `glpi_printers`\n            WHERE `serial`='" . $cleanSerial . "'\n            LIMIT 1";
        $resultnb = $DB->query($querynb);
        if ($DB->numrows($resultnb) == '0') {
            $input = array();
            $input['id'] = $data['id'];
            $input["serial"] = $cleanSerial;
            $printer->update($input);
        }
    }
    /*
     * Update blacklist
     */
    $input = array();
    $input['03000200-0400-0500-0006-000700080009'] = '2';
    $input['6AB5B300-538D-1014-9FB5-B0684D007B53'] = '2';
    $input['01010101-0101-0101-0101-010101010101'] = '2';
    $input['20:41:53:59:4e:ff'] = '3';
    $input['02:00:4e:43:50:49'] = '3';
    $input['e2:e6:16:20:0a:35'] = '3';
    $input['d2:0a:2d:a0:04:be'] = '3';
    $input['00:a0:c6:00:00:00'] = '3';
    $input['d2:6b:25:2f:2c:e7'] = '3';
    $input['33:50:6f:45:30:30'] = '3';
    $input['0a:00:27:00:00:00'] = '3';
    $input['00:50:56:C0:00:01'] = '3';
    $input['00:50:56:C0:00:02'] = '3';
    $input['00:50:56:C0:00:03'] = '3';
    $input['00:50:56:C0:00:04'] = '3';
    $input['00:50:56:C0:00:08'] = '3';
    $input['FE:FF:FF:FF:FF:FF'] = '3';
    $input['00:00:00:00:00:00'] = '3';
    $input['00:0b:ca:fe:00:00'] = '3';
    $input['02:80:37:EC:02:00'] = '3';
    $input['MB-1234567890'] = '1';
    $input['Not Specified'] = '1';
    $input['OEM_Serial'] = '1';
    $input['SystemSerialNumb'] = '1';
    $input['Not'] = '2';
    foreach ($input as $value => $type) {
        $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputerblacklists`\n         WHERE `plugin_fusioninventory_criterium_id`='" . $type . "'\n          AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `glpi_plugin_fusioninventory_inventorycomputerblacklists`\n            (`plugin_fusioninventory_criterium_id`, `value`) VALUES\n            ( '" . $type . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    $migration->displayMessage("Add Crontasks");
    /*
     * Add Crontask if not exist
     */
    $crontask = new CronTask();
    if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjob', 'taskscheduler')) {
        $crontask->fields['itemtype'] = 'PluginFusioninventoryTask';
        $crontask->updateInDB(array('itemtype'));
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryTask', 'taskscheduler')) {
        CronTask::Register('PluginFusioninventoryTask', 'taskscheduler', '60', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjobstate', 'cleantaskjob') and $crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob')) {
        $crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob');
        $crontask->delete($crontask->fields);
    }
    if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob')) {
        $query = "UPDATE `glpi_crontasks` SET `itemtype`='PluginFusioninventoryTaskjobstate'\n         WHERE `itemtype`='PluginFusioninventoryTaskjobstatus'";
        $DB->query($query);
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryTaskjobstate', 'cleantaskjob')) {
        Crontask::Register('PluginFusioninventoryTaskjobstate', 'cleantaskjob', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if ($crontask->getFromDBbyName('PluginFusinvsnmpNetworkPortLog', 'cleannetworkportlogs')) {
        $crontask->delete($crontask->fields);
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryNetworkPortLog', 'cleannetworkportlogs')) {
        Crontask::Register('PluginFusioninventoryNetworkPortLog', 'cleannetworkportlogs', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if ($crontask->getFromDBbyName('PluginFusioninventoryConfigurationManagement', 'checkdevices')) {
        $crontask->delete($crontask->fields);
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryAgent', 'cleanoldagents')) {
        Crontask::Register('PluginFusioninventoryAgent', 'cleanoldagents', 86400, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'hourmin' => 22, 'hourmax' => 6, 'comment' => 'Clean agents not contacted since xxx days'));
    }
    /*
     * Update task's agents list from dynamic group periodically in order to automatically target new
     * computer.
     */
    if (!$crontask->getFromDBbyName('PluginFusioninventoryTaskjob', 'updatedynamictasks')) {
        CronTask::Register('PluginFusioninventoryTaskjob', 'updatedynamictasks', '60', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'state' => 0));
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryAgentWakeup', 'wakeupAgents')) {
        Crontask::Register('PluginFusioninventoryAgentWakeup', 'wakeupAgents', 120, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'comment' => 'Wake agents ups'));
    }
    /**
     * Add field to manage which group can be refreshed by updatedynamictasks crontask
     */
    if (!FieldExists('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group')) {
        $migration->addField('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group', 'bool');
        $migration->addKey('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group');
        $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_dynamicdatas');
    }
    //   $pfIgnoredimportdevice = new PluginFusioninventoryIgnoredimportdevice();
    //   $pfIgnoredimportdevice->install();
    //Change static & dynamic structure to fit the GLPI framework
    $migration->changeField('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'groups_id', 'plugin_fusioninventory_deploygroups_id', 'integer');
    $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_dynamicdatas');
    $migration->changeField('glpi_plugin_fusioninventory_deploygroups_staticdatas', 'groups_id', 'plugin_fusioninventory_deploygroups_id', 'integer');
    $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_staticdatas');
    // Delete data in glpi_logs(agent problem => ticket http://forge.fusioninventory.org/issues/1546)
    // ** Token
    $query = "DELETE FROM `glpi_logs`\n      WHERE `itemtype`='PluginFusioninventoryAgent'\n         AND `id_search_option`='9'";
    $DB->query($query);
    // ** Last contact
    $query = "DELETE FROM `glpi_logs`\n      WHERE `itemtype`='PluginFusioninventoryAgent'\n         AND `id_search_option`='4'";
    $DB->query($query);
    // ** Version
    $query = "DELETE FROM `glpi_logs`\n      WHERE `itemtype`='PluginFusioninventoryAgent'\n         AND `id_search_option`='8'\n         AND `old_value`=`new_value`";
    $DB->query($query);
    /*
     * Manage devices with is_dynamic
     */
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipments`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $DB->query("UPDATE `glpi_networkequipments` SET `is_dynamic`='1'\n                        WHERE `id`='" . $data['networkequipments_id'] . "'");
    }
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercomputers`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $DB->query("UPDATE `glpi_computers` SET `is_dynamic`='1'\n                        WHERE `id`='" . $data['computers_id'] . "'");
    }
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_printers`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $DB->query("UPDATE `glpi_printers` SET `is_dynamic`='1'\n                        WHERE `id`='" . $data['printers_id'] . "'");
    }
    // Update networkports types
    $pfNetworkporttype = new PluginFusioninventoryNetworkporttype();
    $pfNetworkporttype->init();
    if (TableExists('glpi_plugin_fusioninventory_profiles')) {
        //Migrate rights to the new system introduction in GLPI 0.85
        PluginFusioninventoryProfile::migrateProfiles();
        //Drop old table
        $migration->dropTable('glpi_plugin_fusioninventory_profiles');
    }
    //Create first access to the current profile is needed
    if (isset($_SESSION['glpiactiveprofile'])) {
        PluginFusioninventoryProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    }
    // Define lastup field of fusion networkports
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_mappings`\n      WHERE `name`='ifstatus'\n      LIMIT 1";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $query_np = "SELECT * FROM `glpi_plugin_fusioninventory_networkports`";
        $result_np = $DB->query($query_np);
        while ($data_np = $DB->fetch_array($result_np)) {
            $query_nplog = "SELECT * FROM `glpi_plugin_fusioninventory_networkportlogs`\n            WHERE `networkports_id`='" . $data_np['networkports_id'] . "'\n               AND `plugin_fusioninventory_mappings_id`='" . $data['id'] . "'\n            ORDER BY `date_mod` DESC\n            LIMIT 1";
            $result_nplog = $DB->query($query_nplog);
            while ($data_nplog = $DB->fetch_array($result_nplog)) {
                $DB->query("UPDATE `glpi_plugin_fusioninventory_networkports`\n               SET `lastup`='" . $data_nplog['date_mod'] . "'\n               WHERE `id`='" . $data_np['id'] . "'");
            }
        }
    }
    //Migrate search params for dynamic groups
    doDynamicDataSearchParamsMigration();
}
 /**
  * Import IPs
  *
  * @param $p_ips IPs code to import
  * @param $networkequipments_id id of network equipment
  *
  * @return errors string to be alimented if import ko / '' if ok
  **/
 function internalPorts($a_ips, $networkequipments_id, $mac, $networkname_name)
 {
     $networkPort = new NetworkPort();
     $iPAddress = new IPAddress();
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $networkName = new NetworkName();
     // Get agregated ports
     $a_networkPortAggregates = current($networkPort->find("`itemtype`='NetworkEquipment'\n                       AND `items_id`='" . $networkequipments_id . "'\n                       AND `instantiation_type`='NetworkPortAggregate'\n                       AND `logical_number` = '0'", '', 1));
     $a_ips_DB = array();
     $networkports_id = 0;
     if (isset($a_networkPortAggregates['id'])) {
         $a_networkPortAggregates['mac'] = $mac;
         $networkPort->update($a_networkPortAggregates);
         $networkports_id = $a_networkPortAggregates['id'];
     } else {
         $input = array();
         $input['itemtype'] = 'NetworkEquipment';
         $input['items_id'] = $networkequipments_id;
         $input['instantiation_type'] = 'NetworkPortAggregate';
         $input['name'] = 'general';
         $input['mac'] = $mac;
         $networkports_id = $networkPort->add($input);
     }
     // Get networkname
     $a_networknames_find = current($networkName->find("`items_id`='" . $networkports_id . "'\n                                                         AND `itemtype`='NetworkPort'", "", 1));
     $networknames_id = 0;
     if (isset($a_networknames_find['id'])) {
         $networknames_id = $a_networknames_find['id'];
         $a_networknames_find['name'] = $networkname_name;
         $networkName->update($a_networknames_find);
     } else {
         $input = array();
         $input['items_id'] = $networkports_id;
         $input['itemtype'] = 'NetworkPort';
         $input['name'] = $networkname_name;
         $networknames_id = $networkName->add($input);
     }
     $a_ips_fromDB = $iPAddress->find("`itemtype`='NetworkName'\n                                    AND `items_id`='" . $networknames_id . "'");
     foreach ($a_ips_fromDB as $data) {
         $a_ips_DB[$data['id']] = $data['name'];
     }
     foreach ($a_ips as $key => $ip) {
         foreach ($a_ips_DB as $keydb => $ipdb) {
             if ($ip == $ipdb) {
                 unset($a_ips[$key]);
                 unset($a_ips_DB[$keydb]);
                 break;
             }
         }
     }
     if (count($a_ips) == 0 and count($a_ips_DB) == 0) {
         // Nothing to do
     } else {
         if (count($a_ips_DB) != 0 && count($a_ips) != 0) {
             // Delete IPs in DB
             foreach ($a_ips_DB as $idtmp => $ip) {
                 $iPAddress->delete(array('id' => $idtmp));
             }
         }
         if (count($a_ips) != 0) {
             foreach ($a_ips as $ip) {
                 if ($ip != '127.0.0.1') {
                     $input = array();
                     $input['entities_id'] = 0;
                     $input['itemtype'] = 'NetworkName';
                     $input['items_id'] = $networknames_id;
                     $input['name'] = $ip;
                     $iPAddress->add($input);
                     // Search in unmanaged device if device with IP (LLDP) is yet added, in this case,
                     // we get id of this unmanaged device
                     $a_manageds = $pfUnmanaged->find("`ip`='" . $ip . "'", "", 1);
                     if (count($a_manageds) > 0) {
                         $datas = current($a_unmanageds);
                         $this->unmanagedCDP = $datas['id'];
                     }
                 }
             }
         }
     }
 }