cliupdate.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  * @version $Id: cliupdate.php 21176 2013-06-23 14:23:49Z moyo $
00004  -------------------------------------------------------------------------
00005  GLPI - Gestionnaire Libre de Parc Informatique
00006  Copyright (C) 2003-2013 by the INDEPNET Development Team.
00007 
00008  http://indepnet.net/   http://glpi-project.org
00009  -------------------------------------------------------------------------
00010 
00011  LICENSE
00012 
00013  This file is part of GLPI.
00014 
00015  GLPI is free software; you can redistribute it and/or modify
00016  it under the terms of the GNU General Public License as published by
00017  the Free Software Foundation; either version 2 of the License, or
00018  (at your option) any later version.
00019 
00020  GLPI is distributed in the hope that it will be useful,
00021  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  GNU General Public License for more details.
00024 
00025  You should have received a copy of the GNU General Public License
00026  along with GLPI. If not, see <http://www.gnu.org/licenses/>.
00027  --------------------------------------------------------------------------
00028  */
00029 
00030 /** @file
00031 * @brief
00032 */
00033 
00034 if (in_array('--help', $_SERVER['argv'])) {
00035    die("usage: ".$_SERVER['argv'][0]."  [ --upgrade | --force ] [ --optimize ] [ --fr ]\n");
00036 }
00037 
00038 chdir(dirname($_SERVER["SCRIPT_FILENAME"]));
00039 
00040 if (!defined('GLPI_ROOT')) {
00041    define('GLPI_ROOT', realpath('..'));
00042 }
00043 
00044 include_once (GLPI_ROOT . "/inc/autoload.function.php");
00045 include_once (GLPI_ROOT . "/inc/db.function.php");
00046 include_once (GLPI_CONFIG_DIR . "/config_db.php");
00047 Config::detectRootDoc();
00048 
00049 // Old itemtype for compatibility
00050 define("GENERAL_TYPE",         0);
00051 define("COMPUTER_TYPE",        1);
00052 define("NETWORKING_TYPE",      2);
00053 define("PRINTER_TYPE",         3);
00054 define("MONITOR_TYPE",         4);
00055 define("PERIPHERAL_TYPE",      5);
00056 define("SOFTWARE_TYPE",        6);
00057 define("CONTACT_TYPE",         7);
00058 define("ENTERPRISE_TYPE",      8);
00059 define("INFOCOM_TYPE",         9);
00060 define("CONTRACT_TYPE",       10);
00061 define("CARTRIDGEITEM_TYPE",  11);
00062 define("TYPEDOC_TYPE",        12);
00063 define("DOCUMENT_TYPE",       13);
00064 define("KNOWBASE_TYPE",       14);
00065 define("USER_TYPE",           15);
00066 define("TRACKING_TYPE",       16);
00067 define("CONSUMABLEITEM_TYPE", 17);
00068 define("CONSUMABLE_TYPE",     18);
00069 define("CARTRIDGE_TYPE",      19);
00070 define("SOFTWARELICENSE_TYPE",20);
00071 define("LINK_TYPE",           21);
00072 define("STATE_TYPE",          22);
00073 define("PHONE_TYPE",          23);
00074 define("DEVICE_TYPE",         24);
00075 define("REMINDER_TYPE",       25);
00076 define("STAT_TYPE",           26);
00077 define("GROUP_TYPE",          27);
00078 define("ENTITY_TYPE",         28);
00079 define("RESERVATION_TYPE",    29);
00080 define("AUTHMAIL_TYPE",       30);
00081 define("AUTHLDAP_TYPE",       31);
00082 define("OCSNG_TYPE",          32);
00083 define("REGISTRY_TYPE",       33);
00084 define("PROFILE_TYPE",        34);
00085 define("MAILGATE_TYPE",       35);
00086 define("RULE_TYPE",           36);
00087 define("TRANSFER_TYPE",       37);
00088 define("BOOKMARK_TYPE",       38);
00089 define("SOFTWAREVERSION_TYPE",39);
00090 define("PLUGIN_TYPE",         40);
00091 define("COMPUTERDISK_TYPE",   41);
00092 define("NETWORKING_PORT_TYPE",42);
00093 define("FOLLOWUP_TYPE",       43);
00094 define("BUDGET_TYPE",         44);
00095 
00096 // Old devicetype for compatibility
00097 define("MOBOARD_DEVICE",   1);
00098 define("PROCESSOR_DEVICE", 2);
00099 define("RAM_DEVICE",       3);
00100 define("HDD_DEVICE",       4);
00101 define("NETWORK_DEVICE",   5);
00102 define("DRIVE_DEVICE",     6);
00103 define("CONTROL_DEVICE",   7);
00104 define("GFX_DEVICE",       8);
00105 define("SND_DEVICE",       9);
00106 define("PCI_DEVICE",      10);
00107 define("CASE_DEVICE",     11);
00108 define("POWER_DEVICE",    12);
00109 
00110 
00111 if (is_writable(GLPI_SESSION_DIR)) {
00112    Session::setPath();
00113 } else {
00114    die("Can't write in ".GLPI_SESSION_DIR."\n");
00115 }
00116 Session::start();
00117 
00118 // Init debug variable
00119 Toolbox::setDebugMode(Session::DEBUG_MODE, 0, 0, 1);
00120 $_SESSION['glpilanguage']  = (in_array('--fr', $_SERVER['argv']) ? 'fr_FR' : 'en_GB');
00121 
00122 Session::loadLanguage();
00123 
00124 $DB = new DB();
00125 if (!$DB->connected) {
00126    die("No DB connection\n");
00127 }
00128 
00129 /* ----------------------------------------------------------------- */
00130 /**
00131  * Extends class Migration to redefine display mode
00132 **/
00133 class CliMigration extends Migration {
00134 
00135 
00136    function __construct($ver) {
00137       $this->deb = time();
00138       $this->setVersion($ver);
00139    }
00140 
00141 
00142    function setVersion($ver) {
00143       $this->version = $ver;
00144    }
00145 
00146 
00147    function displayMessage ($msg) {
00148 
00149       $msg .= " (".Html::clean(Html::timestampToString(time()-$this->deb)).")";
00150       echo str_pad($msg, 100)."\r";
00151    }
00152 
00153 
00154    function displayTitle($title) {
00155       echo "\n".str_pad(" $title ", 100, '=', STR_PAD_BOTH)."\n";
00156    }
00157 
00158 
00159    function displayWarning($msg, $red=false) {
00160 
00161       if ($red) {
00162          $msg = "** $msg";
00163       }
00164       echo str_pad($msg, 100)."\n";
00165    }
00166 }
00167 
00168 /*---------------------------------------------------------------------*/
00169 
00170 if (TableExists("glpi_configs")) {
00171    $query = "SELECT `version`, `language`
00172              FROM `glpi_configs`";
00173 } else if (TableExists("glpi_config")) {
00174    $query = "SELECT `version`, `language`
00175              FROM `glpi_config`";
00176 } else {
00177    die("Bad schema\n");
00178 }
00179 
00180 $result          = $DB->query($query) or die("get current version ".$DB->error());
00181 $current_version = trim($DB->result($result,0,0));
00182 $glpilanguage    = trim($DB->result($result,0,1));
00183 
00184 $migration = new CliMigration($current_version);
00185 
00186 $migration->displayWarning("Current GLPI Data version: $current_version");
00187 $migration->displayWarning("Current GLPI Code version: ".GLPI_VERSION);
00188 $migration->displayWarning("Default GLPI Language: $glpilanguage");
00189 
00190 
00191 // To prevent problem of execution time
00192 ini_set("max_execution_time", "0");
00193 
00194 if (version_compare($current_version, GLPI_VERSION, 'ne')
00195     && !in_array('--upgrade', $_SERVER['argv'])) {
00196    die("Upgrade required\n");
00197 }
00198 
00199 switch ($current_version) {
00200    case "0.72.3" :
00201    case "0.72.4" :
00202       include("../install/update_0723_078.php");
00203       update0723to078();
00204 
00205    case "0.78" :
00206       include("../install/update_078_0781.php");
00207       update078to0781();
00208 
00209    case "0.78.1" :
00210       include("../install/update_0781_0782.php");
00211       update0781to0782();
00212 
00213    case "0.78.2":
00214    case "0.78.3":
00215    case "0.78.4":
00216    case "0.78.5":
00217       include("../install/update_0782_080.php");
00218       update0782to080();
00219 
00220    case "0.80" :
00221       include("../install/update_080_0801.php");
00222       update080to0801();
00223       // nobreak;
00224 
00225    case "0.80.1" :
00226    case "0.80.2" :
00227       include("../install/update_0801_0803.php");
00228       update0801to0803();
00229       // nobreak;
00230 
00231    case "0.80.3" :
00232    case "0.80.4" :
00233    case "0.80.5" :
00234    case "0.80.6" :
00235    case "0.80.61" :
00236    case "0.80.7" :
00237       include("../install/update_0803_083.php");
00238       update0803to083();
00239       // nobreak;
00240 
00241    case "0.83" :
00242       include("../install/update_083_0831.php");
00243       update083to0831();
00244       // nobreak;
00245 
00246    case "0.83.1" :
00247    case "0.83.2" :
00248       include("../install/update_0831_0833.php");
00249       update0831to0833();
00250 
00251    case "0.83.3" :
00252    case "0.83.31" :
00253    case "0.83.4" :
00254    case "0.83.5" :
00255    case "0.83.6" :
00256    case "0.83.7" :
00257    case "0.83.8" :
00258    case "0.83.9" :
00259    case "0.83.91" :
00260       include("../install/update_0831_084.php");
00261       update0831to084();
00262 
00263    case GLPI_VERSION :
00264       break;
00265 
00266    default :
00267       die("Unsupported version ($current_version)\n");
00268 }
00269 
00270 if (version_compare($current_version, GLPI_VERSION, 'ne')) {
00271 
00272    // Update version number and default langage and new version_founded ---- LEAVE AT THE END
00273    $query = "UPDATE `glpi_configs`
00274              SET `version` = '".GLPI_VERSION."',
00275                  `founded_new_version` = ''";
00276    $DB->queryOrDie($query, 'update version number');
00277 
00278    // Update process desactivate all plugins
00279    $plugin = new Plugin();
00280    $plugin->unactivateAll();
00281 
00282    $migration->displayWarning("\nMigration Done.");
00283 
00284 } else if (in_array('--force', $_SERVER['argv'])) {
00285 
00286    include("../install/update_0831_084.php");
00287    update0831to084();
00288 
00289    $migration->displayWarning("\nForced migration Done.");
00290 
00291 } else {
00292    $migration->displayWarning("No migration needed.");
00293 }
00294 
00295 
00296 if (in_array('--optimize', $_SERVER['argv'])) {
00297 
00298    DBmysql::optimize_tables($migration);
00299    $migration->displayWarning("Optimize done.");
00300 }
00301 ?>