Exemplo n.º 1
0
 /**
  * @see CommonGLPI::getAdditionalMenuOptions()
  **/
 static function getAdditionalMenuOptions()
 {
     if (static::canView()) {
         $options['networkportmigration']['title'] = NetworkPortMigration::getTypeName(Session::getPluralNumber());
         $options['networkportmigration']['page'] = NetworkPortMigration::getSearchURL(false);
         $options['networkportmigration']['search'] = NetworkPortMigration::getSearchURL(false);
         return $options;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Show ports for an item
  *
  * @param $item                     CommonDBTM object
  * @param $withtemplate   integer   withtemplate param (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $rand = mt_rand();
     $itemtype = $item->getType();
     $items_id = $item->getField('id');
     if (!Session::haveRight('networking', 'r') || !$item->can($items_id, 'r')) {
         return false;
     }
     $netport = new self();
     $netport->item = $item;
     if ($itemtype == 'NetworkPort') {
         $canedit = false;
     } else {
         $canedit = $item->can($items_id, 'w');
     }
     $showmassiveactions = false;
     if ($withtemplate != 2) {
         $showmassiveactions = $canedit;
     }
     // Show Add Form
     if ($canedit && (empty($withtemplate) || $withtemplate != 2)) {
         echo "\n<form method='get' action='" . $netport->getFormURL() . "'>\n";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>\n";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n";
         echo "<div class='firstbloc'><table class='tab_cadre_fixe'>\n";
         echo "<tr class='tab_bg_2'><td class='center'>\n";
         _e('Network port type to be added');
         echo "&nbsp;";
         $instantiations = array();
         foreach (self::getNetworkPortInstantiations() as $inst_type) {
             if (call_user_func(array($inst_type, 'canCreate'))) {
                 $instantiations[$inst_type] = call_user_func(array($inst_type, 'getTypeName'));
             }
         }
         Dropdown::showFromArray('instantiation_type', $instantiations, array('value' => 'NetworkPortEthernet'));
         echo "</td>\n";
         echo "<td class='tab_bg_2 center' width='50%'>";
         _e('Add several ports');
         echo "&nbsp;<input type='checkbox' name='several' value='1'></td>\n";
         echo "<td>\n";
         echo "<input type='submit' name='create' value=\"" . _sx('button', 'Add') . "\" class='submit'>\n";
         echo "</td></tr></table></div>\n";
         Html::closeForm();
     }
     if ($showmassiveactions) {
         $checkbox_column = true;
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
     } else {
         $checkbox_column = false;
     }
     $is_active_network_port = false;
     Session::initNavigateListItems('NetworkPort', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
     if ($itemtype == 'NetworkPort') {
         $porttypes = array('NetworkPortAlias', 'NetworkPortAggregate');
     } else {
         $porttypes = self::getNetworkPortInstantiations();
         // Manage NetworkportMigration
         $porttypes[] = '';
     }
     $display_options = self::getDisplayOptions($itemtype);
     $table = new HTMLTableMain();
     $number_port = self::countForItem($item);
     $table_options = array('canedit' => $canedit, 'display_options' => &$display_options);
     // Make table name and add the correct show/hide parameters
     $table_name = sprintf(__('%1$s: %2$d'), self::getTypeName($number_port), $number_port);
     // Add the link to the popup to display the options ...
     $table_namelink = self::getDisplayOptionsLink($itemtype);
     $table_name = sprintf(__('%1$s - %2$s'), $table_name, $table_namelink);
     $table->setTitle($table_name);
     $c_main = $table->addHeader('main', self::getTypeName(2));
     if ($display_options['dynamic_import'] && $item->isDynamic()) {
         $table_options['display_isDynamic'] = true;
     } else {
         $table_options['display_isDynamic'] = false;
     }
     if ($display_options['characteristics']) {
         $c_instant = $table->addHeader('Instantiation', __('Characteristics'));
         $c_instant->setHTMLClass('center');
     }
     if ($display_options['internet']) {
         $options = array('names' => 'NetworkName', 'aliases' => 'NetworkAlias', 'ipaddresses' => 'IPAddress', 'ipnetworks' => 'IPNetwork');
         $table_options['dont_display'] = array();
         foreach ($options as $option => $itemtype_for_option) {
             if (!$display_options[$option]) {
                 $table_options['dont_display'][$itemtype_for_option] = true;
             }
         }
         $c_network = $table->addHeader('Internet', _n(__('Internet information'), __('Internet information'), 2));
         $c_network->setHTMLClass('center');
     } else {
         $c_network = NULL;
     }
     foreach ($porttypes as $portType) {
         if (empty($portType)) {
             $group_name = 'Migration';
             $group_title = __('Network ports waiting for manual migration');
         } else {
             $group_name = $portType;
             $group_title = $portType::getTypeName(2);
         }
         $t_group = $table->createGroup($group_name, $group_title);
         if ($withtemplate != 2 && $canedit) {
             $c_checkbox = $t_group->addHeader('checkbox', Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand, '__RAND__'), $c_main);
         } else {
             $c_checkbox = NULL;
         }
         $c_number = $t_group->addHeader('NetworkPort', "#", $c_main);
         $c_name = $t_group->addHeader("Name", __('Name'), $c_main);
         $c_name->setItemType('NetworkPort');
         $c_name->setHTMLClass('center');
         if ($table_options['display_isDynamic']) {
             $c_dynamic = $t_group->addHeader("Dynamic", __('Automatic inventory'), $c_main);
             $c_dynamic->setHTMLClass('center');
         }
         if ($display_options['characteristics']) {
             if (empty($portType)) {
                 NetworkPortMigration::getMigrationInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options);
             } else {
                 $instantiation = new $portType();
                 $instantiation->getInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options);
                 unset($instantiation);
             }
         }
         if ($display_options['internet'] && !$display_options['characteristics']) {
             NetworkName::getHTMLTableHeader(__CLASS__, $t_group, $c_network, NULL, $table_options);
         }
         if ($itemtype == 'NetworkPort') {
             switch ($portType) {
                 case 'NetworkPortAlias':
                     $search_table = 'glpi_networkportaliases';
                     $search_request = "`networkports_id_alias`='{$items_id}'";
                     break;
                 case 'NetworkPortAggregate':
                     $search_table = 'glpi_networkportaggregates';
                     $search_request = "`networkports_id_list` like '%\"{$items_id}\"%'";
                     break;
             }
             $query = "SELECT `networkports_id` AS id\n                      FROM  `{$search_table}`\n                      WHERE {$search_request}";
         } else {
             $query = "SELECT `id`\n                      FROM `glpi_networkports`\n                      WHERE `items_id` = '{$items_id}'\n                            AND `itemtype` = '{$itemtype}'\n                            AND `instantiation_type` = '{$portType}'\n                            AND `is_deleted` = '0'\n                      ORDER BY `name`,\n                               `logical_number`";
         }
         if ($result = $DB->query($query)) {
             echo "<div class='spaced'>";
             $number_port = $DB->numrows($result);
             if ($number_port != 0) {
                 $is_active_network_port = true;
                 $save_canedit = $canedit;
                 if (!empty($portType)) {
                     $name = sprintf(__('%1$s (%2$s)'), self::getTypeName($number_port), call_user_func(array($portType, 'getTypeName')));
                     $name = sprintf(__('%1$s: %2$s'), $name, $number_port);
                 } else {
                     $name = __('Network ports waiting for manual migration');
                     $canedit = false;
                 }
                 while ($devid = $DB->fetch_row($result)) {
                     $t_row = $t_group->createRow();
                     $netport->getFromDB(current($devid));
                     // No massive action for migration ports
                     if ($withtemplate != 2 && $canedit && !empty($portType)) {
                         $ce_checkbox = $t_row->addCell($c_checkbox, "<input type='checkbox' name='item[" . $netport->fields["id"] . "]' value='1'>");
                     } else {
                         $ce_checkbox = NULL;
                     }
                     $content = "<span class='b'>";
                     // Display link based on default rights
                     if ($save_canedit && $withtemplate != 2) {
                         if (!empty($portType)) {
                             $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">";
                         } else {
                             $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkportmigration.form.php?id=" . $netport->fields["id"] . "\">";
                         }
                     }
                     $content .= $netport->fields["logical_number"];
                     if ($canedit && $withtemplate != 2) {
                         $content .= "</a>";
                     }
                     $content .= "</span>";
                     $content .= Html::showToolTip($netport->fields['comment'], array('display' => false));
                     $t_row->addCell($c_number, $content);
                     $value = $netport->fields["name"];
                     $t_row->addCell($c_name, $value, NULL, $netport);
                     if ($table_options['display_isDynamic']) {
                         $t_row->addCell($c_dynamic, Dropdown::getYesNo($netport->fields['is_dynamic']));
                     }
                     $instant_cell = NULL;
                     if ($display_options['characteristics']) {
                         $instantiation = $netport->getInstantiation();
                         if ($instantiation !== false) {
                             $instantiation->getInstantiationHTMLTable($netport, $t_row, NULL, $table_options);
                             unset($instantiation);
                         }
                     } else {
                         if ($display_options['internet']) {
                             NetworkName::getHTMLTableCellsForItem($t_row, $netport, NULL, $table_options);
                         }
                     }
                 }
                 $canedit = $save_canedit;
             }
             echo "</div>";
         }
     }
     if ($is_active_network_port && $showmassiveactions) {
         $massiveactionparams = array('num_displayed' => $number_port, 'check_itemtype' => $itemtype, 'check_items_id' => $items_id);
         Html::showMassiveActions('NetworkPort', $massiveactionparams);
     }
     $table->display(array('display_thead' => false, 'display_tfoot' => false));
     unset($table);
     if (!$is_active_network_port) {
         echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network port found') . "</th></tr>";
         echo "</table>";
     }
     if ($showmassiveactions) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions('NetworkPort', $massiveactionparams);
         Html::closeForm();
     }
 }
