5) {$defaulttimeout=$max_time-2;$defaultrowlimit=1;} else {$defaulttimeout=1;$defaultrowlimit=1;} $db=new DB; function init_time() { global $TPSDEB,$TPSCOUR; list ($usec,$sec)=explode(" ",microtime()); $TPSDEB=$sec; $TPSCOUR=0; } function current_time() { global $TPSDEB,$TPSCOUR; list ($usec,$sec)=explode(" ",microtime()); $TPSFIN=$sec; if (round($TPSFIN-$TPSDEB,1)>=$TPSCOUR+1) //une seconde de plus { $TPSCOUR=round($TPSFIN-$TPSDEB,1); } } function test_content_ok(){ global $db; $query1="SELECT ID FROM glpi_computers WHERE comments LIKE '%\\\\\\%';"; $query2="SELECT ID FROM glpi_printers WHERE comments LIKE '%\\\\\\%';"; $query3="SELECT ID FROM glpi_tracking WHERE contents LIKE '%\\\\\\%';"; $query4="SELECT ID FROM glpi_followups WHERE contents LIKE '%\\\\\\%';"; $result1=$db->query($query1); if ($db->numrows($result1)>0) return false; $result4=$db->query($query4); if ($db->numrows($result4)>0) return false; $result3=$db->query($query3); if ($db->numrows($result3)>0) return false; $result2=$db->query($query2); if ($db->numrows($result2)>0) return false; return true; } function seems_utf8($Str) { for ($i=0; $iquery("SELECT * FROM $table LIMIT $from,$limit"); if($result) while($row = $db->fetch_assoc($result)) { if (isset($row["ID"])) { if (get_magic_quotes_runtime()) $row=stripslashes_deep($row); $row=stripslashes_deep($row); $insert = "UPDATE $table SET "; foreach ($row as $key => $val) { $insert.=" ".$key."="; if(!isset($val)) $insert .= "NULL,"; else if($val != "") { if ($conv_utf8) { // Gestion users AD qui sont déjà en UTF8 if ($table!="glpi_users"||!seems_utf8($val)) $val=utf8_encode($val); } $insert .= "'".addslashes($val)."',"; } else $insert .= "'',"; } $insert = ereg_replace(",$","",$insert); $insert.=" WHERE ID = '".$row["ID"]."' "; $insert .= ";\n"; $content .= $insert; } } //if ($table=="glpi_dropdown_locations") echo $content; return $content; } function UpdateContent($db, $duree,$rowlimit,$conv_utf8) { // $dumpFile, fichier source // $database, nom de la base de données cible // $mysqlUser, login pouyr la connexion au serveur MySql // $mysqlPassword, mot de passe // $histMySql, nom de la machine serveur MySQl // $duree=timeout pour changement de page (-1 = aucun) global $TPSCOUR,$offsettable,$offsetrow,$cpt; if ($db->error) { echo "Connexion impossible à $hostMySql pour $mysqlUser"; return FALSE; } $result=$db->list_tables(); $numtab=0; while ($t=$db->fetch_array($result)){ if (ereg("glpi_",$t[0])){ $tables[$numtab]=$t[0]; $numtab++; } } for (;$offsettable<$numtab;$offsettable++){ // Dump de la strucutre table if ($offsetrow==-1){ $offsetrow++; $cpt++; } current_time(); if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti return TRUE; $fin=0; while (!$fin){ $todump=get_update_content($db,$tables[$offsettable],$offsetrow,$rowlimit,$conv_utf8); // echo $todump."
"; $rowtodump=substr_count($todump, "UPDATE "); if ($rowtodump>0){ // echo $todump; $result = $db->query($todump); // if (!$result) echo "ECHEC ".$todump; $cpt+=$rowtodump; $offsetrow+=$rowlimit; if ($rowtodump<$rowlimit) $fin=1; current_time(); if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti return TRUE; } else {$fin=1;$offsetrow=-1;} } if ($fin) $offsetrow=-1; current_time(); if ($duree>0 and $TPSCOUR>=$duree) //on atteint la fin du temps imparti return TRUE; } if ($db->error()) echo "
ERREUR à partir de [$formattedQuery]
".$db->error()."
"; $offsettable=-1; return TRUE; } //########################### Script start ################################ loadLang(); // Send UTF8 Headers header("Content-Type: text/html; charset=UTF-8"); //style and co echo ""; echo ""; echo ""; echo " "; echo " "; echo " "; echo " "; echo ""; echo ""; echo "Setup GLPI"; echo ""; echo ""; echo ""; echo "
"; //end style and co /*if (!isset($_POST["oui"])&&!isset($_POST["non"])&&!isset($_GET["dump"])) if (test_content_ok()) { echo "
"; echo $lang["update"]["108"]; echo $lang["update"]["109"]; echo "
"; echo "  "; echo ""; echo "
"; } else { echo "
"; echo $lang["update"]["110"]; echo $lang["update"]["109"]; echo "
"; echo "  "; echo ""; echo "
"; } */ // #################" UPDATE CONTENT ################################# $time_file=date("Y-m-d-h-i"); $cur_time=date("Y-m-d H:i"); init_time(); //initialise le temps //début de fichier if (!isset($_GET["offsettable"])) $offsettable=0; else $offsettable=$_GET["offsettable"]; //début de fichier if (!isset($_GET["offsetrow"])) $offsetrow=-1; else $offsetrow=$_GET["offsetrow"]; //timeout de 5 secondes par défaut, -1 pour utiliser sans timeout if (!isset($_GET["duree"])) $duree=$defaulttimeout; else $duree=$_GET["duree"]; //Limite de lignes à dumper à chaque fois if (!isset($_GET["rowlimit"])) $rowlimit=$defaultrowlimit; else $rowlimit=$_GET["rowlimit"]; $tab=$db->list_tables(); $tot=$db->numrows($tab); if(isset($offsettable)){ if ($offsettable>=0) $percent=min(100,round(100*$offsettable/$tot,0)); else $percent=100; } else $percent=0; if ($percent >= 0) { displayProgressBar(400,$percent); } $conv_utf8=false; if(!FieldExists("glpi_config","utf8_conv")) { $conv_utf8=true; } if ($offsettable>=0){ if (UpdateContent($db,$duree,$rowlimit,$conv_utf8)) { echo "
Redirection automatique sinon cliquez ici"; echo ""; echo "
"; glpi_flush(); exit; } } else { //echo "

Terminé. Nombre de requêtes totales traitées : $cpt

"; echo "

".$lang["install"][64]."

"; echo ""; } if ($conv_utf8){ $query = "ALTER TABLE `glpi_config` ADD `utf8_conv` INT( 11 ) DEFAULT '0' NOT NULL"; $db->query($query) or die(" 0.6 add utf8_conv to glpi_config".$lang["update"][90].$db->error()); } ?>