Fix: Corrige pb sur passage script migration si contient des requetes vides (lignes de blanc)
This commit is contained in:
parent
0c1e1e1a8c
commit
0ce24b707b
@ -1,219 +1,222 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
* $Source$
|
* $Source$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/install/upgrade.php
|
\file htdocs/install/upgrade.php
|
||||||
\brief Execute le script de migration
|
\brief Execute le script de migration
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once("./inc.php");
|
include_once("./inc.php");
|
||||||
|
|
||||||
$migfile='^2.0.0-2.1.0.sql$';
|
$migfile='^2.0.0-2.1.0.sql$';
|
||||||
$grant_query='';
|
$grant_query='';
|
||||||
$etape = 2;
|
$etape = 2;
|
||||||
$ok = 0;
|
$ok = 0;
|
||||||
|
|
||||||
|
|
||||||
// Cette page peut etre longue. On augmente le délai par défaut de 30 à 60.
|
// 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.
|
// Ne fonctionne que si on est pas en safe_mode.
|
||||||
$err=error_reporting();
|
$err=error_reporting();
|
||||||
error_reporting(0);
|
error_reporting(0);
|
||||||
set_time_limit(60);
|
set_time_limit(60);
|
||||||
error_reporting($err);
|
error_reporting($err);
|
||||||
|
|
||||||
$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto');
|
$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto');
|
||||||
$langs->setDefaultLang($setuplang);
|
$langs->setDefaultLang($setuplang);
|
||||||
|
|
||||||
$langs->load("admin");
|
$langs->load("admin");
|
||||||
$langs->load("install");
|
$langs->load("install");
|
||||||
|
|
||||||
|
|
||||||
pHeader($langs->trans("DatabaseMigration"),"upgrade2","upgrade");
|
pHeader($langs->trans("DatabaseMigration"),"upgrade2","upgrade");
|
||||||
|
|
||||||
|
|
||||||
if (file_exists($conffile))
|
if (file_exists($conffile))
|
||||||
{
|
{
|
||||||
include_once($conffile);
|
include_once($conffile);
|
||||||
if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_';
|
if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_';
|
||||||
define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);
|
define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($dolibarr_main_db_type == "mysql")
|
if($dolibarr_main_db_type == "mysql")
|
||||||
{
|
{
|
||||||
require_once($dolibarr_main_document_root . "/lib/mysql.lib.php");
|
require_once($dolibarr_main_document_root . "/lib/mysql.lib.php");
|
||||||
$choix=1;
|
$choix=1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
require_once($dolibarr_main_document_root . "/lib/pgsql.lib.php");
|
require_once($dolibarr_main_document_root . "/lib/pgsql.lib.php");
|
||||||
require_once($dolibarr_main_document_root . "/lib/grant.postgres.php");
|
require_once($dolibarr_main_document_root . "/lib/grant.postgres.php");
|
||||||
$choix=2;
|
$choix=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once($dolibarr_main_document_root . "/conf/conf.class.php");
|
require_once($dolibarr_main_document_root . "/conf/conf.class.php");
|
||||||
|
|
||||||
|
|
||||||
if (isset($_GET["action"]) && $_GET["action"] == "upgrade")
|
if (isset($_GET["action"]) && $_GET["action"] == "upgrade")
|
||||||
{
|
{
|
||||||
print '<h2>'.$langs->trans("DatabaseMigration").'</h2>';
|
print '<h2>'.$langs->trans("DatabaseMigration").'</h2>';
|
||||||
|
|
||||||
print '<table cellspacing="0" cellpadding="1" border="0" width="100%">';
|
print '<table cellspacing="0" cellpadding="1" border="0" width="100%">';
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
$conf = new Conf();// on pourrait s'en passer
|
$conf = new Conf();// on pourrait s'en passer
|
||||||
$conf->db->type = $dolibarr_main_db_type;
|
$conf->db->type = $dolibarr_main_db_type;
|
||||||
$conf->db->host = $dolibarr_main_db_host;
|
$conf->db->host = $dolibarr_main_db_host;
|
||||||
$conf->db->name = $dolibarr_main_db_name;
|
$conf->db->name = $dolibarr_main_db_name;
|
||||||
$conf->db->user = $dolibarr_main_db_user;
|
$conf->db->user = $dolibarr_main_db_user;
|
||||||
$conf->db->pass = $dolibarr_main_db_pass;
|
$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);
|
$db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name);
|
||||||
if ($db->connected == 1)
|
if ($db->connected == 1)
|
||||||
{
|
{
|
||||||
print "<tr><td nowrap>";
|
print "<tr><td nowrap>";
|
||||||
print $langs->trans("ServerConnection")." : $dolibarr_main_db_host</td><td align=\"right\">".$langs->trans("OK")."</td></tr>";
|
print $langs->trans("ServerConnection")." : $dolibarr_main_db_host</td><td align=\"right\">".$langs->trans("OK")."</td></tr>";
|
||||||
$ok = 1 ;
|
$ok = 1 ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "<tr><td>Erreur lors de la création de : $dolibarr_main_db_name</td><td align=\"right\">".$langs->trans("Error")."</td></tr>";
|
print "<tr><td>Erreur lors de la création de : $dolibarr_main_db_name</td><td align=\"right\">".$langs->trans("Error")."</td></tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ok)
|
if ($ok)
|
||||||
{
|
{
|
||||||
if($db->database_selected == 1)
|
if($db->database_selected == 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name");
|
dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$ok = 0 ;
|
$ok = 0 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************************
|
/***************************************************************************************
|
||||||
*
|
*
|
||||||
* Chargement fichiers dans migration
|
* Chargement fichiers dans migration
|
||||||
*
|
*
|
||||||
***************************************************************************************/
|
***************************************************************************************/
|
||||||
if ($ok)
|
if ($ok)
|
||||||
{
|
{
|
||||||
if ($choix==1) $dir = "../../mysql/migration/";
|
if ($choix==1) $dir = "../../mysql/migration/";
|
||||||
else $dir = "../../pgsql/migration/";
|
else $dir = "../../pgsql/migration/";
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$ok = 0;
|
$ok = 0;
|
||||||
$handle=opendir($dir);
|
$handle=opendir($dir);
|
||||||
while (($file = readdir($handle))!==false)
|
while (($file = readdir($handle))!==false)
|
||||||
{
|
{
|
||||||
if (eregi($migfile,$file))
|
if (eregi($migfile,$file))
|
||||||
{
|
{
|
||||||
print '<tr><td nowrap>';
|
print '<tr><td nowrap>';
|
||||||
print $langs->trans("ChooseMigrateScript").'</td><td align="right">'.$file.'</td></tr>';
|
print $langs->trans("ChooseMigrateScript").'</td><td align="right">'.$file.'</td></tr>';
|
||||||
|
|
||||||
$name = substr($file, 0, strlen($file) - 4);
|
$name = substr($file, 0, strlen($file) - 4);
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
$fp = fopen($dir.$file,"r");
|
$fp = fopen($dir.$file,"r");
|
||||||
if ($fp)
|
if ($fp)
|
||||||
{
|
{
|
||||||
while (!feof ($fp))
|
while (!feof ($fp))
|
||||||
{
|
{
|
||||||
$buf = fgets($fp, 4096);
|
$buf = fgets($fp, 4096);
|
||||||
$buf = ereg_replace('--(.*)','',$buf); // Delete SQL comments
|
$buf = ereg_replace('--(.*)','',$buf); // Delete SQL comments
|
||||||
//print $buf.'<br>';
|
//print $buf.'<br>';
|
||||||
$buffer .= $buf;
|
$buffer .= $buf;
|
||||||
if (eregi(';',$buffer))
|
if (eregi(';',$buffer))
|
||||||
{
|
{
|
||||||
// Found new request
|
// Found new request
|
||||||
$arraysql[$i]=$buffer;
|
$arraysql[$i]=trim($buffer);
|
||||||
$i++;
|
$i++;
|
||||||
$buffer='';
|
$buffer='';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($buffer) $arraysql[$i]=$buffer;
|
if ($buffer) $arraysql[$i]=trim($buffer);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop on each request
|
// Loop on each request
|
||||||
foreach($arraysql as $i=>$sql)
|
foreach($arraysql as $i=>$sql)
|
||||||
{
|
{
|
||||||
// print '<tr><td>'.$langs->trans("Request").' '.$i.'</td>';
|
if ($sql)
|
||||||
|
{
|
||||||
if ($db->query($sql))
|
// print '<tr><td>'.$langs->trans("Request").' '.$i.'</td>';
|
||||||
{
|
print("Execution de requete=".($i+1)." sql='".$sql."'<br>\n");
|
||||||
// print '<td align="right">OK</td>';
|
if ($db->query($sql))
|
||||||
}
|
{
|
||||||
else
|
// print '<td align="right">OK</td>';
|
||||||
{
|
}
|
||||||
$errno=$db->errno();
|
else
|
||||||
$okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS',
|
{
|
||||||
'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
$errno=$db->errno();
|
||||||
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
$okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS',
|
||||||
'DB_ERROR_RECORD_ALREADY_EXISTS',
|
'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
||||||
'DB_ERROR_NOSUCHTABLE',
|
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
||||||
'DB_ERROR_NOSUCHFIELD',
|
'DB_ERROR_RECORD_ALREADY_EXISTS',
|
||||||
'DB_ERROR_CANNOT_CREATE' // Qd contrainte deja existante
|
'DB_ERROR_NOSUCHTABLE',
|
||||||
);
|
'DB_ERROR_NOSUCHFIELD',
|
||||||
if (in_array($errno,$okerror))
|
'DB_ERROR_CANNOT_CREATE' // Qd contrainte deja existante
|
||||||
{
|
);
|
||||||
// print '<td align="right">'.$langs->trans("OK").'</td>';
|
if (in_array($errno,$okerror))
|
||||||
}
|
{
|
||||||
else
|
// print '<td align="right">'.$langs->trans("OK").'</td>';
|
||||||
{
|
}
|
||||||
print '<tr><td valign="top">'.$langs->trans("Request").' '.$i.'</td>';
|
else
|
||||||
print '<td valign="top">'.$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error()."</td>";
|
{
|
||||||
print '</tr>';
|
print '<tr><td valign="top">'.$langs->trans("Request").' '.($i+1).'</td>';
|
||||||
$error++;
|
print '<td valign="top">'.$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error()."</td>";
|
||||||
}
|
print '</tr>';
|
||||||
}
|
$error++;
|
||||||
|
}
|
||||||
// print '</tr>';
|
}
|
||||||
}
|
|
||||||
|
// print '</tr>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
closedir($handle);
|
}
|
||||||
|
|
||||||
if ($error == 0)
|
}
|
||||||
{
|
closedir($handle);
|
||||||
print '<tr><td>';
|
|
||||||
print $langs->trans("ProcessMigrateScript").'</td><td align="right">'.$langs->trans("OK").'</td></tr>';
|
if ($error == 0)
|
||||||
$ok = 1;
|
{
|
||||||
}
|
print '<tr><td>';
|
||||||
}
|
print $langs->trans("ProcessMigrateScript").'</td><td align="right">'.$langs->trans("OK").'</td></tr>';
|
||||||
|
$ok = 1;
|
||||||
print '</table>';
|
}
|
||||||
|
}
|
||||||
$db->close();
|
|
||||||
}
|
print '</table>';
|
||||||
else
|
|
||||||
{
|
$db->close();
|
||||||
print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>';
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
pFooter(! $ok,$setuplang);
|
print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>';
|
||||||
|
}
|
||||||
?>
|
|
||||||
|
pFooter(! $ok,$setuplang);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user