[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: upgrade.php,v 1.8.2.1 2006/01/04 16:19:36 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/install/upgrade.php,v $ 21 */ 22 23 /** 24 \file htdocs/install/upgrade.php 25 \brief Execute le script de migration 26 \version $Revision: 1.8.2.1 $ 27 */ 28 29 include_once ("./inc.php"); 30 31 $grant_query=''; 32 $etape = 2; 33 $ok = 0; 34 35 36 // Cette page peut etre longue. On augmente le délai par défaut de 30 à 60. 37 // Ne fonctionne que si on est pas en safe_mode. 38 $err=error_reporting(); 39 error_reporting(0); 40 set_time_limit(60); 41 error_reporting($err); 42 43 $setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto'); 44 $langs->setDefaultLang($setuplang); 45 46 $langs->load("admin"); 47 $langs->load("install"); 48 49 50 pHeader($langs->trans("DatabaseMigration"),"upgrade2","upgrade"); 51 52 53 if (file_exists($conffile)) 54 { 55 include_once($conffile); 56 if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_'; 57 define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix); 58 } 59 60 if($dolibarr_main_db_type == "mysql") 61 { 62 require_once($dolibarr_main_document_root . "/lib/mysql.lib.php"); 63 $choix=1; 64 } 65 else 66 { 67 require_once($dolibarr_main_document_root . "/lib/pgsql.lib.php"); 68 require_once($dolibarr_main_document_root . "/lib/grant.postgres.php"); 69 $choix=2; 70 } 71 72 require_once($dolibarr_main_document_root . "/conf/conf.class.php"); 73 74 75 if (isset($_GET["action"]) && $_GET["action"] == "upgrade") 76 { 77 print '<h2>'.$langs->trans("DatabaseMigration").'</h2>'; 78 79 print '<table cellspacing="0" cellpadding="1" border="0" width="100%">'; 80 $error=0; 81 82 $conf = new Conf();// on pourrait s'en passer 83 $conf->db->type = $dolibarr_main_db_type; 84 $conf->db->host = $dolibarr_main_db_host; 85 $conf->db->name = $dolibarr_main_db_name; 86 $conf->db->user = $dolibarr_main_db_user; 87 $conf->db->pass = $dolibarr_main_db_pass; 88 89 $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name); 90 if ($db->connected == 1) 91 { 92 print "<tr><td nowrap>"; 93 print $langs->trans("ServerConnection")." : $dolibarr_main_db_host</td><td align=\"right\">".$langs->trans("OK")."</td></tr>"; 94 $ok = 1 ; 95 } 96 else 97 { 98 print "<tr><td>Erreur lors de la création de : $dolibarr_main_db_name</td><td align=\"right\">".$langs->trans("Error")."</td></tr>"; 99 } 100 101 if ($ok) 102 { 103 if($db->database_selected == 1) 104 { 105 106 dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name"); 107 } 108 else 109 { 110 $ok = 0 ; 111 } 112 } 113 114 115 /*************************************************************************************** 116 * 117 * Chargement fichiers dans migration 118 * 119 ***************************************************************************************/ 120 if ($ok) 121 { 122 if ($choix==1) $dir = "../../mysql/migration/"; 123 else $dir = "../../pgsql/migration/"; 124 $migfile='^1.1.0-2.0.0.sql$'; 125 126 $i = 0; 127 $ok = 0; 128 $handle=opendir($dir); 129 while (($file = readdir($handle))!==false) 130 { 131 if (eregi($migfile,$file)) 132 { 133 print '<tr><td nowrap>'; 134 print $langs->trans("ChooseMigrateScript").'</td><td align="right">'.$file.'</td></tr>'; 135 136 $name = substr($file, 0, strlen($file) - 4); 137 $buffer = ''; 138 $fp = fopen($dir.$file,"r"); 139 if ($fp) 140 { 141 while (!feof ($fp)) 142 { 143 $buf = fgets($fp, 4096); 144 $buf = ereg_replace('--(.*)','',$buf); // Delete SQL comments 145 //print $buf.'<br>'; 146 $buffer .= $buf; 147 if (eregi(';',$buffer)) 148 { 149 // Found new request 150 $arraysql[$i]=$buffer; 151 $i++; 152 $buffer=''; 153 } 154 } 155 if ($buffer) $arraysql[$i]=$buffer; 156 fclose($fp); 157 } 158 159 // Loop on each request 160 foreach($arraysql as $i=>$sql) 161 { 162 // print '<tr><td>'.$langs->trans("Request").' '.$i.'</td>'; 163 164 if ($db->query($sql)) 165 { 166 // print '<td align="right">OK</td>'; 167 } 168 else 169 { 170 $errno=$db->errno(); 171 $okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS', 172 'DB_ERROR_COLUMN_ALREADY_EXISTS', 173 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', 174 'DB_ERROR_RECORD_ALREADY_EXISTS', 175 'DB_ERROR_NOSUCHTABLE', 176 'DB_ERROR_NOSUCHFIELD', 177 'DB_ERROR_CANNOT_CREATE' // Qd contrainte deja existante 178 ); 179 if (in_array($errno,$okerror)) 180 { 181 // print '<td align="right">'.$langs->trans("OK").'</td>'; 182 } 183 else 184 { 185 print '<tr><td valign="top">'.$langs->trans("Request").' '.$i.'</td>'; 186 print '<td valign="top">'.$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error()."</td>"; 187 print '</tr>'; 188 $error++; 189 } 190 } 191 192 // print '</tr>'; 193 } 194 195 } 196 197 } 198 closedir($handle); 199 200 if ($error == 0) 201 { 202 print '<tr><td>'; 203 print $langs->trans("ProcessMigrateScript").'</td><td align="right">'.$langs->trans("OK").'</td></tr>'; 204 $ok = 1; 205 } 206 } 207 208 print '</table>'; 209 210 $db->close(); 211 } 212 else 213 { 214 print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>'; 215 } 216 217 pFooter(! $ok,$setuplang); 218 219 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |