ryxeo-glpi-git / install / update_content.php @ b67d8923
Historique | Voir | Annoter | Télécharger (10,6 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: update_content.php 7763 2009-01-06 18:44:50Z moyo $
|
4 |
-------------------------------------------------------------------------
|
5 |
GLPI - Gestionnaire Libre de Parc Informatique
|
6 |
Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
7 |
|
8 |
http://indepnet.net/ http://glpi-project.org
|
9 |
-------------------------------------------------------------------------
|
10 |
|
11 |
LICENSE
|
12 |
|
13 |
This file is part of GLPI.
|
14 |
|
15 |
GLPI is free software; you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
17 |
the Free Software Foundation; either version 2 of the License, or
|
18 |
(at your option) any later version.
|
19 |
|
20 |
GLPI is distributed in the hope that it will be useful,
|
21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
GNU General Public License for more details.
|
24 |
|
25 |
You should have received a copy of the GNU General Public License
|
26 |
along with GLPI; if not, write to the Free Software
|
27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
28 |
--------------------------------------------------------------------------
|
29 |
*/
|
30 |
|
31 |
// ----------------------------------------------------------------------
|
32 |
// Original Author of file: Julien Dombre & Bazile Lebeau
|
33 |
// Purpose of file:
|
34 |
// ----------------------------------------------------------------------
|
35 |
|
36 |
//#################### INCLUDE & SESSIONS ############################
|
37 |
define('GLPI_ROOT', '..'); |
38 |
|
39 |
include_once (GLPI_ROOT . "/config/define.php"); |
40 |
|
41 |
include_once (GLPI_ROOT . "/inc/dbmysql.class.php"); |
42 |
include_once (GLPI_ROOT . "/inc/common.function.php"); |
43 |
include_once (GLPI_ROOT . "/inc/display.function.php"); |
44 |
include_once (GLPI_ROOT . "/inc/db.function.php"); |
45 |
include_once (GLPI_ROOT . "/config/based_config.php"); |
46 |
include_once (GLPI_CONFIG_DIR . "/config_db.php"); |
47 |
|
48 |
setGlpiSessionPath(); |
49 |
startGlpiSession(); |
50 |
|
51 |
// Init debug variable
|
52 |
$CFG_GLPI["debug"]=DEBUG_MODE; |
53 |
$CFG_GLPI["debug_sql"]=$CFG_GLPI["debug_vars"]=$CFG_GLPI["debug_profile"]=$CFG_GLPI["debug_lang"]=0; |
54 |
$CFG_GLPI["use_errorlog"]=1; |
55 |
//################################ Functions ################################
|
56 |
|
57 |
function loadLang() { |
58 |
if (isset($LANG)){ |
59 |
unset($LANG); |
60 |
} |
61 |
global $LANG; |
62 |
if (isset($_SESSION["glpilanguage"])) |
63 |
$dict=$_SESSION["glpilanguage"]; |
64 |
else $dict="en_GB"; |
65 |
|
66 |
$file = GLPI_ROOT ."/locales/$dict.php"; |
67 |
if (!is_file($file)) |
68 |
$file = GLPI_ROOT ."/locales/en_GB.php"; |
69 |
include($file); |
70 |
} |
71 |
|
72 |
$max_time=min(get_cfg_var("max_execution_time"),get_cfg_var("max_input_time")); |
73 |
if ($max_time>5) {$defaulttimeout=$max_time-2;$defaultrowlimit=1;} |
74 |
else {$defaulttimeout=1;$defaultrowlimit=1;} |
75 |
|
76 |
$DB=new DB; |
77 |
|
78 |
function init_time() |
79 |
{ |
80 |
global $TPSDEB,$TPSCOUR; |
81 |
|
82 |
|
83 |
list ($usec,$sec)=explode(" ",microtime()); |
84 |
$TPSDEB=$sec; |
85 |
$TPSCOUR=0; |
86 |
|
87 |
} |
88 |
|
89 |
function current_time() |
90 |
{ |
91 |
global $TPSDEB,$TPSCOUR; |
92 |
list ($usec,$sec)=explode(" ",microtime()); |
93 |
$TPSFIN=$sec; |
94 |
if (round($TPSFIN-$TPSDEB,1)>=$TPSCOUR+1) //une seconde de plus |
95 |
{ |
96 |
$TPSCOUR=round($TPSFIN-$TPSDEB,1); |
97 |
} |
98 |
|
99 |
} |
100 |
|
101 |
|
102 |
function get_update_content($DB, $table,$from,$limit,$conv_utf8) |
103 |
{ |
104 |
$content=""; |
105 |
$DB->query("SET NAMES latin1"); |
106 |
|
107 |
$result = $DB->query("SELECT * FROM $table LIMIT $from,$limit"); |
108 |
|
109 |
if($result){ |
110 |
while($row = $DB->fetch_assoc($result)) { |
111 |
if (isset($row["ID"])) { |
112 |
$insert = "UPDATE $table SET "; |
113 |
foreach ($row as $key => $val) { |
114 |
$insert.=" `".$key."`="; |
115 |
|
116 |
if(!isset($val)) $insert .= "NULL,"; |
117 |
else if($val != "") { |
118 |
if ($conv_utf8) { |
119 |
// Gestion users AD qui sont d��en UTF8
|
120 |
if ($table!="glpi_users"||!seems_utf8($val)) |
121 |
$val=utf8_encode($val); |
122 |
} |
123 |
$insert .= "'".addslashes($val)."',"; |
124 |
} |
125 |
else $insert .= "'',"; |
126 |
} |
127 |
$insert = ereg_replace(",$","",$insert); |
128 |
$insert.=" WHERE ID = '".$row["ID"]."' "; |
129 |
$insert .= ";\n"; |
130 |
$content .= $insert; |
131 |
} |
132 |
} |
133 |
} |
134 |
//if ($table=="glpi_dropdown_locations") echo $content;
|
135 |
return $content; |
136 |
} |
137 |
|
138 |
|
139 |
function UpdateContent($DB, $duree,$rowlimit,$conv_utf8,$complete_utf8) |
140 |
{ |
141 |
// $dumpFile, fichier source
|
142 |
// $database, nom de la base de données cible
|
143 |
// $mysqlUser, login pouyr la connexion au serveur MySql
|
144 |
// $mysqlPassword, mot de passe
|
145 |
// $histMySql, nom de la machine serveur MySQl
|
146 |
// $duree=timeout pour changement de page (-1 = aucun)
|
147 |
|
148 |
|
149 |
global $TPSCOUR,$offsettable,$offsetrow,$cpt,$LANG; |
150 |
|
151 |
$result=$DB->list_tables(); |
152 |
$numtab=0; |
153 |
while ($t=$DB->fetch_array($result)){ |
154 |
if (ereg("glpi_",$t[0])){ |
155 |
$tables[$numtab]=$t[0]; |
156 |
$numtab++;
|
157 |
} |
158 |
} |
159 |
|
160 |
|
161 |
for (;$offsettable<$numtab;$offsettable++){ |
162 |
// echo $tables[$offsettable]."<br>\n";
|
163 |
// Dump de la structyre table
|
164 |
if ($offsetrow==-1){ |
165 |
if ($complete_utf8){ |
166 |
$DB->query("ALTER TABLE `".$tables[$offsettable]."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"); |
167 |
$data=$DB->list_fields($tables[$offsettable]); |
168 |
|
169 |
foreach ($data as $key =>$val){ |
170 |
// echo "<br>".$key."<br>";
|
171 |
// print_r($val);
|
172 |
|
173 |
if (eregi("^char",$val["Type"])){ |
174 |
$default="NULL"; |
175 |
if (!empty($val["Default"])&&!is_null($val["Default"])){ |
176 |
$default="'".$val["Default"]."'"; |
177 |
} |
178 |
|
179 |
$DB->query("ALTER TABLE `".$tables[$offsettable]."` CHANGE `".$val["Field"]."` `".$val["Field"]."` ".$val["Type"]." CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT $default"); |
180 |
} else if (eregi("^varchar",$val["Type"])){ |
181 |
$default="NULL"; |
182 |
if (!empty($val["Default"])&&!is_null($val["Default"])){ |
183 |
$default="'".$val["Default"]."'"; |
184 |
} |
185 |
$DB->query("ALTER TABLE `".$tables[$offsettable]."` CHANGE `".$val["Field"]."` `".$val["Field"]."` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT $default"); |
186 |
} else if (eregi("^longtext",$val["Type"])){ |
187 |
$DB->query("ALTER TABLE `".$tables[$offsettable]."` CHANGE `".$val["Field"]."` `".$val["Field"]."` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL"); |
188 |
} else if (eregi("^text",$val["Type"])){ |
189 |
$DB->query("ALTER TABLE `".$tables[$offsettable]."` CHANGE `".$val["Field"]."` `".$val["Field"]."` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL"); |
190 |
} else if (eregi("^tinyint",$val["Type"])){ |
191 |
$DB->query("ALTER TABLE `".$tables[$offsettable]."` CHANGE `".$val["Field"]."` `".$val["Field"]."` SMALLINT NOT NULL DEFAULT '".$val["Default"]."'"); |
192 |
} |
193 |
|
194 |
} |
195 |
} |
196 |
$offsetrow++;
|
197 |
$cpt++;
|
198 |
} |
199 |
|
200 |
current_time(); |
201 |
if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti |
202 |
return TRUE; |
203 |
|
204 |
$fin=0; |
205 |
while (!$fin){ |
206 |
$todump=get_update_content($DB,$tables[$offsettable],$offsetrow,$rowlimit,$conv_utf8); |
207 |
// echo $todump."<br>";
|
208 |
$rowtodump=substr_count($todump, "UPDATE "); |
209 |
if ($rowtodump>0){ |
210 |
$DB->query("SET NAMES utf8"); |
211 |
$result = $DB->query($todump); |
212 |
// if (!$result) echo "ECHEC ".$todump;
|
213 |
|
214 |
$cpt+=$rowtodump; |
215 |
$offsetrow+=$rowlimit; |
216 |
if ($rowtodump<$rowlimit) $fin=1; |
217 |
current_time(); |
218 |
if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti |
219 |
return TRUE; |
220 |
|
221 |
} |
222 |
else {$fin=1;$offsetrow=-1;} |
223 |
} |
224 |
if ($fin) $offsetrow=-1; |
225 |
current_time(); |
226 |
if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti |
227 |
return TRUE; |
228 |
|
229 |
} |
230 |
if ($DB->error()){ |
231 |
echo "<hr>".$LANG["backup"][23]." [$formattedQuery]<br>".$DB->error()."<hr>"; |
232 |
} |
233 |
$offsettable=-1; |
234 |
return TRUE; |
235 |
} |
236 |
|
237 |
//########################### Script start ################################
|
238 |
|
239 |
loadLang(); |
240 |
|
241 |
|
242 |
// Send UTF8 Headers
|
243 |
header("Content-Type: text/html; charset=UTF-8"); |
244 |
|
245 |
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"; |
246 |
echo "<html>"; |
247 |
echo "<head>"; |
248 |
echo " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"; |
249 |
echo "<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\"> "; |
250 |
echo "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"> "; |
251 |
echo "<meta http-equiv=\"Content-Language\" content=\"fr\"> "; |
252 |
echo "<meta name=\"generator\" content=\"\">"; |
253 |
echo "<meta name=\"DC.Language\" content=\"fr\" scheme=\"RFC1766\">"; |
254 |
echo "<title>Setup GLPI</title>"; |
255 |
// CSS
|
256 |
echo "<link rel='stylesheet' href='../css/style_install.css' type='text/css' media='screen' >"; |
257 |
|
258 |
echo "</head>"; |
259 |
echo "<body>"; |
260 |
echo "<div id='principal'>"; |
261 |
echo "<div id='bloc'>"; |
262 |
echo "<div class='haut'></div>"; |
263 |
echo "<h2>GLPI SETUP</h2>"; |
264 |
//end style and co
|
265 |
|
266 |
// #################" UPDATE CONTENT #################################
|
267 |
|
268 |
$time_file=date("Y-m-d-h-i"); |
269 |
$cur_time=date("Y-m-d H:i"); |
270 |
|
271 |
init_time(); //initialise le temps
|
272 |
//debut de fichier
|
273 |
if (!isset($_GET["offsettable"])) $offsettable=0; |
274 |
else $offsettable=$_GET["offsettable"]; |
275 |
//debut de fichier
|
276 |
if (!isset($_GET["offsetrow"])) $offsetrow=-1; |
277 |
else $offsetrow=$_GET["offsetrow"]; |
278 |
//timeout de 5 secondes par d�aut, -1 pour utiliser sans timeout
|
279 |
if (!isset($_GET["duree"])) $duree=$defaulttimeout; |
280 |
else $duree=$_GET["duree"]; |
281 |
//Limite de lignes �dumper �chaque fois
|
282 |
if (!isset($_GET["rowlimit"])) $rowlimit=$defaultrowlimit; |
283 |
else $rowlimit=$_GET["rowlimit"]; |
284 |
|
285 |
$tab=$DB->list_tables(); |
286 |
$tot=$DB->numrows($tab); |
287 |
if(isset($offsettable)){ |
288 |
if ($offsettable>=0) |
289 |
$percent=min(100,round(100*$offsettable/$tot,0)); |
290 |
else $percent=100; |
291 |
} |
292 |
else $percent=0; |
293 |
|
294 |
$conv_utf8=false; |
295 |
$complete_utf8=true; |
296 |
|
297 |
if(!FieldExists("glpi_config","utf8_conv")) { |
298 |
$conv_utf8=true; |
299 |
} else {
|
300 |
$query="SELECT utf8_conv FROM glpi_config WHERE ID='1'"; |
301 |
$result=$DB->query($query); |
302 |
$data=$DB->fetch_assoc($result); |
303 |
if ($data["utf8_conv"]){ |
304 |
$complete_utf8=false; |
305 |
} |
306 |
} |
307 |
|
308 |
if ($offsettable>=0&&$complete_utf8){ |
309 |
if ($percent >= 0) { |
310 |
|
311 |
displayProgressBar(400,$percent); |
312 |
echo "<div class='bas'></div></div></div></body></html>"; |
313 |
glpi_flush(); |
314 |
|
315 |
} |
316 |
if (UpdateContent($DB,$duree,$rowlimit,$conv_utf8,$complete_utf8)) |
317 |
{ |
318 |
echo "<br><a href=\"update_content.php?dump=1&duree=$duree&rowlimit=$rowlimit&offsetrow=$offsetrow&offsettable=$offsettable&cpt=$cpt\">".$LANG["backup"][24]."</a>"; |
319 |
echo "<script language=\"javascript\" type=\"text/javascript\">window.location=\"update_content.php?dump=1&duree=$duree&rowlimit=$rowlimit&offsetrow=$offsetrow&offsettable=$offsettable&cpt=$cpt\";</script>"; |
320 |
// echo "<div class='bas'></div></div></div></body></html>";
|
321 |
|
322 |
glpi_flush(); |
323 |
exit;
|
324 |
} |
325 |
} |
326 |
else {
|
327 |
echo "<p class='submit'> <a href=\"../index.php\"><span class='button'>".$LANG["install"][64]."</span></a></p>"; |
328 |
echo "<div class='bas'></div></div></div></body></html>"; |
329 |
|
330 |
} |
331 |
|
332 |
if ($conv_utf8){ |
333 |
$query = "ALTER TABLE `glpi_config` ADD `utf8_conv` INT( 11 ) DEFAULT '0' NOT NULL"; |
334 |
$DB->query($query) or die(" 0.6 add utf8_conv to glpi_config".$LANG["update"][90].$DB->error()); |
335 |
} |
336 |
|
337 |
if ($complete_utf8){ |
338 |
$DB->query("ALTER DATABASE `".$DB->dbdefault."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"); |
339 |
$DB->query("UPDATE glpi_config SET utf8_conv='1' WHERE ID='1'"); |
340 |
} |
341 |
|
342 |
?>
|