Exemplo n.º 3
0
/**
 * Update all Network Organisation
 *
 * @param $ADDTODISPLAYPREF
**/
function updateNetworkFramework(&$ADDTODISPLAYPREF)
{
    global $DB, $migration;
    $ADDTODISPLAYPREF['FQDN'] = array(11);
    $ADDTODISPLAYPREF['WifiNetwork'] = array(10);
    $ADDTODISPLAYPREF['NetworkPortMigration'] = array();
    $ADDTODISPLAYPREF['IPNetwork'] = array(14, 10, 11, 12, 13);
    $ADDTODISPLAYPREF['NetworkName'] = array(12, 13);
    $optionIndex = 10;
    foreach (NetworkPortMigration::getMotives() as $key => $name) {
        $ADDTODISPLAYPREF['NetworkPortMigration'][] = $optionIndex++;
    }
    $migration->displayMessage(sprintf(__('Data migration - %s'), 'Network framework'));
    $originTables = array();
    foreach (array('glpi_networkports', 'glpi_networkequipments') as $table) {
        $originTables[$table] = 'origin_' . $table;
    }
    if (!TableExists('origin_glpi_networkequipments')) {
        // remove of mac field from glpi_networkequipments is done at the end of migration
        // framework process
        if (!FieldExists('glpi_networkequipments', 'mac')) {
            // Nothing to be done : migration of NetworkPort already OK !
            // But don't add display preference for NetworkPortMigration if none exists
            if (!TableExists('glpi_networkportmigrations')) {
                unset($ADDTODISPLAYPREF['NetworkPortMigration']);
            }
            $migration->displayWarning('Network Framework already migrated: nothing to be done !', false);
            return;
        }
        foreach ($originTables as $table => $originTable) {
            if (!TableExists($originTable) && TableExists($table)) {
                $migration->copyTable($table, $originTable);
                $migration->displayWarning("To be safe, we are working on {$originTable}. " . "It is a copy of {$table}", false);
            }
        }
    }
    // Remove all tables created by any previous migration
    $new_network_ports = array('glpi_fqdns', 'glpi_ipaddresses', 'glpi_ipaddresses_ipnetworks', 'glpi_ipnetworks', 'glpi_networkaliases', 'glpi_networknames', 'glpi_networkportaggregates', 'glpi_networkportdialups', 'glpi_networkportethernets', 'glpi_networkportlocals', 'glpi_networkportmigrations', 'glpi_networkportwifis', 'glpi_wifinetworks');
    foreach ($new_network_ports as $table) {
        $migration->dropTable($table);
    }
    // Create the glpi_networkportmigrations that is a copy of origin_glpi_networkports
    $query = "CREATE TABLE `glpi_networkportmigrations` LIKE `origin_glpi_networkports`";
    $DB->queryOrDie($query, "0.84 create glpi_networkportmigrations");
    // And add the error motive fields
    foreach (NetworkPortMigration::getMotives() as $key => $name) {
        $migration->addField('glpi_networkportmigrations', $key, 'bool');
    }
    $migration->migrationOneTable('glpi_networkportmigrations');
    $migration->displayMessage(sprintf(__('Data migration - %s'), 'glpi_fqdns'));
    // Adding FQDN table
    if (!TableExists('glpi_fqdns')) {
        $query = "CREATE TABLE `glpi_fqdns` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `entities_id` int(11) NOT NULL DEFAULT '0',\n                  `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n                  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `fqdn` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `comment` text COLLATE utf8_unicode_ci,\n                  PRIMARY KEY (`id`),\n                  KEY `entities_id` (`entities_id`),\n                  KEY `name` (`name`),\n                  KEY `fqdn` (`fqdn`),\n                  KEY `is_recursive` (`is_recursive`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_fqdns");
        $fqdn = new FQDN();
        // Then, populate it from domains (beware that "domains" can be FQDNs and Windows workgroups)
        $query = "SELECT DISTINCT LOWER(`name`) AS name, `comment`\n                FROM `glpi_domains`";
        foreach ($DB->request($query) as $domain) {
            $domainName = $domain['name'];
            // We ensure that domains have at least 1 dote to be sure it is not a Windows workgroup
            if (strpos($domainName, '.') !== false && FQDN::checkFQDN($domainName)) {
                $migration->insertInTable($fqdn->getTable(), array('entities_id' => 0, 'name' => $domainName, 'fqdn' => $domainName, 'comment' => $domain['comment']));
            }
        }
    }
    $migration->displayMessage(sprintf(__('Data migration - %s'), 'glpi_ipaddresses'));
    // Adding IPAddress table
    if (!TableExists('glpi_ipaddresses')) {
        $query = "CREATE TABLE `glpi_ipaddresses` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `entities_id` int(11) NOT NULL DEFAULT '0',\n                  `items_id` int(11) NOT NULL DEFAULT '0',\n                  `itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n                  `version` tinyint unsigned DEFAULT '0',\n                  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `binary_0`  int unsigned NOT NULL DEFAULT '0',\n                  `binary_1`  int unsigned NOT NULL DEFAULT '0',\n                  `binary_2`  int unsigned NOT NULL DEFAULT '0',\n                  `binary_3`  int unsigned NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  KEY `entities_id` (`entities_id`),\n                  KEY `textual` (`name`),\n                  KEY `binary` (`binary_0`, `binary_1`, `binary_2`, `binary_3`),\n                  KEY `item` (`itemtype`, `items_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_ipaddresses");
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), 'glpi_wifinetworks'));
    // Adding WifiNetwork table
    if (!TableExists('glpi_wifinetworks')) {
        $query = "CREATE TABLE `glpi_wifinetworks` (\n                 `id` int(11) NOT NULL AUTO_INCREMENT,\n                 `entities_id` int(11) NOT NULL DEFAULT '0',\n                 `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n                 `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                 `essid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                 `mode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL\n                        COMMENT 'ad-hoc, access_point',\n                 `comment` text COLLATE utf8_unicode_ci,\n                 PRIMARY KEY (`id`),\n                 KEY `entities_id` (`entities_id`),\n                 KEY `essid` (`essid`),\n                 KEY `name` (`name`)\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_wifinetworks");
    }
    $migration->displayMessage(sprintf(__('Data migration - %s'), "glpi_ipnetworks"));
    // Adding IPNetwork table
    if (!TableExists('glpi_ipnetworks')) {
        $query = "CREATE TABLE `glpi_ipnetworks` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `entities_id` int(11) NOT NULL DEFAULT '0',\n                  `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n                  `ipnetworks_id` int(11) NOT NULL DEFAULT '0',\n                  `completename` text COLLATE utf8_unicode_ci,\n                  `level` int(11) NOT NULL DEFAULT '0',\n                  `ancestors_cache` longtext COLLATE utf8_unicode_ci,\n                  `sons_cache` longtext COLLATE utf8_unicode_ci,\n                  `addressable` tinyint(1) NOT NULL DEFAULT '0',\n                  `version` tinyint unsigned DEFAULT '0',\n                  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `address` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `address_0`  int unsigned NOT NULL DEFAULT '0',\n                  `address_1`  int unsigned NOT NULL DEFAULT '0',\n                  `address_2`  int unsigned NOT NULL DEFAULT '0',\n                  `address_3`  int unsigned NOT NULL DEFAULT '0',\n                  `netmask` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `netmask_0`  int unsigned NOT NULL DEFAULT '0',\n                  `netmask_1`  int unsigned NOT NULL DEFAULT '0',\n                  `netmask_2`  int unsigned NOT NULL DEFAULT '0',\n                  `netmask_3`  int unsigned NOT NULL DEFAULT '0',\n                  `gateway` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `gateway_0`  int unsigned NOT NULL DEFAULT '0',\n                  `gateway_1`  int unsigned NOT NULL DEFAULT '0',\n                  `gateway_2`  int unsigned NOT NULL DEFAULT '0',\n                  `gateway_3`  int unsigned NOT NULL DEFAULT '0',\n                  `comment` text COLLATE utf8_unicode_ci,\n                  PRIMARY KEY (`id`),\n                  KEY `network_definition` (`entities_id`,`address`,`netmask`),\n                  KEY `address` (`address_0`, `address_1`, `address_2`, `address_3`),\n                  KEY `netmask` (`netmask_0`, `netmask_1`, `netmask_2`, `netmask_3`),\n                  KEY `gateway` (`gateway_0`, `gateway_1`, `gateway_2`, `gateway_3`),\n                  KEY `name` (`name`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_ipnetworks");
        // Retrieve all the networks from the current network ports and add them to the IPNetworks
        $query = "SELECT DISTINCTROW INET_NTOA(INET_ATON(`ip`)&INET_ATON(`netmask`)) AS address,\n                     `netmask`, `gateway`, `entities_id`\n                FROM `origin_glpi_networkports`\n                ORDER BY `gateway` DESC";
        $address = new IPAddress();
        $netmask = new IPNetmask();
        $gateway = new IPAddress();
        $network = new IPNetwork();
        foreach ($DB->request($query) as $entry) {
            $address = $entry['address'];
            $netmask = $entry['netmask'];
            $gateway = $entry['gateway'];
            $entities_id = $entry['entities_id'];
            if (empty($address) || $address == '0.0.0.0' || empty($netmask) || $netmask == '0.0.0.0' || $netmask == '255.255.255.255') {
                continue;
            }
            if ($gateway == '0.0.0.0') {
                $gateway = '';
            }
            $networkDefinition = "{$address}/{$netmask}";
            $networkName = $networkDefinition . (empty($gateway) ? "" : " - " . $gateway);
            $input = array('entities_id' => $entities_id, 'name' => $networkName, 'network' => $networkDefinition, 'gateway' => $gateway, 'ipnetworks_id' => 0, 'addressable' => 1, 'completename' => $networkName, 'level' => 1);
            $preparedInput = $network->prepareInput($input);
            if (is_array($preparedInput['input'])) {
                $input = $preparedInput['input'];
                if (isset($preparedInput['error'])) {
                    $query = "SELECT id, items_id, itemtype\n                         FROM origin_glpi_networkports\n                         WHERE INET_NTOA(INET_ATON(`ip`)&INET_ATON(`netmask`)) = '{$address}'\n                               AND `netmask` = '{$netmask}'\n                               AND `gateway` = '{$gateway}'\n                               AND `entities_id` = '{$entities_id}'";
                    $result = $DB->query($query);
                    foreach ($DB->request($query) as $data) {
                        addNetworkPortMigrationError($data['id'], 'invalid_gateway');
                        logNetworkPortError('network warning', $data['id'], $data['itemtype'], $data['items_id'], $preparedInput['error']);
                    }
                }
                $migration->insertInTable($network->getTable(), $input);
            } else {
                if (isset($preparedInput['error'])) {
                    $query = "SELECT id, items_id, itemtype\n                      FROM origin_glpi_networkports\n                      WHERE INET_NTOA(INET_ATON(`ip`)&INET_ATON(`netmask`)) = '" . $entry['address'] . "'\n                            AND `netmask` = '{$netmask}'\n                            AND `gateway` = '{$gateway}'\n                            AND `entities_id` = '{$entities_id}'";
                    $result = $DB->query($query);
                    foreach ($DB->request($query) as $data) {
                        addNetworkPortMigrationError($data['id'], 'invalid_network');
                        logNetworkPortError('network error', $data['id'], $data['itemtype'], $data['items_id'], $preparedInput['error']);
                    }
                }
            }
        }
    }
    $migration->displayMessage(sprintf(__('Data migration - %s'), "glpi_ipnetworks_vlans"));
    // Adding IPNetwork table
    if (!TableExists('glpi_ipnetworks_vlans')) {
        $query = "CREATE TABLE `glpi_ipnetworks_vlans` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `ipnetworks_id` int(11) NOT NULL DEFAULT '0',\n                  `vlans_id` int(11) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `link` (`ipnetworks_id`, `vlans_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->queryOrDie($query, "0.84 create glpi_ipnetworks_vlans");
    }
    $migration->displayMessage(sprintf(__('Data migration - %s'), "glpi_networknames"));
    // Adding NetworkName table
    if (!TableExists('glpi_networknames')) {
        $query = "CREATE TABLE `glpi_networknames` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `entities_id` int(11) NOT NULL DEFAULT '0',\n                  `items_id` int(11) NOT NULL DEFAULT '0',\n                  `itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n                  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `comment` text COLLATE utf8_unicode_ci,\n                  `fqdns_id` int(11) NOT NULL DEFAULT '0',\n                  `is_deleted` tinyint(1) NOT NULL DEFAULT '0',\n                  `is_dynamic` tinyint(1) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  KEY `entities_id` (`entities_id`),\n                  KEY `FQDN` (`name`,`fqdns_id`),\n                  KEY `name` (`name`),\n                  KEY `item` (`itemtype`, `items_id`),\n                  KEY `fqdns_id` (`fqdns_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_networknames");
        // Retrieve all the networks from the current network ports and add them to the IPNetworks
        $query = "SELECT `ip`, `id`, `entities_id`, `itemtype`, `items_id`\n                FROM `origin_glpi_networkports`\n                WHERE `ip` <> ''";
        foreach ($DB->request($query) as $entry) {
            if (empty($entry["ip"])) {
                continue;
            }
            createNetworkNameFromItem('NetworkPort', $entry['id'], $entry['items_id'], $entry['itemtype'], $entry['entities_id'], $entry["ip"]);
        }
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), "glpi_networkaliases"));
    // Adding NetworkAlias table
    if (!TableExists('glpi_networkaliases')) {
        $query = "CREATE TABLE `glpi_networkaliases` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `entities_id` int(11) NOT NULL DEFAULT '0',\n                  `networknames_id` int(11) NOT NULL DEFAULT '0',\n                  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `fqdns_id` int(11) NOT NULL DEFAULT '0',\n                  `comment` text COLLATE utf8_unicode_ci,\n                  PRIMARY KEY (`id`),\n                  KEY `entities_id` (`entities_id`),\n                  KEY `name` (`name`),\n                  KEY `networknames_id` (`networknames_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_networkaliases");
    }
    $migration->displayMessage(sprintf(__('Data migration - %s'), "glpi_ipaddresses_ipnetworks"));
    // Adding IPAddress_IPNetwork table
    if (!TableExists('glpi_ipaddresses_ipnetworks')) {
        $query = "CREATE TABLE `glpi_ipaddresses_ipnetworks` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `ipaddresses_id` int(11) NOT NULL DEFAULT '0',\n                  `ipnetworks_id` int(11) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `unicity` (`ipaddresses_id`,`ipnetworks_id`),\n                  KEY `ipnetworks_id` (`ipnetworks_id`),\n                  KEY `ipaddresses_id` (`ipaddresses_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->queryOrDie($query, "0.84 create glpi_ipaddresses_ipnetworks");
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), "glpi_networkinterfaces"));
    // Update NetworkPorts
    $migration->addField('glpi_networkports', 'instantiation_type', 'string', array('after' => 'name', 'update' => "'NetworkPortEthernet'"));
    $migration->displayMessage(sprintf(__('Data migration - %s'), "glpi_networkports"));
    // Retrieve all the networks from the current network ports and add them to the IPNetwork
    $query = "SELECT *\n             FROM `glpi_networkinterfaces`";
    foreach ($DB->request($query) as $entry) {
        $instantiation_type = "";
        switch ($entry['name']) {
            case 'Local':
                $instantiation_type = "NetworkPortLocal";
                break;
            case 'Ethernet':
                $instantiation_type = "NetworkPortEthernet";
                break;
            case 'Wifi':
                $instantiation_type = "NetworkPortWifi";
                break;
            case 'Dialup':
                $instantiation_type = "NetworkPortDialup";
                break;
            default:
                if (preg_match('/TX/i', $entry['name']) || preg_match('/SX/i', $entry['name']) || preg_match('/Ethernet/i', $entry['name'])) {
                    $instantiation_type = "NetworkPortEthernet";
                }
                break;
        }
        /// In case of unknown Interface Type, we should have to set instantiation_type to ''
        /// Thus we should be able to convert it later to correct type (ethernet, wifi, loopback ...)
        if (!empty($instantiation_type)) {
            $query = "UPDATE `glpi_networkports`\n                   SET `instantiation_type` = '{$instantiation_type}'\n                   WHERE `id` IN (SELECT `id`\n                                  FROM `origin_glpi_networkports`\n                                  WHERE `networkinterfaces_id` = '" . $entry['id'] . "')";
            $DB->queryOrDie($query, "0.84 update instantiation_type field of glpi_networkports");
            // Clear $instantiation_type for next check inside the loop
            unset($instantiation_type);
        }
    }
    foreach (array('ip', 'gateway', 'netmask', 'netpoints_id', 'networkinterfaces_id', 'subnet') as $field) {
        $migration->dropField('glpi_networkports', $field);
    }
    foreach (array('ip', 'mac') as $field) {
        $migration->dropField('glpi_networkequipments', $field);
    }
    $migration->displayMessage(sprintf(__('Data migration - %s'), 'Index mac field and transform address mac to lower'));
    $query = "UPDATE `glpi_networkports`\n             SET `mac` = LOWER(`mac`)";
    $DB->queryOrDie($query, "0.84 transforme MAC to lower case");
    $migration->addKey('glpi_networkports', 'mac');
    $migration->displayMessage(sprintf(__('Data migration - %s'), 'Update migration of interfaces errors'));
    $query = "SELECT id\n             FROM `glpi_networkports`\n             WHERE `instantiation_type` = ''";
    foreach ($DB->request($query) as $networkPortID) {
        addNetworkPortMigrationError($networkPortID['id'], 'unknown_interface_type');
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), "glpi_networkportethernets"));
    // Adding NetworkPortEthernet table
    if (!TableExists('glpi_networkportethernets')) {
        $query = "CREATE TABLE `glpi_networkportethernets` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `networkports_id` int(11) NOT NULL DEFAULT '0',\n                  `items_devicenetworkcards_id` int(11) NOT NULL DEFAULT '0',\n                  `netpoints_id` int(11) NOT NULL DEFAULT '0',\n                  `type` varchar(10) COLLATE utf8_unicode_ci DEFAULT '' COMMENT 'T, LX, SX',\n                  `speed` int(11) NOT NULL DEFAULT '10' COMMENT 'Mbit/s: 10, 100, 1000, 10000',\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `networkports_id` (`networkports_id`),\n                  KEY `card` (`items_devicenetworkcards_id`),\n                  KEY `netpoint` (`netpoints_id`),\n                  KEY `type` (`type`),\n                  KEY `speed` (`speed`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_networkportethernets");
        $port = new NetworkPortEthernet();
        updateNetworkPortInstantiation($port, array('`netpoints_id`' => 'netpoints_id'), true);
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), "glpi_networkportwifis"));
    // Adding NetworkPortWifi table
    if (!TableExists('glpi_networkportwifis')) {
        $query = "CREATE TABLE `glpi_networkportwifis` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `networkports_id` int(11) NOT NULL DEFAULT '0',\n                  `items_devicenetworkcards_id` int(11) NOT NULL DEFAULT '0',\n                  `wifinetworks_id` int(11) NOT NULL DEFAULT '0',\n                  `networkportwifis_id` int(11) NOT NULL DEFAULT '0'\n                                        COMMENT 'only usefull in case of Managed node',\n                  `version` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL\n                            COMMENT 'a, a/b, a/b/g, a/b/g/n, a/b/g/n/y',\n                  `mode` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL\n                         COMMENT 'ad-hoc, managed, master, repeater, secondary, monitor, auto',\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `networkports_id` (`networkports_id`),\n                  KEY `card` (`items_devicenetworkcards_id`),\n                  KEY `essid` (`wifinetworks_id`),\n                  KEY `version` (`version`),\n                  KEY `mode` (`mode`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_networkportwifis");
        $port = new NetworkPortWifi();
        updateNetworkPortInstantiation($port, array(), true);
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), "glpi_networkportlocals"));
    // Adding NetworkPortLocal table
    if (!TableExists('glpi_networkportlocals')) {
        $query = "CREATE TABLE `glpi_networkportlocals` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `networkports_id` int(11) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `networkports_id` (`networkports_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_networkportlocals");
        $port = new NetworkPortLocal();
        updateNetworkPortInstantiation($port, array(), false);
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), "glpi_networkportdialups"));
    // Adding NetworkPortDialup table
    if (!TableExists('glpi_networkportdialups')) {
        $query = "CREATE TABLE `glpi_networkportdialups` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `networkports_id` int(11) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `networkports_id` (`networkports_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_networkportdialups");
        $port = new NetworkPortDialup();
        updateNetworkPortInstantiation($port, array(), true);
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), "glpi_networkportaggregates"));
    // Adding NetworkPortAggregate table
    if (!TableExists('glpi_networkportaggregates')) {
        $query = "CREATE TABLE `glpi_networkportaggregates` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `networkports_id` int(11) NOT NULL DEFAULT '0',\n                  `networkports_id_list` TEXT DEFAULT NULL\n                             COMMENT 'array of associated networkports_id',\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `networkports_id` (`networkports_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_networkportaggregates");
        // Transform NetworkEquipment local MAC address as a networkport that aggregates all ports
        $query = "SELECT *\n                FROM `origin_glpi_networkequipments`\n                WHERE `mac` != ''\n                      OR `ip` != ''";
        $port_input = array('itemtype' => 'NetworkEquipment', 'logical_number' => '0', 'name' => 'management', 'instantiation_type' => 'NetworkPortAggregate');
        foreach ($DB->request($query) as $equipment) {
            $networkequipments_id = $equipment['id'];
            $query = "SELECT `id`, `ip`, `mac`\n                   FROM `origin_glpi_networkports`\n                   WHERE `itemtype` = 'NetworkEquipment'\n                         AND `items_id` = '{$networkequipments_id}'\n                         AND (`ip` = '" . $equipment['ip'] . "'\n                              OR `mac` = '" . $equipment['mac'] . "')";
            $both = array();
            $mac = array();
            $ip = array();
            foreach ($DB->request($query) as $ports) {
                if ($ports['ip'] == $equipment['ip']) {
                    if ($ports['mac'] == $equipment['mac']) {
                        $both[] = $ports['id'];
                    } else {
                        $ip[] = $ports['id'];
                    }
                } else {
                    $mac[] = $ports['id'];
                }
            }
            if (count($both) != 1) {
                // Only add a NetworkPort if there is 0 or more than one element !
                $port_input['items_id'] = $networkequipments_id;
                $port_input['entities_id'] = $equipment['entities_id'];
                $port_input['is_recursive'] = $equipment['is_recursive'];
                $port_input['mac'] = strtolower($equipment['mac']);
                $networkports_id = $migration->insertInTable('glpi_networkports', $port_input);
                $aggregate_input = array();
                $aggregate_input['networkports_id'] = $networkports_id;
                $aggregate_input['networkports_id_list'] = exportArrayToDB($both);
                $migration->insertInTable('glpi_networkportaggregates', $aggregate_input);
                createNetworkNameFromItem('NetworkPort', $networkports_id, $equipment['id'], 'NetworkEquipment', $equipment['entities_id'], $equipment['ip']);
                foreach ($both as $aggregated_networkports_id) {
                    $query = "DELETE\n                         FROM `glpi_networknames`\n                         WHERE `itemtype` = 'NetworkPort'\n                               AND `items_id` = '{$aggregated_networkports_id}'";
                    $DB->query($query);
                    $query = "UPDATE `glpi_networkports`\n                         SET `mac` = ''\n                         WHERE `id` = '{$aggregated_networkports_id}'";
                    $DB->query($query);
                }
            }
        }
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), "glpi_networkportaliases"));
    // Adding NetworkPortAlias table
    if (!TableExists('glpi_networkportaliases')) {
        $query = "CREATE TABLE `glpi_networkportaliases` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `networkports_id` int(11) NOT NULL DEFAULT '0',\n                  `networkports_id_alias` int(11) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `networkports_id` (`networkports_id`),\n                  KEY `networkports_id_alias` (`networkports_id_alias`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.84 create glpi_networkportaliases");
        // New element, so, we don't need to create items
    }
    $migration->addField('glpi_networkports_vlans', 'tagged', 'bool', array('value' => '0'));
    $migration->addField('glpi_vlans', 'entities_id', 'integer', array('value' => '0', 'after' => 'id'));
    $migration->addKey('glpi_vlans', 'entities_id');
    $migration->addField('glpi_vlans', 'is_recursive', 'bool', array('value' => '0', 'after' => 'entities_id', 'update' => '1'));
    $migration->addKey('glpi_vlans', 'tag');
    $migration->displayMessage(sprintf(__('Data migration - %s'), 'Update connections between IPAddress and IPNetwork'));
    // Here, we are sure that there is only IPv4 addresses. So, the SQL requests are simplified
    $query = "SELECT `id`, `address_3`, `netmask_3`\n             FROM `glpi_ipnetworks`";
    if ($network_result = $DB->query($query)) {
        unset($query);
        while ($ipnetwork_row = $DB->fetch_assoc($network_result)) {
            $ipnetworks_id = $ipnetwork_row['id'];
            $netmask = floatval($ipnetwork_row['netmask_3']);
            $address = floatval($ipnetwork_row['address_3']) & $netmask;
            $query = "SELECT `id`\n                   FROM `glpi_ipaddresses`\n                   WHERE (`glpi_ipaddresses`.`binary_3` & '{$netmask}') = {$address}\n                         AND `glpi_ipaddresses`.`version` = '4'\n                   GROUP BY `items_id`";
            if ($ipaddress_result = $DB->query($query)) {
                unset($query);
                while ($link = $DB->fetch_assoc($ipaddress_result)) {
                    $query = "INSERT INTO `glpi_ipaddresses_ipnetworks`\n                                (`ipaddresses_id`, `ipnetworks_id`)\n                         VALUES ('" . $link['id'] . "', '{$ipnetworks_id}')";
                    $DB->query($query);
                    unset($query);
                }
            }
        }
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), 'Drop table glpi_networkportmigrations if empty'));
    if (countElementsInTable("glpi_networkportmigrations") == 0) {
        $migration->dropTable("glpi_networkportmigrations");
        $migration->dropTable("glpi_networkportinterfaces");
        unset($ADDTODISPLAYPREF['NetworkPortMigration']);
    }
    // We migrate glpi_networkequipments: mac field presence is used to check if framework has
    // already been migrated
    $migration->migrationOneTable('glpi_networkequipments');
    foreach ($originTables as $table) {
        $migration->dropTable($table);
    }
}
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';
if (!TableExists('glpi_networkportmigrations')) {
    Html::displayNotFoundError();
}
$np = new NetworkPortMigration();
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (isset($_POST["purge"])) {
    $np->check($_POST['id'], PURGE);
    $np->delete($_POST, 1);
    Event::log($_POST['id'], "networkport", 5, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
    Html::redirect($CFG_GLPI["root_doc"] . "/front/networkportmigration.php");
} else {
    if (isset($_POST["delete_several"])) {
        Session::checkRight("networking", UPDATE);
        if (isset($_POST["del_port"]) && count($_POST["del_port"])) {
            foreach ($_POST["del_port"] as $port_id => $val) {
                if ($np->can($port_id, PURGE)) {
                    $np->delete(array("id" => $port_id));
Exemplo n.º 5
0
-------------------------------------------------------------------------

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("networking", UPDATE);
if (!TableExists('glpi_networkportmigrations')) {
    Html::displayNotFoundError();
}
Html::header(NetworkPortMigration::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "tools", "migration", "networkportmigration");
Search::show('NetworkPortMigration');
Html::footer();
Exemplo n.º 6
0
-------------------------------------------------------------------------

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("networking", "w");
if (!TableExists('glpi_networkportmigrations')) {
    Html::displayNotFoundError();
}
Html::header(NetworkPortMigration::getTypeName(2), $_SERVER['PHP_SELF'], "utils", "migration", "networkportmigration");
Search::show('NetworkPortMigration');
Html::footer();
Exemplo n.º 7
0
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';
if (!TableExists('glpi_networkportmigrations')) {
    Html::displayNotFoundError();
}
$np = new NetworkPortMigration();
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (isset($_POST["delete"])) {
    $np->check($_POST['id'], 'd');
    $np->delete($_POST);
    Event::log($_POST['id'], "networkport", 5, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
    Html::redirect($CFG_GLPI["root_doc"] . "/front/networkportmigration.php");
} else {
    if (isset($_POST["delete_several"])) {
        Session::checkRight("networking", "w");
        if (isset($_POST["del_port"]) && count($_POST["del_port"])) {
            foreach ($_POST["del_port"] as $port_id => $val) {
                if ($np->can($port_id, 'd')) {
                    $np->delete(array("id" => $port_id));
Exemplo n.º 8
0
 /**
  * Clean the date in the relation tables for the deleted item
  * Clear N/N Relation
  **/
 function cleanRelationTable()
 {
     global $CFG_GLPI, $DB;
     // If this type have INFOCOM, clean one associated to purged item
     if (Infocom::canApplyOn($this)) {
         $infocom = new Infocom();
         if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) {
             $infocom->delete(array('id' => $infocom->fields['id']));
         }
     }
     // If this type have NETPORT, clean one associated to purged item
     if (in_array($this->getType(), $CFG_GLPI['networkport_types'])) {
         // If we don't use delete, then cleanDBonPurge() is not call and the NetworkPorts are not
         // clean properly
         $networkPortObject = new NetworkPort();
         $networkPortObject->cleanDBonItemDelete($this->getType(), $this->getID());
         // Manage networkportmigration if exists
         if (TableExists('glpi_networkportmigrations')) {
             $networkPortMigObject = new NetworkPortMigration();
             $networkPortMigObject->cleanDBonItemDelete($this->getType(), $this->getID());
         }
     }
     // If this type is RESERVABLE clean one associated to purged item
     if (in_array($this->getType(), $CFG_GLPI['reservation_types'])) {
         $rr = new ReservationItem();
         if ($rr->getFromDBbyItem($this->getType(), $this->fields['id'])) {
             $rr->delete(array('id' => $infocom->fields['id']));
         }
     }
     // If this type have CONTRACT, clean one associated to purged item
     if (in_array($this->getType(), $CFG_GLPI['contract_types'])) {
         $ci = new Contract_Item();
         $ci->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     }
     // If this type have DOCUMENT, clean one associated to purged item
     if (Document::canApplyOn($this)) {
         $di = new Document_Item();
         $di->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     }
     // If this type have NOTEPAD, clean one associated to purged item
     if ($this->usenotepad) {
         $note = new Notepad();
         $note->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     }
 }