update_0713_072.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * @version $Id: update_0713_072.php 20129 2013-02-04 16:53:59Z moyo $
00005  -------------------------------------------------------------------------
00006  GLPI - Gestionnaire Libre de Parc Informatique
00007  Copyright (C) 2003-2013 by the INDEPNET Development Team.
00008 
00009  http://indepnet.net/   http://glpi-project.org
00010  -------------------------------------------------------------------------
00011 
00012  LICENSE
00013 
00014  This file is part of GLPI.
00015 
00016  GLPI is free software; you can redistribute it and/or modify
00017  it under the terms of the GNU General Public License as published by
00018  the Free Software Foundation; either version 2 of the License, or
00019  (at your option) any later version.
00020 
00021  GLPI is distributed in the hope that it will be useful,
00022  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  GNU General Public License for more details.
00025 
00026  You should have received a copy of the GNU General Public License
00027  along with GLPI. If not, see <http://www.gnu.org/licenses/>.
00028  --------------------------------------------------------------------------
00029  */
00030 
00031 /** @file
00032 * @brief
00033 */
00034 
00035 /// Update from 0.71.2 to 0.72
00036 
00037 function update0713to072() {
00038    global $DB, $CFG_GLPI;
00039 
00040    //TRANS: %s is the number of new version
00041    echo "<h3>".sprintf(__('Update to %s'), '0.72')."</h3>";
00042    displayMigrationMessage("072"); // Start
00043 
00044    if (!FieldExists("glpi_networking", "recursive", false)) {
00045       $query = "ALTER TABLE `glpi_networking`
00046                 ADD `recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `FK_entities`";
00047       $DB->queryOrDie($query, "0.72 add recursive in glpi_networking");
00048    }
00049 
00050    if (!FieldExists("glpi_printers", "recursive", false)) {
00051       $query = "ALTER TABLE `glpi_printers`
00052                 ADD `recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `FK_entities`";
00053       $DB->queryOrDie($query, "0.72 add recursive in glpi_printers");
00054    }
00055 
00056    if (!FieldExists("glpi_links", "FK_entities", false)) {
00057       $query = "ALTER TABLE `glpi_links`
00058                 ADD `FK_entities` INT( 11 ) NOT NULL DEFAULT '0' AFTER `ID`";
00059       $DB->queryOrDie($query, "0.72 add FK_entities in glpi_links");
00060    }
00061 
00062    if (!FieldExists("glpi_links", "recursive", false)) {
00063       $query = "ALTER TABLE `glpi_links`
00064                 ADD `recursive` INT( 1 ) NOT NULL DEFAULT '1' AFTER `FK_entities`";
00065       $DB->queryOrDie($query, "0.72 add recursive in glpi_links");
00066    }
00067 
00068    // Clean datetime fields
00069    $date_fields = array('glpi_docs.date_mod',
00070                         'glpi_event_log.date',
00071                         'glpi_monitors.date_mod',
00072                         'glpi_networking.date_mod',
00073                         'glpi_ocs_link.last_update',
00074                         'glpi_peripherals.date_mod',
00075                         'glpi_phones.date_mod',
00076                         'glpi_printers.date_mod',
00077                         'glpi_reservation_resa.begin',
00078                         'glpi_reservation_resa.end',
00079                         'glpi_tracking.closedate',
00080                         'glpi_tracking_planning.begin',
00081                         'glpi_tracking_planning.end',
00082                         'glpi_users.last_login',
00083                         'glpi_users.date_mod');
00084 
00085    foreach ($date_fields as $tablefield) {
00086       displayMigrationMessage("072", "Date format (1) ($tablefield)");
00087 
00088       list($table,$field) = explode('.', $tablefield);
00089       if (FieldExists($table, $field, false)) {
00090          $query = "ALTER TABLE `$table`
00091                    CHANGE `$field` `$field` DATETIME NULL";
00092          $DB->queryOrDie($query, "0.72 alter $field in $table");
00093       }
00094    }
00095 
00096    $date_fields[] = "glpi_computers.date_mod";
00097    $date_fields[] = "glpi_followups.date";
00098    $date_fields[] = "glpi_history.date_mod";
00099    $date_fields[] = "glpi_kbitems.date";
00100    $date_fields[] = "glpi_kbitems.date_mod";
00101    $date_fields[] = "glpi_ocs_config.date_mod";
00102    $date_fields[] = "glpi_ocs_link.last_ocs_update";
00103    $date_fields[] = "glpi_reminder.date";
00104    $date_fields[] = "glpi_reminder.begin";
00105    $date_fields[] = "glpi_reminder.end";
00106    $date_fields[] = "glpi_reminder.date_mod";
00107    $date_fields[] = "glpi_software.date_mod";
00108    $date_fields[] = "glpi_tracking.date";
00109    $date_fields[] = "glpi_tracking.date_mod";
00110    $date_fields[] = "glpi_type_docs.date_mod";
00111 
00112    foreach ($date_fields as $tablefield) {
00113       displayMigrationMessage("072", "Date format (2) ($tablefield)");
00114 
00115       list($table,$field) = explode('.', $tablefield);
00116       if (FieldExists($table, $field, false)) {
00117          $query = "UPDATE `$table`
00118                    SET `$field` = NULL
00119                    WHERE `$field` = '0000-00-00 00:00:00'";
00120          $DB->queryOrDie($query, "0.72 update data of $field in $table");
00121       }
00122    }
00123 
00124    // Clean date fields
00125    $date_fields = array('glpi_infocoms.buy_date',
00126                         'glpi_infocoms.use_date');
00127 
00128    foreach ($date_fields as $tablefield) {
00129       list($table,$field) = explode('.', $tablefield);
00130       if (FieldExists($table, $field, false)) {
00131          $query = "ALTER TABLE `$table`
00132                    CHANGE `$field` `$field` DATE NULL";
00133          $DB->queryOrDie($query, "0.72 alter $field in $table");
00134       }
00135    }
00136 
00137    $date_fields[] = "glpi_cartridges.date_in";
00138    $date_fields[] = "glpi_cartridges.date_use";
00139    $date_fields[] = "glpi_cartridges.date_out";
00140    $date_fields[] = "glpi_consumables.date_in";
00141    $date_fields[] = "glpi_consumables.date_out";
00142    $date_fields[] = "glpi_contracts.begin_date";
00143    $date_fields[] = "glpi_licenses.expire";
00144 
00145    foreach ($date_fields as $tablefield) {
00146       list($table,$field) = explode('.', $tablefield);
00147       if (FieldExists($table, $field, false)) {
00148          $query = "UPDATE `$table`
00149                    SET `$field` = NULL
00150                    WHERE `$field` = '0000-00-00'";
00151          $DB->queryOrDie($query, "0.72 update data of $field in $table");
00152       }
00153    }
00154 
00155    // Software Updates
00156    displayMigrationMessage("072", _n('Software', 'Software', 2));
00157 
00158    // Make software recursive
00159    if (!FieldExists("glpi_software", "recursive", false)) {
00160       $query = "ALTER TABLE `glpi_software`
00161                 ADD `recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `FK_entities`";
00162       $DB->queryOrDie($query, "0.72 add recursive in glpi_software");
00163    }
00164 
00165    if (!FieldExists("glpi_inst_software", "vID", false)) {
00166       $query = "ALTER TABLE `glpi_inst_software`
00167                 CHANGE `license` `vID` INT( 11 ) NOT NULL DEFAULT '0'";
00168       $DB->queryOrDie($query, "0.72 alter inst_software rename license to vID");
00169    }
00170 
00171    if (TableExists("glpi_softwarelicenses")) {
00172       if (TableExists("glpi_softwarelicenses_backup")) {
00173          $query = "DROP TABLE `glpi_softwarelicenses_backup`";
00174          $DB->queryOrDie($query, "0.72 drop backup table glpi_softwarelicenses_backup");
00175       }
00176 
00177       $query = "RENAME TABLE `glpi_softwarelicenses`
00178                 TO `glpi_softwarelicenses_backup`";
00179       $DB->queryOrDie($query, "0.72 backup table glpi_softwareversions");
00180 
00181       echo "<span class='b'><p>glpi_softwarelicenses table already exists.
00182             A backup have been done to glpi_softwarelicenses_backup.</p>
00183             <p>You can delete it if you have no need of it.</p></span>";
00184    }
00185 
00186    // Create licenses
00187    if (!TableExists("glpi_softwarelicenses")) {
00188       $query = "CREATE TABLE `glpi_softwarelicenses` (
00189                   `ID` int(11) NOT NULL auto_increment,
00190                   `sID` int(11) NOT NULL default '0',
00191                   `FK_entities` int(11) NOT NULL default '0',
00192                   `recursive` tinyint(1) NOT NULL DEFAULT '0',
00193                   `number` int(11) NOT NULL default '0',
00194                   `type` int(11) NOT NULL default '0',
00195                   `name` varchar(255) NULL default NULL,
00196                   `serial` varchar(255) NULL default NULL,
00197                   `otherserial` varchar(255) NULL default NULL,
00198                   `buy_version` int(11) NOT NULL default '0',
00199                   `use_version` int(11) NOT NULL default '0',
00200                   `expire` date default NULL,
00201                   `FK_computers` int(11) NOT NULL default '0',
00202                   `comments` text,
00203                   PRIMARY KEY (`ID`),
00204                   KEY `name` (`name`),
00205                   KEY `type` (`type`),
00206                   KEY `sID` (`sID`),
00207                   KEY `FK_entities` (`FK_entities`),
00208                   KEY `buy_version` (`buy_version`),
00209                   KEY `use_version` (`use_version`),
00210                   KEY `FK_computers` (`FK_computers`),
00211                   KEY `serial` (`serial`),
00212                   KEY `otherserial` (`otherserial`),
00213                   KEY `expire` (`expire`)
00214                 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
00215       $DB->queryOrDie($query, "0.72 create glpi_softwarelicenses");
00216    }
00217 
00218    if (TableExists("glpi_softwareversions")) {
00219       if (TableExists("glpi_softwareversions_backup")) {
00220          $query = "DROP TABLE `glpi_softwareversions_backup`";
00221          $DB->queryOrDie($query, "0.72 drop backup table glpi_softwareversions_backup");
00222       }
00223 
00224       $query = "RENAME TABLE `glpi_softwareversions`
00225                TO `glpi_softwareversions_backup`";
00226       $DB->queryOrDie($query, "0.72 backup table glpi_softwareversions");
00227 
00228       echo "<p><span class='b'>glpi_softwareversions table already exists.
00229             A backup have been done to glpi_softwareversions_backup.</p><p>
00230             You can delete it if you have no need of it.</p></span>";
00231    }
00232 
00233    if (!TableExists("glpi_softwareversions")) {
00234       $query = "CREATE TABLE `glpi_softwareversions` (
00235                   `ID` int(11) NOT NULL auto_increment,
00236                   `sID` int(11) NOT NULL default '0',
00237                   `state` int(11) NOT NULL default '0',
00238                   `name` varchar(255) NULL default NULL,
00239                   `comments` text,
00240                   PRIMARY KEY (`ID`),
00241                   KEY `sID` (`sID`),
00242                   KEY `name` (`name`)
00243                 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
00244       $DB->queryOrDie($query, "0.72 create glpi_softwareversions");
00245    }
00246 
00247    if (TableExists("glpi_licenses")) {
00248       // Update Infocoms to device_type 9999
00249       $query = "UPDATE `glpi_infocoms`
00250                 SET `device_type` = '9999'
00251                 WHERE `device_type` = '".SOFTWARELICENSE_TYPE."'";
00252       $DB->queryOrDie($query, "0.72 prepare infocoms for update softwares");
00253 
00254       // Foreach software
00255       $query_softs = "SELECT *
00256                       FROM `glpi_software`
00257                       ORDER BY `FK_entities`";
00258 
00259       if ($result_softs = $DB->query($query_softs)) {
00260          $nbsoft  = $DB->numrows($result_softs);
00261          $step    = round($nbsoft/100);
00262          if (!$step) {
00263             $step = 1;
00264          }
00265          if ($step > 500) {
00266             $step = 500;
00267          }
00268 
00269          for ($numsoft=0 ; $soft=$DB->fetch_assoc($result_softs) ; $numsoft++) {
00270             // To avoid navigator timeout on by DB
00271             if (!($numsoft % $step)) {
00272                displayMigrationMessage("072 ", "Licenses : $numsoft / $nbsoft");
00273             }
00274 
00275             // oldstate present if migration run more than once
00276             if (isset($soft["oldstate"])) {
00277                 $soft["state"] = $soft["oldstate"];
00278             }
00279 
00280             // Foreach lics
00281             $query_versions = "SELECT `glpi_licenses`.*,
00282                                       `glpi_infocoms`.`ID` AS infocomID
00283                                FROM `glpi_licenses`
00284                                LEFT JOIN `glpi_infocoms`
00285                                   ON (`glpi_infocoms`.`device_type` = '9999'
00286                                       AND `glpi_infocoms`.`FK_device` = `glpi_licenses`.`ID`)
00287                                WHERE `sID` = '".$soft['ID']."'
00288                                ORDER BY `ID`";
00289 
00290             if ($result_vers = $DB->query($query_versions)) {
00291                if ($DB->numrows($result_vers)>0) {
00292                   while ($vers = $DB->fetch_assoc($result_vers)) {
00293                      $install_count = 0;
00294                      $vers_ID       = $vers['ID'];
00295 
00296                      // init : count installations
00297                      $query_count = "SELECT COUNT(*)
00298                                      FROM `glpi_inst_software`
00299                                      WHERE `vID` = '".$vers['ID']."'";
00300 
00301                      if ($result_count=$DB->query($query_count)) {
00302                         $install_count = $DB->result($result_count,0,0);
00303                         $DB->free_result($result_count);
00304                      }
00305 
00306                      // 1 - Is version already exists ?
00307                      $query_search_version = "SELECT *
00308                                               FROM `glpi_softwareversions`
00309                                               WHERE `sID` = '".$soft['ID']."'
00310                                                     AND `name` = '".$vers['version']."'";
00311 
00312                      if ($result_searchvers = $DB->query($query_search_version)) {
00313                         // Version already exists : update inst_software
00314                         if ($DB->numrows($result_searchvers)==1) {
00315                            $found_vers = $DB->fetch_assoc($result_searchvers);
00316                            $vers_ID    = $found_vers['ID'];
00317 
00318                            $query = "UPDATE `glpi_inst_software`
00319                                      SET `vID` = '".$found_vers['ID']."'
00320                                      WHERE `vID` = '".$vers['ID']."'";
00321                            $DB->query($query);
00322 
00323                         } else {
00324                            // Re Create new entry
00325                            $query = "INSERT INTO `glpi_softwareversions`
00326                                             SELECT `ID`, `sID`, '".$soft["state"]."', `version`,''
00327                                             FROM `glpi_licenses`
00328                                             WHERE `ID` = '".$vers_ID."'";
00329                            $DB->query($query);
00330 
00331                            // Transfert History for this version
00332                            $findstr = " (v. ".$vers['version'].")"; // Log event format in 0.71
00333                            $findlen = Toolbox::strlen($findstr);
00334 
00335                            $DB->query("UPDATE `glpi_history`
00336                                       SET `FK_glpi_device` = '".$vers_ID."',
00337                                           `device_type` = '". SOFTWAREVERSION_TYPE."'
00338                                       WHERE `FK_glpi_device` = '".$soft['ID']."'
00339                                             AND `device_type` = '". SOFTWARE_TYPE."'
00340                                             AND ((`linked_action` = '".Log::HISTORY_INSTALL_SOFTWARE."'
00341                                                    AND RIGHT(new_value, $findlen) = '$findstr')
00342                                                  OR (`linked_action` = '".Log::HISTORY_UNINSTALL_SOFTWARE."'
00343                                                       AND RIGHT(old_value, $findlen) = '$findstr'))");
00344                         }
00345                         $DB->free_result($result_searchvers);
00346                      }
00347 
00348                      // 2 - Create glpi_licenses
00349                      if ($vers['buy'] // Buy license
00350                          || (!empty($vers['serial'])
00351                              && !in_array($vers['serial'], array('free','global'))) // Non global / free serial
00352                          || !empty($vers['comments'])  // With comments
00353                          || !empty($vers['expire'])  // with an expire date
00354                          || $vers['oem_computer'] > 0 // oem license
00355                          || !empty($vers['infocomID'])) { // with and infocoms
00356 
00357                         $found_lic = -1;
00358                         // No infocoms try to find already exists license
00359                         if (empty($vers['infocomID'])) {
00360                            $query_search_lic = "SELECT `ID`
00361                                                 FROM `glpi_softwarelicenses`
00362                                                 WHERE `buy_version` = '$vers_ID'
00363                                                       AND `serial` = '".$vers['serial']."'
00364                                                       AND `FK_computers` = '".$vers['oem_computer']."'
00365                                                       AND `comments` = '".$vers['comments']."'";
00366 
00367                            if (empty($vers['expire'])) {
00368                               $query .= " AND `expire` IS NULL";
00369                            } else {
00370                               $query .= " AND `expire` = '".$vers['expire']."'";
00371                            }
00372 
00373                            if ($result_searchlic = $DB->query($query_search_lic)) {
00374                               if ($DB->numrows($result_searchlic)>0) {
00375                                  $found_lic = $DB->result($result_searchlic,0,0);
00376                                  $DB->free_result($result_searchlic);
00377                               }
00378                            }
00379                         }
00380 
00381                         if ($install_count == 0) {
00382                            $install_count = 1; // license exists so count 1
00383                         }
00384 
00385                         // Found license : merge with found one
00386                         if ($found_lic > 0) {
00387                            $query = "UPDATE `glpi_softwarelicenses`
00388                                      SET `number` = `number`+1
00389                                      WHERE `ID` = '$found_lic'";
00390                            $DB->query($query);
00391                         } else { // Create new license
00392                            if (empty($vers['expire'])) {
00393                               $vers['expire'] = 'NULL';
00394                            } else {
00395                            $vers['expire'] = "'".$vers['expire']."'";
00396                            }
00397 
00398                            $query = "INSERT INTO `glpi_softwarelicenses`
00399                                             (`sID` ,`FK_entities`,
00400                                              `number` ,`type` ,`name` ,
00401                                              `serial` ,`buy_version`,
00402                                              `use_version`, `expire`,
00403                                              `FK_computers` ,
00404                                              `comments`)
00405                                      VALUES ('".$soft['ID']."', '".$soft["FK_entities"]."',
00406                                              $install_count, 0, '".$vers['serial']."',
00407                                              '".addslashes($vers['serial'])."' , '$vers_ID',
00408                                              '$vers_ID', ".$vers['expire'].",
00409                                              '".$vers['oem_computer']."',
00410                                              '".addslashes($vers['comments'])."')";
00411 
00412                            if ($DB->query($query)) {
00413                               $lic_ID = $DB->insert_id();
00414                               // Update infocoms link
00415                               if (!empty($vers['infocomID'])) {
00416                                  $query = "UPDATE `glpi_infocoms`
00417                                            SET `device_type` = '".SOFTWARELICENSE_TYPE."',
00418                                                `FK_device` = '$lic_ID'
00419                                            WHERE `device_type` = '9999'
00420                                                  AND `FK_device` = '".$vers['ID']."'";
00421                                  $DB->query($query);
00422                               }
00423                            }
00424 
00425                         } // Create licence
00426                      } // Buy licence
00427                   } // Each license
00428                } // while
00429                $DB->free_result($result_vers);
00430             }
00431             // Clean History for this software (old versions no more installed)
00432             $DB->query("DELETE
00433                         FROM `glpi_history`
00434                         WHERE `FK_glpi_device` = '".$soft['ID']."'
00435                               AND `device_type` = '". SOFTWARE_TYPE."'
00436                               AND (`linked_action` = '".Log::HISTORY_INSTALL_SOFTWARE."'
00437                                    OR `linked_action` = '".Log::HISTORY_UNINSTALL_SOFTWARE."')");
00438          } // For
00439       } // Each Software
00440 
00441       $query = "DROP TABLE `glpi_licenses`";
00442       $DB->queryOrDie($query, "0.72 drop table glpi_licenses");
00443 
00444       // Drop alerts on licenses : 2 = Alert::END
00445       $query = "DELETE
00446                 FROM `glpi_alerts`
00447                 WHERE `glpi_alerts`.`device_type` = '".SOFTWARELICENSE_TYPE."'
00448                       AND `glpi_alerts`.`type` = '2'";
00449       $DB->queryOrDie($query, "0.72 clean alerts for licenses infocoms");
00450 
00451    } // TableExists("glpi_licenses")
00452 
00453 
00454    // Change software search pref
00455    $query = "SELECT DISTINCT `FK_users`
00456              FROM `glpi_display`
00457              WHERE `type` = '".SOFTWARE_TYPE."'";
00458 
00459    if ($result = $DB->query($query)) {
00460       if ($DB->numrows($result)>0) {
00461          while ($data = $DB->fetch_assoc($result)) {
00462             $query = "SELECT max(`rank`)
00463                       FROM `glpi_display`
00464                       WHERE `FK_users` = '".$data['FK_users']."'
00465                             AND `type` = '".SOFTWARE_TYPE."'";
00466             $result  = $DB->query($query);
00467             $rank    = $DB->result($result,0,0);
00468             $rank++;
00469 
00470             $query = "SELECT *
00471                       FROM `glpi_display`
00472                       WHERE `FK_users` = '".$data['FK_users']."'
00473                             AND `num` = '72'
00474                             AND `type` = '".SOFTWARE_TYPE."'";
00475 
00476             if ($result2=$DB->query($query)) {
00477                if ($DB->numrows($result2)==0) {
00478                   $query = "INSERT INTO `glpi_display`
00479                                    (`type` ,`num` ,`rank` ,
00480                                     `FK_users`)
00481                             VALUES ('".SOFTWARE_TYPE."', '72', '".$rank++."',
00482                                     '".$data['FK_users']."')";
00483                   $DB->query($query);
00484                }
00485             }
00486 
00487             $query = "SELECT *
00488                       FROM `glpi_display`
00489                       WHERE `FK_users` = '".$data['FK_users']."'
00490                             AND `num` = '163'
00491                             AND `type` = '".SOFTWARE_TYPE."'";
00492 
00493             if ($result2=$DB->query($query)) {
00494                if ($DB->numrows($result2) == 0) {
00495                   $query = "INSERT INTO `glpi_display`
00496                                    (`type` ,`num` ,`rank` ,
00497                                     `FK_users`)
00498                             VALUES ('".SOFTWARE_TYPE."', '163', '".$rank++."',
00499                                     '".$data['FK_users']."');";
00500                   $DB->query($query);
00501                }
00502             }
00503          }
00504       }
00505    }
00506 
00507 
00508    displayMigrationMessage("072", _n('Software', 'Software', 2));
00509 
00510    // If migration run more than once
00511    if (!FieldExists("glpi_softwareversions", "state", false)) {
00512       $query = "ALTER TABLE `glpi_softwareversions`
00513                 ADD `state` INT NOT NULL DEFAULT '0' AFTER `sID`";
00514       $DB->queryOrDie($query, "0.72 add state to softwareversion table");
00515    }
00516 
00517    // To allow migration to be run more than once
00518    if (FieldExists("glpi_software", "state", false)) {
00519       $query = "ALTER TABLE `glpi_software`
00520                 CHANGE `state` `oldstate` INT( 11 ) NOT NULL DEFAULT '0'";
00521       $DB->queryOrDie($query, "0.72 change state to to oldtsate in softwareversion table");
00522    }
00523 
00524    if (!TableExists("glpi_dropdown_licensetypes")) {
00525       $query = "CREATE TABLE `glpi_dropdown_licensetypes` (
00526                   `ID` int(11) NOT NULL auto_increment,
00527                   `name` varchar(255) NULL default NULL,
00528                   `comments` text,
00529                   PRIMARY KEY (`ID`),
00530                   KEY `name` (`name`)
00531                 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
00532       $DB->queryOrDie($query, "0.72 create glpi_dropdown_licensetypes table");
00533 
00534       $input["tablename"]   = "glpi_dropdown_licensetypes";
00535       $input["value"]       = "OEM";
00536       $input['type']        = "first";
00537       $input["comment"]     = "";
00538       $input["entities_id"] = -1;
00539 
00540       $query = "INSERT INTO `glpi_dropdown_licensetypes`
00541                        (`name`)
00542                 VALUES ('OEM')";
00543 
00544       if ($result = $DB->query($query)) {
00545          $oemtype  =  $DB->insert_id();
00546          $query    = "UPDATE `glpi_softwarelicenses`
00547                       SET `type` = '$oemtype'
00548                       WHERE `FK_computers` > '0'";
00549          $DB->queryOrDie($query, "0.72 affect OEM as licensetype");
00550       }
00551    }
00552 
00553    displayMigrationMessage("072", _n('User', 'Users', 2));
00554 
00555    if (!FieldExists("glpi_groups", "recursive", false)) {
00556       $query = "ALTER TABLE `glpi_groups`
00557                 ADD `recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `FK_entities`";
00558       $DB->queryOrDie($query, "0.72 add recursive in glpi_groups");
00559    }
00560 
00561    if (!FieldExists("glpi_auth_ldap", "ldap_field_title", false)) {
00562       $query = "ALTER TABLE `glpi_auth_ldap`
00563                 ADD `ldap_field_title` VARCHAR( 255 ) DEFAULT NULL ";
00564       $DB->queryOrDie($query, "0.72 add ldap_field_title in glpi_auth_ldap");
00565    }
00566 
00567    //Add user title retrieval from LDAP
00568    if (!TableExists("glpi_dropdown_user_titles")) {
00569       $query = "CREATE TABLE `glpi_dropdown_user_titles` (
00570                   `ID` int( 11 ) NOT NULL AUTO_INCREMENT ,
00571                   `name` varchar( 255 ) NULL default NULL ,
00572                   `comments` text ,
00573                   PRIMARY KEY ( `ID` ) ,
00574                   KEY `name` (`name`)
00575                 ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci";
00576       $DB->queryOrDie($query, "0.72 create glpi_dropdown_user_titles table");
00577    }
00578 
00579    if (!FieldExists("glpi_users", "title", false)) {
00580       $query = "ALTER TABLE `glpi_users`
00581                 ADD `title` INT( 11 ) NOT NULL DEFAULT '0'";
00582       $DB->queryOrDie($query, "0.72 add title in glpi_users");
00583    }
00584 
00585    if (!isIndex("glpi_users", "title")) {
00586       $query = " ALTER TABLE `glpi_users`
00587                 ADD INDEX `title` (`title`)";
00588       $DB->queryOrDie($query, "0.72 add index on title in glpi_users");
00589    }
00590 
00591    if (!FieldExists("glpi_auth_ldap", "ldap_field_type", false)) {
00592       $query = "ALTER TABLE `glpi_auth_ldap`
00593                 ADD `ldap_field_type` VARCHAR( 255 ) DEFAULT NULL";
00594       $DB->queryOrDie($query, "0.72 add ldap_field_title in glpi_auth_ldap");
00595    }
00596 
00597    //Add user type retrieval from LDAP
00598    if (!TableExists("glpi_dropdown_user_types")) {
00599       $query = "CREATE TABLE `glpi_dropdown_user_types` (
00600                   `ID` int( 11 ) NOT NULL AUTO_INCREMENT,
00601                   `name` varchar( 255 ) NULL default NULL,
00602                   `comments` text,
00603                   PRIMARY KEY (`ID`),
00604                   KEY `name` (`name`)
00605                 ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci";
00606       $DB->queryOrDie($query, "0.72 create glpi_dropdown_user_types table");
00607    }
00608 
00609    if (!FieldExists("glpi_users", "type", false)) {
00610       $query = "ALTER TABLE `glpi_users`
00611                 ADD `type` INT( 11 ) NOT NULL DEFAULT '0'";
00612       $DB->queryOrDie($query, "0.72 add type in glpi_users");
00613    }
00614 
00615    if (!isIndex("glpi_users", "type")) {
00616       $query = " ALTER TABLE `glpi_users`
00617                  ADD INDEX `type` (`type`)";
00618       $DB->queryOrDie($query, "0.72 add index on type in glpi_users");
00619    }
00620 
00621    if (!isIndex("glpi_users", "active")) {
00622       $query = " ALTER TABLE `glpi_users`
00623                  ADD INDEX `active` (`active`)";
00624       $DB->queryOrDie($query, "0.72 add index on active in glpi_users");
00625    }
00626 
00627    if (!FieldExists("glpi_auth_ldap", "ldap_field_language", false)) {
00628       $query = "ALTER TABLE `glpi_auth_ldap`
00629                 ADD `ldap_field_language` VARCHAR( 255 ) NULL DEFAULT NULL ";
00630       $DB->queryOrDie($query, "0.72 add ldap_field_language in glpi_auth_ldap");
00631    }
00632 
00633    if (!FieldExists("glpi_ocs_config", "tag_exclude", false)) {
00634       $query = "ALTER TABLE `glpi_ocs_config`
00635                 ADD `tag_exclude` VARCHAR( 255 ) NULL AFTER `tag_limit`";
00636       $DB->queryOrDie($query, "0.72 add tag_exclude in glpi_ocs_config");
00637    }
00638 
00639    if (!FieldExists("glpi_config", "cache_max_size", false)) {
00640       $query = "ALTER TABLE `glpi_config`
00641                 ADD `cache_max_size` INT( 11 ) NOT NULL DEFAULT '20' AFTER `use_cache`";
00642       $DB->queryOrDie($query, "0.72 add cache_max_size in glpi_config");
00643    }
00644 
00645    displayMigrationMessage("072", _n('Volume', 'Volumes', 2));
00646 
00647    if (!TableExists("glpi_dropdown_filesystems")) {
00648       $query = "CREATE TABLE `glpi_dropdown_filesystems` (
00649                   `ID` int(11) NOT NULL auto_increment,
00650                   `name` varchar(255) NULL default NULL,
00651                   `comments` text ,
00652                   PRIMARY KEY (`ID`),
00653                   KEY `name` (`name`)
00654                 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
00655       $DB->queryOrDie($query, "0.72 create glpi_dropdown_filesystems table");
00656 
00657       $fstype = array('ext', 'ext2', 'ext3', 'ext4', 'FAT', 'FAT32', 'VFAT', 'HFS', 'HPFS', 'HTFS',
00658                       'JFS', 'JFS2', 'NFS', 'NTFS', 'ReiserFS', 'SMBFS', 'UDF', 'UFS', 'XFS', 'ZFS');
00659       foreach ($fstype as $fs) {
00660          $query = "INSERT INTO `glpi_dropdown_filesystems`
00661                          (`name`)
00662                    VALUES ('$fs')";
00663          $DB->queryOrDie($query, "0.72 add filesystems type");
00664       }
00665    }
00666 
00667    if (!TableExists("glpi_computerdisks")) {
00668       $query = "CREATE TABLE `glpi_computerdisks` (
00669                   `ID` int(11) NOT NULL auto_increment,
00670                   `FK_computers` int(11) NOT NULL default 0,
00671                   `name` varchar(255)  NULL default NULL,
00672                   `device` varchar(255) NULL default NULL,
00673                   `mountpoint` varchar(255) NULL default NULL,
00674                   `FK_filesystems` int(11) NOT NULL default 0,
00675                   `totalsize` int(11) NOT NULL default 0,
00676                   `freesize` int(11) NOT NULL default 0,
00677                   PRIMARY KEY  (`ID`),
00678                   KEY `name` (`name`),
00679                   KEY `FK_filesystems` (`FK_filesystems`),
00680                   KEY `FK_computers` (`FK_computers`),
00681                   KEY `device` (`device`),
00682                   KEY `mountpoint` (`mountpoint`),
00683                   KEY `totalsize` (`totalsize`),
00684                   KEY `freesize` (`freesize`)
00685                 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
00686       $DB->queryOrDie($query, "0.72 create glpi_computerfilesystems table");
00687    }
00688 
00689    if (!FieldExists("glpi_ocs_config", "import_disk", false)) {
00690       $query = "ALTER TABLE `glpi_ocs_config`
00691                 ADD `import_disk` INT( 2 ) NOT NULL DEFAULT '0' AFTER `import_ip`";
00692       $DB->queryOrDie($query, "0.72 add import_disk in glpi_ocs_config");
00693    }
00694 
00695    if (!FieldExists("glpi_ocs_link", "import_disk", false)) {
00696       $query = "ALTER TABLE `glpi_ocs_link`
00697                 ADD `import_disk` LONGTEXT NULL AFTER `import_device`";
00698       $DB->queryOrDie($query, "0.72 add import_device in glpi_ocs_link");
00699    }
00700 
00701    // Clean software ocs
00702    if (FieldExists("glpi_ocs_config", "import_software_buy", false)) {
00703       $query = " ALTER TABLE `glpi_ocs_config`
00704                  DROP `import_software_buy`";
00705       $DB->queryOrDie($query, "0.72 drop import_software_buy in glpi_ocs_config");
00706    }
00707 
00708    if (FieldExists("glpi_ocs_config", "import_software_licensetype", false)) {
00709       $query = " ALTER TABLE `glpi_ocs_config`
00710                  DROP `import_software_licensetype`";
00711       $DB->queryOrDie($query, "0.72 drop import_software_licensetype in glpi_ocs_config");
00712    }
00713 
00714    //// Clean interface use for GFX card
00715    // Insert default values
00716 
00717    update_importDropdown("glpi_dropdown_interface", "AGP");
00718    update_importDropdown("glpi_dropdown_interface", "PCI");
00719    update_importDropdown("glpi_dropdown_interface", "PCIe");
00720    update_importDropdown("glpi_dropdown_interface", "PCI-X");
00721 
00722    if (!FieldExists("glpi_device_gfxcard", "FK_interface", false)) {
00723       $query = "ALTER TABLE `glpi_device_gfxcard`
00724                 ADD `FK_interface` INT NOT NULL DEFAULT '0' AFTER `interface` ";
00725       $DB->queryOrDie($query, "0.72 alter glpi_device_gfxcard add new field interface");
00726 
00727       // Get all data from interface_old / Insert in glpi_dropdown_interface if needed
00728       $query = "SELECT DISTINCT `interface` AS OLDNAME
00729                 FROM `glpi_device_gfxcard`";
00730 
00731       if ($result=$DB->query($query)) {
00732          if ($DB->numrows($result)>0) {
00733             while ($data=$DB->fetch_assoc($result)) {
00734                $data = Toolbox::addslashes_deep($data);
00735                // Update datas
00736                if ($newID=update_importDropdown("glpi_dropdown_interface", $data['OLDNAME'])) {
00737                   $query2 = "UPDATE `glpi_device_gfxcard`
00738                              SET `FK_interface` = '$newID'
00739                              WHERE `interface` = '".$data['OLDNAME']."'";
00740                   $DB->queryOrDie($query2, "0.72 update glpi_device_gfxcard set new interface value");
00741                }
00742             }
00743          }
00744       }
00745 
00746       $query = "ALTER TABLE `glpi_device_gfxcard`
00747                 DROP `interface` ";
00748       $DB->queryOrDie($query, "0.72 alter $table drop tmp enum field");
00749    }
00750 
00751    if (!FieldExists("glpi_config","existing_auth_server_field_clean_domain", false)) {
00752       $query = "ALTER TABLE `glpi_config`
00753                 ADD `existing_auth_server_field_clean_domain` SMALLINT NOT NULL DEFAULT '0'
00754                                                               AFTER `existing_auth_server_field`";
00755       $DB->queryOrDie($query, "0.72 alter config add existing_auth_server_field_clean_domain");
00756    }
00757 
00758    if (FieldExists("glpi_profiles","contract_infocom", false)) {
00759       $query = "ALTER TABLE `glpi_profiles`
00760                 CHANGE `contract_infocom` `contract` CHAR( 1 ) NULL DEFAULT NULL ";
00761       $DB->queryOrDie($query, "0.72 alter profiles rename contract_infocom to contract");
00762 
00763       $query = "ALTER TABLE `glpi_profiles`
00764                 ADD `infocom` CHAR( 1 ) NULL DEFAULT NULL AFTER `contract`";
00765       $DB->queryOrDie($query, "0.72 alter profiles create infocom");
00766 
00767       $query = "UPDATE `glpi_profiles`
00768                 SET `infocom` = `contract`";
00769       $DB->queryOrDie($query, "0.72 update data for infocom in profiles");
00770    }
00771 
00772    // Debug mode in user pref to allow debug in production environment
00773    if (FieldExists("glpi_config","debug", false)) {
00774       $query = "ALTER TABLE `glpi_config`
00775                 DROP `debug`";
00776       $DB->queryOrDie($query, "0.72 drop debug mode in config");
00777    }
00778 
00779    if (!FieldExists("glpi_users","use_mode", false)) {
00780       $query = "ALTER TABLE `glpi_users`
00781                 ADD `use_mode` SMALLINT NOT NULL DEFAULT '0' AFTER `language`";
00782       $DB->queryOrDie($query, "0.72 create use_mode in glpi_users");
00783    }
00784 
00785    // Default bookmark as default view
00786    if (!TableExists("glpi_display_default")) {
00787       $query = "CREATE TABLE IF NOT EXISTS `glpi_display_default` (
00788                   `ID` int(11) NOT NULL auto_increment,
00789                   `FK_users` int(11) NOT NULL,
00790                   `device_type` int(11) NOT NULL,
00791                   `FK_bookmark` int(11) NOT NULL,
00792                   PRIMARY KEY (`ID`),
00793                   UNIQUE KEY `FK_users` (`FK_users`,`device_type`)
00794                 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
00795       $DB->queryOrDie($query, "0.72 create table glpi_display_default");
00796    }
00797 
00798    // Correct cost contract data type
00799    if (FieldExists("glpi_contracts","cost", false)) {
00800       $query=" ALTER TABLE `glpi_contracts`
00801                CHANGE `cost` `cost` DECIMAL( 20, 4 ) NOT NULL DEFAULT '0.0000'";
00802       $DB->queryOrDie($query, "0.72 alter contract cost data type");
00803    }
00804 
00805    // Plugins table
00806    if (!TableExists("glpi_plugins")) {
00807       $query = "CREATE TABLE IF NOT EXISTS `glpi_plugins` (
00808                   `ID` int(11) NOT NULL auto_increment,
00809                   `directory` varchar(255) NOT NULL,
00810                   `name` varchar(255)  NOT NULL,
00811                   `version` varchar(255)  NOT NULL,
00812                   `state` tinyint(4) NOT NULL default '0',
00813                   `author` varchar(255) NULL default NULL,
00814                   `homepage` varchar(255) NULL default NULL,
00815                   PRIMARY KEY (`ID`),
00816                   UNIQUE KEY `name` (`directory`)
00817                 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
00818       $DB->queryOrDie($query, "0.72 create table glpi_plugins");
00819    }
00820 
00821    //// CORRECT glpi_config field type
00822    if (FieldExists("glpi_config","num_of_events", false)) {
00823       $query = "ALTER TABLE `glpi_config`
00824                 CHANGE `num_of_events` `num_of_events` INT( 11 ) NOT NULL DEFAULT '10'";
00825       $DB->queryOrDie($query, "0.72 alter config num_of_events");
00826    }
00827 
00828    if (FieldExists("glpi_config","jobs_at_login", false)) {
00829       $query = "ALTER TABLE `glpi_config`
00830                 CHANGE `jobs_at_login` `jobs_at_login` SMALLINT( 6 ) NOT NULL DEFAULT '0'";
00831       $DB->queryOrDie($query, "0.72 alter config jobs_at_login");
00832    }
00833 
00834    if (FieldExists("glpi_config","cut", false)) {
00835       $query = "UPDATE `glpi_config`
00836                 SET `cut` = ROUND(`cut`/50)*50";
00837       $DB->queryOrDie($query, "0.72 update config cut value to prepare update");
00838 
00839       $query = "ALTER TABLE `glpi_config`
00840                 CHANGE `cut` `cut` INT( 11 ) NOT NULL DEFAULT '255'";
00841       $DB->queryOrDie($query, "0.72 alter config cut");
00842    }
00843 
00844    if (FieldExists("glpi_config","list_limit", false)) {
00845       $query = "ALTER TABLE `glpi_config`
00846                 CHANGE `list_limit` `list_limit` INT( 11 ) NOT NULL DEFAULT '20'";
00847       $DB->queryOrDie($query, "0.72 alter config list_limit");
00848    }
00849 
00850    if (FieldExists("glpi_config","expire_events", false)) {
00851       $query = "ALTER TABLE `glpi_config`
00852                 CHANGE `expire_events` `expire_events` INT( 11 ) NOT NULL DEFAULT '30'";
00853       $DB->queryOrDie($query, "0.72 alter config expire_events");
00854    }
00855 
00856    if (FieldExists("glpi_config","event_loglevel", false)) {
00857       $query = "ALTER TABLE `glpi_config`
00858                 CHANGE `event_loglevel` `event_loglevel` SMALLINT( 6 ) NOT NULL DEFAULT '5'";
00859       $DB->queryOrDie($query, "0.72 alter config event_loglevel");
00860    }
00861 
00862    if (FieldExists("glpi_config","permit_helpdesk", false)) {
00863       $query = "UPDATE `glpi_config`
00864                 SET `permit_helpdesk` = '0'
00865                 WHERE `permit_helpdesk` = ''";
00866       $DB->queryOrDie($query, "0.72 update config permit_helpdesk value to prepare update");
00867 
00868       $query = "ALTER TABLE `glpi_config`
00869                 CHANGE `permit_helpdesk` `permit_helpdesk` SMALLINT NOT NULL DEFAULT '0'";
00870       $DB->queryOrDie($query, "0.72 alter config permit_helpdesk");
00871    }
00872 
00873    if (!FieldExists("glpi_config","language", false)) {
00874       $query = "ALTER TABLE `glpi_config`
00875                 CHANGE `default_language` `language` VARCHAR( 255 ) NULL DEFAULT 'en_GB'";
00876       $DB->queryOrDie($query, "0.72 alter config default_language");
00877    }
00878 
00879    if (!FieldExists("glpi_config","tracking_order", false)) {
00880       $query = "ALTER TABLE `glpi_config`
00881                 ADD `tracking_order` SMALLINT NOT NULL default '0'";
00882       $DB->queryOrDie($query, "0.72 alter config add tracking_order");
00883    }
00884 
00885    if (!FieldExists("glpi_users","dateformat", false)) {
00886       $query = "ALTER TABLE `glpi_users`
00887                 ADD `dateformat` SMALLINT NULL DEFAULT NULL";
00888       $DB->queryOrDie($query, "0.72 add dateformat in users");
00889    }
00890 
00891    if (FieldExists("glpi_users","list_limit", false)) {
00892       $query = "ALTER TABLE `glpi_users`
00893                 CHANGE `list_limit` `list_limit` INT( 11 ) NULL DEFAULT NULL";
00894       $DB->queryOrDie($query, "0.72 alter list_limit in users");
00895    }
00896 
00897    if (FieldExists("glpi_users","tracking_order", false)) {
00898       $query = "ALTER TABLE `glpi_users`
00899                 CHANGE `tracking_order` `tracking_order` SMALLINT( 6 ) NULL DEFAULT NULL";
00900       $DB->queryOrDie($query, "0.72 alter tracking_order in users");
00901    }
00902 
00903    if (!FieldExists("glpi_users","numberformat", false)) {
00904       $query = "ALTER TABLE `glpi_users`
00905                 ADD `numberformat` SMALLINT NULL DEFAULT NULL";
00906       $DB->queryOrDie($query, "0.72 add numberformat in users");
00907    }
00908 
00909    if (!FieldExists("glpi_users","view_ID", false)) {
00910       $query = "ALTER TABLE `glpi_users`
00911                 ADD `view_ID` SMALLINT NULL DEFAULT NULL";
00912       $DB->queryOrDie($query, "0.72 add view_ID in users");
00913    }
00914 
00915    if (!FieldExists("glpi_users","dropdown_limit", false)) {
00916       $query = "ALTER TABLE `glpi_users`
00917                 ADD `dropdown_limit` INT NULL DEFAULT NULL";
00918       $DB->queryOrDie($query, "0.72 add dropdown_limit in users");
00919         }
00920 
00921    if (!FieldExists("glpi_users","flat_dropdowntree", false)) {
00922       $query = "ALTER TABLE `glpi_users`
00923                 ADD `flat_dropdowntree` SMALLINT NULL DEFAULT NULL";
00924       $DB->queryOrDie($query, "0.72 add flat_dropdowntree in users");
00925    }
00926 
00927    if (!FieldExists("glpi_users","num_of_events", false)) {
00928       $query = "ALTER TABLE `glpi_users`
00929                 ADD `num_of_events` INT NULL DEFAULT NULL";
00930       $DB->queryOrDie($query, "0.72 add num_of_events in users");
00931    }
00932 
00933    if (!FieldExists("glpi_users","nextprev_item", false)) {
00934       $query = "ALTER TABLE `glpi_users`
00935                 ADD `nextprev_item` VARCHAR( 255 ) NULL DEFAULT NULL";
00936       $DB->queryOrDie($query, "0.72 add nextprev_item in users");
00937    }
00938 
00939    if (!FieldExists("glpi_users","jobs_at_login", false)) {
00940       $query = "ALTER TABLE `glpi_users`
00941                 ADD `jobs_at_login` SMALLINT NULL DEFAULT NULL";
00942       $DB->queryOrDie($query, "0.72 add jobs_at_login in users");
00943    }
00944 
00945    if (!FieldExists("glpi_users","priority_1", false)) {
00946       $query = "ALTER TABLE `glpi_users`
00947                 ADD `priority_1` VARCHAR( 255 ) NULL DEFAULT NULL,
00948                 ADD `priority_2` VARCHAR( 255 ) NULL DEFAULT NULL,
00949                 ADD `priority_3` VARCHAR( 255 ) NULL DEFAULT NULL,
00950                 ADD `priority_4` VARCHAR( 255 ) NULL DEFAULT NULL,
00951                 ADD `priority_5` VARCHAR( 255 ) NULL DEFAULT NULL";
00952       $DB->queryOrDie($query, "0.72 add priority_X in users");
00953    }
00954 
00955    if (!FieldExists("glpi_users","expand_soft_categorized", false)) {
00956       $query = "ALTER TABLE `glpi_users`
00957                 ADD `expand_soft_categorized` INT( 1 ) NULL DEFAULT NULL";
00958       $DB->queryOrDie($query, "0.72 add expand_soft_categorized in users");
00959    }
00960 
00961    if (!FieldExists("glpi_users","expand_soft_not_categorized", false)) {
00962       $query = "ALTER TABLE `glpi_users`
00963                 ADD `expand_soft_not_categorized` INT( 1 ) NULL DEFAULT NULL";
00964       $DB->queryOrDie($query, "0.72 add expand_soft_not_categorized in users");
00965    }
00966 
00967    if (!FieldExists("glpi_users","followup_private", false)) {
00968       $query = "ALTER TABLE `glpi_users`
00969                 ADD `followup_private` SMALLINT NULL DEFAULT NULL";
00970       $DB->queryOrDie($query, "0.72 add followup_private in users");
00971    }
00972 
00973    if (!FieldExists("glpi_config","followup_private", false)) {
00974       $query = "ALTER TABLE `glpi_config`
00975                 ADD `followup_private` SMALLINT NOT NULL DEFAULT '0'";
00976       $DB->queryOrDie($query, "0.72 add followup_private in config");
00977    }
00978 
00979    // INDEX key order change
00980    if (isIndex("glpi_contract_device", "FK_contract")) {
00981       $query = "ALTER TABLE `glpi_contract_device`
00982                 DROP INDEX `FK_contract`";
00983       $DB->queryOrDie($query, "0.72 drop index FK_contract on glpi_contract_device");
00984    }
00985 
00986    if (!isIndex("glpi_contract_device", "FK_contract_device")) {
00987       $query = "ALTER TABLE `glpi_contract_device`
00988                 ADD UNIQUE INDEX `FK_contract_device` (`FK_contract` , `device_type`, `FK_device` )";
00989       $DB->queryOrDie($query, "0.72 add index FK_contract_device in glpi_contract_device");
00990    }
00991 
00992    if (isIndex("glpi_doc_device", "FK_doc")) {
00993       $query = "ALTER TABLE `glpi_doc_device`
00994                 DROP INDEX `FK_doc`";
00995       $DB->queryOrDie($query, "0.72 drop index FK_doc on glpi_doc_device");
00996    }
00997 
00998    if (!isIndex("glpi_doc_device", "FK_doc_device")) {
00999       $query = "ALTER TABLE `glpi_doc_device`
01000                 ADD UNIQUE INDEX `FK_doc_device` (`FK_doc` , `device_type`, `FK_device` )";
01001       $DB->queryOrDie($query, "0.72 add index FK_doc_device in glpi_doc_device");
01002    }
01003 
01004    //(AD) DistinguishedName criteria is wrong. DN in AD is not distinguishedName but DN.
01005    $query = "SELECT `ID`
01006              FROM `glpi_rules_ldap_parameters`
01007              WHERE `value` = 'distinguishedname'";
01008    $result = $DB->query($query);
01009 
01010    //If (AD) DistinguishedName criteria is still present
01011    if ($DB->numrows($result) == 1) {
01012       $query = "SELECT COUNT(`ID`) AS cpt
01013                 FROM `glpi_rules_criterias`
01014                 WHERE `criteria` = 'distinguishedname'";
01015       $result = $DB->query($query);
01016 
01017       if ($DB->result($result,0,"cpt") > 0) {
01018          echo "<div class='center spaced'>";
01019          echo "<span class='red'>LDAP Criteria (AD)Distinguishedname must be removed.<br>".
01020                "As it is used in one or more LDAP rules, you need to remove it manually</span>";
01021          echo "</div><br>";
01022       } else {
01023          //Delete If (AD) DistinguishedName criteria
01024          $query = "DELETE
01025                    FROM `glpi_rules_ldap_parameters`
01026                    WHERE `value` = 'distinguishedname'";
01027          $result = $DB->query($query);
01028       }
01029    }
01030 
01031    //// Clean DB
01032    if (isIndex("glpi_alerts", "item") && isIndex("glpi_alerts", "alert")) {
01033       $query = "ALTER TABLE `glpi_alerts`
01034                 DROP INDEX `item`";
01035       $DB->queryOrDie($query, "0.72 drop item index on glpi_alerts");
01036    }
01037 
01038    if (isIndex("glpi_alerts", "device_type") && isIndex("glpi_alerts", "alert")) {
01039       $query = "ALTER TABLE `glpi_alerts`
01040                 DROP INDEX `device_type`";
01041       $DB->queryOrDie($query, "0.72 drop device_type index on glpi_alerts");
01042    }
01043 
01044    if (isIndex("glpi_cartridges_assoc", "FK_glpi_type_printer_2")
01045        && isIndex("glpi_cartridges_assoc", "FK_glpi_type_printer")) {
01046 
01047       $query = "ALTER TABLE `glpi_cartridges_assoc`
01048                 DROP INDEX `FK_glpi_type_printer_2`";
01049       $DB->queryOrDie($query, "0.72 drop FK_glpi_type_printer_2 index on glpi_cartridges_assoc");
01050    }
01051 
01052    if (isIndex("glpi_computer_device", "device_type")
01053        && isIndex("glpi_computer_device", "device_type_2")) {
01054 
01055       $query = "ALTER TABLE `glpi_computer_device`
01056                 DROP INDEX `device_type`";
01057       $DB->queryOrDie($query, "0.72 drop device_type index on glpi_computer_device");
01058 
01059       $query = "ALTER TABLE `glpi_computer_device`
01060                 DROP INDEX `device_type_2`,
01061                 ADD INDEX `device_type` (`device_type` , `FK_device`) ";
01062       $DB->queryOrDie($query, "0.72 rename device_type_2 index on glpi_computer_device");
01063    }
01064 
01065    if (isIndex("glpi_connect_wire", "end1") && isIndex("glpi_connect_wire", "end1_1")) {
01066       $query = "ALTER TABLE `glpi_connect_wire`
01067                 DROP INDEX `end1`";
01068       $DB->queryOrDie($query, "0.72 drop end1 index on glpi_connect_wire");
01069 
01070       $query = "ALTER TABLE `glpi_connect_wire`
01071                 DROP INDEX `end1_1`,
01072                 ADD UNIQUE `connect` (`end1` , `end2` , `type`)";
01073       $DB->queryOrDie($query, "0.72 rename end1_1 index on glpi_connect_wire");
01074    }
01075 
01076    if (isIndex("glpi_contract_enterprise", "FK_enterprise")
01077        && isIndex("glpi_contract_enterprise", "FK_enterprise_2")) {
01078 
01079       $query = "ALTER TABLE `glpi_contract_enterprise`
01080                 DROP INDEX `FK_enterprise_2`";
01081       $DB->queryOrDie($query, "0.72 drop FK_enterprise_2 index on glpi_contract_enterprise");
01082    }
01083 
01084    if (isIndex("glpi_contact_enterprise", "FK_enterprise")
01085        && isIndex("glpi_contact_enterprise", "FK_enterprise_2")) {
01086 
01087       $query = "ALTER TABLE `glpi_contact_enterprise`
01088                 DROP INDEX `FK_enterprise_2`";
01089       $DB->queryOrDie($query, "0.72 drop FK_enterprise_2 index on glpi_contact_enterprise");
01090    }
01091 
01092    if (isIndex("glpi_contract_device", "FK_contract_2")
01093        && isIndex("glpi_contract_device", "FK_contract_device")) {
01094 
01095       $query = "ALTER TABLE `glpi_contract_device`
01096                 DROP INDEX `FK_contract_2`";
01097       $DB->queryOrDie($query, "0.72 drop FK_contract_2 index on glpi_contract_device");
01098    }
01099 
01100    if (isIndex("glpi_display", "type") && isIndex("glpi_display", "type_2")) {
01101       $query = "ALTER TABLE `glpi_display`
01102                 DROP INDEX `type`";
01103       $DB->queryOrDie($query, "0.72 drop type index on glpi_display");
01104 
01105       $query = "ALTER TABLE `glpi_display`
01106                 DROP INDEX `type_2`,
01107                 ADD UNIQUE `display` (`type` , `num` , `FK_users`)";
01108       $DB->queryOrDie($query, "0.72 rename type_2 index on glpi_display");
01109    }
01110 
01111    if (isIndex("glpi_doc_device", "FK_doc_2") && isIndex("glpi_doc_device", "FK_doc_device")) {
01112       $query = "ALTER TABLE `glpi_doc_device`
01113                 DROP INDEX `FK_doc_2`";
01114       $DB->queryOrDie($query, "0.72 drop FK_doc_2 index on glpi_doc_device");
01115    }
01116 
01117    if (isIndex("glpi_links_device", "device_type")
01118        && isIndex("glpi_links_device", "device_type_2")) {
01119 
01120       $query = "ALTER TABLE `glpi_links_device`
01121                 DROP INDEX `device_type`";
01122       $DB->queryOrDie($query, "0.72 drop device_type index on glpi_links_device");
01123 
01124       $query = "ALTER TABLE `glpi_links_device`
01125                 DROP INDEX `device_type_2`,
01126                 ADD UNIQUE `link` (`device_type` , `FK_links`)";
01127       $DB->queryOrDie($query, "0.72 rename device_type_2 index on glpi_links_device");
01128    }
01129 
01130    if (isIndex("glpi_mailing", "item_type") && isIndex("glpi_mailing", "items")) {
01131       $query = "ALTER TABLE `glpi_mailing`
01132                 DROP INDEX `item_type`";
01133       $DB->queryOrDie($query, "0.72 drop item_type index on glpi_mailing");
01134    }
01135 
01136    if (isIndex("glpi_mailing", "type") && isIndex("glpi_mailing", "mailings")) {
01137       $query = "ALTER TABLE `glpi_mailing`
01138                 DROP INDEX `type`";
01139       $DB->queryOrDie($query, "0.72 drop type index on glpi_mailing");
01140    }
01141 
01142    if (isIndex("glpi_networking_ports", "on_device_2")
01143        && isIndex("glpi_networking_ports", "on_device")) {
01144 
01145       $query = "ALTER TABLE `glpi_networking_ports`
01146                 DROP INDEX `on_device_2`";
01147       $DB->queryOrDie($query, "0.72 drop on_device_2 index on glpi_networking_ports");
01148    }
01149 
01150    if (isIndex("glpi_networking_vlan", "FK_port")
01151        && isIndex("glpi_networking_vlan", "FK_port_2")) {
01152 
01153       $query = "ALTER TABLE `glpi_networking_vlan`
01154                 DROP INDEX `FK_port`";
01155       $DB->queryOrDie($query, "0.72 drop FK_port index on glpi_networking_vlan");
01156 
01157       $query = "ALTER TABLE `glpi_networking_vlan`
01158                 DROP INDEX `FK_port_2`,
01159                 ADD UNIQUE `portvlan` (`FK_port`, `FK_vlan`)";
01160       $DB->queryOrDie($query, "0.72 rename FK_port_2 index on glpi_networking_vlan");
01161    }
01162 
01163    if (isIndex("glpi_networking_wire", "end1") && isIndex("glpi_networking_wire", "end1_1")) {
01164       $query = "ALTER TABLE `glpi_networking_wire`
01165                 DROP INDEX `end1`";
01166       $DB->queryOrDie($query, "0.72 drop end1 index on glpi_networking_wire");
01167 
01168       $query = "ALTER TABLE `glpi_networking_wire`
01169                 DROP INDEX `end1_1`,
01170                 ADD UNIQUE `netwire` (`end1`, `end2`)";
01171       $DB->queryOrDie($query, "0.72 rename end1_1 index on glpi_networking_wire");
01172    }
01173 
01174    if (isIndex("glpi_reservation_item", "device_type")
01175        && isIndex("glpi_reservation_item", "device_type_2")) {
01176 
01177       $query = "ALTER TABLE `glpi_reservation_item`
01178                 DROP INDEX `device_type`";
01179       $DB->queryOrDie($query, "0.72 drop device_type index on glpi_reservation_item");
01180 
01181       $query = "ALTER TABLE `glpi_reservation_item`
01182                 DROP INDEX `device_type_2`,
01183                 ADD INDEX `reservationitem` (`device_type`, `id_device`)";
01184       $DB->queryOrDie($query, "0.72 rename device_type_2 index on glpi_reservation_item");
01185    }
01186 
01187    if (isIndex("glpi_users_groups", "FK_users") && isIndex("glpi_users_groups", "FK_users_2")) {
01188       $query = "ALTER TABLE `glpi_users_groups`
01189                 DROP INDEX `FK_users_2`";
01190       $DB->queryOrDie($query, "0.72 drop FK_users_2 index on glpi_users_groups");
01191 
01192       $query = "ALTER TABLE `glpi_users_groups`
01193                 DROP INDEX `FK_users`,
01194                 ADD UNIQUE `usergroup` (`FK_users`, `FK_groups`)";
01195       $DB->queryOrDie($query, "0.72 rename FK_users index on glpi_users_groups");
01196    }
01197 
01198    if (!FieldExists("glpi_config","software_helpdesk_visible", false)) {
01199       $query = " ALTER TABLE `glpi_config`
01200                  ADD `software_helpdesk_visible` INT(1) NOT NULL DEFAULT '1'";
01201       $DB->queryOrDie($query, "0.72 add software_helpdesk_visible in config");
01202    }
01203 
01204    if (!FieldExists("glpi_entities_data","ldap_dn", false)) {
01205       $query = "ALTER TABLE `glpi_entities_data`
01206                 ADD `ldap_dn` VARCHAR( 255 ) NULL";
01207       $DB->queryOrDie($query, "0.72 add ldap_dn in config");
01208    }
01209 
01210    if (!FieldExists("glpi_entities_data","tag", false)) {
01211       $query = "ALTER TABLE `glpi_entities_data`
01212                 ADD `tag` VARCHAR( 255 ) NULL";
01213       $DB->queryOrDie($query, "0.72 add tag in config");
01214    }
01215 
01216    if (FieldExists("glpi_rules_ldap_parameters","rule_type", false)) {
01217       $query = "ALTER TABLE `glpi_rules_ldap_parameters`
01218                 CHANGE `rule_type` `sub_type` SMALLINT( 6 ) NOT NULL DEFAULT '1'";
01219       $DB->queryOrDie($query, "0.72 rename rule_type to sub_type in glpi_rules_ldap_parameters");
01220    }
01221 
01222    if (FieldExists("glpi_rules_descriptions","rule_type", false)) {
01223       $query = "ALTER TABLE `glpi_rules_descriptions`
01224                 CHANGE `rule_type` `sub_type` SMALLINT( 4 ) NOT NULL DEFAULT '0'";
01225       $DB->queryOrDie($query, "0.72 rename rule_type to sub_type in glpi_rules_descriptions");
01226    }
01227 
01228    //Add title criteria
01229    $result  = $DB->query("SELECT COUNT(*) AS cpt
01230                           FROM `glpi_rules_ldap_parameters`
01231                           WHERE `value` = 'title'
01232                           AND `sub_type` = '1'");
01233 
01234    if (!$DB->result($result,0,"cpt")) {
01235       $DB->query("INSERT INTO `glpi_rules_ldap_parameters`
01236                          (`ID` ,`name` ,`value` ,`sub_type`)
01237                   VALUES (NULL , '(LDAP) Title', 'title', '1')");
01238    }
01239 
01240    // Duplicate index with PRIMARY
01241    if (isIndex("glpi_monitors", "ID")) {
01242       $query = "ALTER TABLE `glpi_monitors`
01243                 DROP INDEX `ID`";
01244       $DB->queryOrDie($query, "0.72 drop ID index on glpi_monitors");
01245    }
01246 
01247    if (FieldExists("glpi_ocs_config","is_template", false)) {
01248       $query = "DELETE
01249                 FROM `glpi_ocs_config`
01250                 WHERE `is_template` = '1'";
01251       $DB->queryOrDie($query, "0.72 delete templates in glpi_ocs_config");
01252 
01253       $query = "ALTER TABLE `glpi_ocs_config`
01254                 DROP `is_template`";
01255       $DB->queryOrDie($query, "0.72 drop is_template in glpi_ocs_config");
01256    }
01257 
01258    if (FieldExists("glpi_ocs_config","tplname", false)) {
01259       $query = "ALTER TABLE `glpi_ocs_config`
01260                 DROP `tplname`";
01261       $DB->queryOrDie($query, "0.72 drop tplname in glpi_ocs_config");
01262    }
01263 
01264    if (FieldExists("glpi_ocs_config","date_mod", false)) {
01265       $query = "ALTER TABLE `glpi_ocs_config`
01266                 DROP `date_mod`";
01267       $DB->queryOrDie($query, "0.72 drop date_mod in glpi_ocs_config");
01268    }
01269 
01270    if (FieldExists("glpi_ocs_config","glpi_link_enabled", false)) {
01271       $query = "ALTER TABLE `glpi_ocs_config`
01272                 CHANGE `glpi_link_enabled` `glpi_link_enabled` INT(1) NOT NULL DEFAULT '0' ";
01273       $DB->queryOrDie($query, "0.72 alter glpi_link_enabled in glpi_ocs_config");
01274    }
01275 
01276    if (FieldExists("glpi_ocs_config","link_ip", false)) {
01277       $query = "ALTER TABLE `glpi_ocs_config`
01278                 CHANGE `link_ip` `link_ip` INT( 1 ) NOT NULL DEFAULT '0' ";
01279       $DB->queryOrDie($query, "0.72 alter link_ip in glpi_ocs_config");
01280    }
01281 
01282    if (FieldExists("glpi_ocs_config","link_name", false)) {
01283       $query = "ALTER TABLE `glpi_ocs_config`
01284                 CHANGE `link_name` `link_name` INT (1) NOT NULL DEFAULT '0' ";
01285       $DB->queryOrDie($query, "0.72 alter link_name in glpi_ocs_config");
01286    }
01287 
01288    if (FieldExists("glpi_ocs_config","link_mac_address", false)) {
01289       $query = "ALTER TABLE `glpi_ocs_config`
01290                 CHANGE `link_mac_address` `link_mac_address` INT( 1 ) NOT NULL DEFAULT '0' ";
01291       $DB->queryOrDie($query, "0.72 alter link_mac_address in glpi_ocs_config");
01292    }
01293 
01294    if (FieldExists("glpi_ocs_config","link_serial", false)) {
01295       $query = "ALTER TABLE `glpi_ocs_config`
01296                 CHANGE `link_serial` `link_serial` INT( 1 ) NOT NULL DEFAULT '0' ";
01297       $DB->queryOrDie($query, "0.72 alter link_serial in glpi_ocs_config");
01298    }
01299 
01300    if (!FieldExists("glpi_config","name_display_order", false)) {
01301       $query = "ALTER TABLE `glpi_config`
01302                 ADD `name_display_order` TINYINT NOT NULL DEFAULT '0'";
01303       $DB->queryOrDie($query, "0.72 add name_display_order in glpi_config");
01304    }
01305 
01306 
01307    // Display "Work ended." message - Keep this as the last action.
01308    displayMigrationMessage("072"); // End
01309 } // fin 0.72 #####################################################################################
01310 ?>