* Copyright (C) 2004-2006 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ */ /** \file htdocs/install/upgrade.php \brief Execute le script de migration \version $Revision$ */ include_once("./inc.php"); $migfile='^2.0.0-2.1.0.sql$'; $grant_query=''; $etape = 2; $ok = 0; // Cette page peut etre longue. On augmente le délai par défaut de 30 à 60. // Ne fonctionne que si on est pas en safe_mode. $err=error_reporting(); error_reporting(0); set_time_limit(60); error_reporting($err); $setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto'); $langs->setDefaultLang($setuplang); $langs->load("admin"); $langs->load("install"); pHeader($langs->trans("DatabaseMigration"),"upgrade2","upgrade"); if (file_exists($conffile)) { include_once($conffile); if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_'; define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix); } if($dolibarr_main_db_type == "mysql") { require_once($dolibarr_main_document_root . "/lib/mysql.lib.php"); $choix=1; } else { require_once($dolibarr_main_document_root . "/lib/pgsql.lib.php"); require_once($dolibarr_main_document_root . "/lib/grant.postgres.php"); $choix=2; } require_once($dolibarr_main_document_root . "/conf/conf.class.php"); if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") { print '

'.$langs->trans("DatabaseMigration").'

'; print ''; $error=0; $conf = new Conf();// on pourrait s'en passer $conf->db->type = $dolibarr_main_db_type; $conf->db->host = $dolibarr_main_db_host; $conf->db->name = $dolibarr_main_db_name; $conf->db->user = $dolibarr_main_db_user; $conf->db->pass = $dolibarr_main_db_pass; $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name); if ($db->connected == 1) { print ""; $ok = 1 ; } else { print ""; } if ($ok) { if($db->database_selected == 1) { dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name"); } else { $ok = 0 ; } } /*************************************************************************************** * * Chargement fichiers dans migration * ***************************************************************************************/ if ($ok) { if ($choix==1) $dir = "../../mysql/migration/"; else $dir = "../../pgsql/migration/"; $i = 0; $ok = 0; $handle=opendir($dir); while (($file = readdir($handle))!==false) { if (eregi($migfile,$file)) { print ''; $name = substr($file, 0, strlen($file) - 4); $buffer = ''; $fp = fopen($dir.$file,"r"); if ($fp) { while (!feof ($fp)) { $buf = fgets($fp, 4096); $buf = ereg_replace('--(.*)','',$buf); // Delete SQL comments //print $buf.'
'; $buffer .= $buf; if (eregi(';',$buffer)) { // Found new request $arraysql[$i]=trim($buffer); $i++; $buffer=''; } } if ($buffer) $arraysql[$i]=trim($buffer); fclose($fp); } // Loop on each request foreach($arraysql as $i=>$sql) { if ($sql) { // Ajout trace sur requete (eventuellement à commenter // si beaucoup de requetes) print('\n"); if ($db->query($sql)) { // print ''; } else { $errno=$db->errno(); $okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS', 'DB_ERROR_COLUMN_ALREADY_EXISTS', 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', 'DB_ERROR_RECORD_ALREADY_EXISTS', 'DB_ERROR_NOSUCHTABLE', 'DB_ERROR_NOSUCHFIELD', 'DB_ERROR_CANNOT_CREATE' // Qd contrainte deja existante ); if (in_array($errno,$okerror)) { // print ''; } else { print ''; print '"; print ''; $error++; } } // print ''; } } } } closedir($handle); if ($error == 0) { print ''; $ok = 1; } } print '
"; print $langs->trans("ServerConnection")." : $dolibarr_main_db_host".$langs->trans("OK")."
Erreur lors de la création de : $dolibarr_main_db_name".$langs->trans("Error")."
'; print $langs->trans("ChooseMigrateScript").''.$file.'
'.$langs->trans("Request").' '.($i+1)." sql='".$sql."'
OK'.$langs->trans("OK").'
'.$langs->trans("Request").' '.($i+1).''.$langs->trans("Error")." ".$db->errno()." ".$sql."
".$db->error()."
'; print $langs->trans("ProcessMigrateScript").''.$langs->trans("OK").'
'; $db->close(); } else { print '
'.$langs->trans("ErrorWrongParameters").'
'; } pFooter(! $ok,$setuplang); ?>