diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php
index 7f3d3be9bc9..8c6c16c7bb5 100644
--- a/htdocs/install/upgrade.php
+++ b/htdocs/install/upgrade.php
@@ -48,7 +48,8 @@ $versionfrom=GETPOST("versionfrom",'',3)?GETPOST("versionfrom",'',3):(empty($arg
$versionto=GETPOST("versionto",'',3)?GETPOST("versionto",'',3):(empty($argv[2])?'':$argv[2]);
$langs->load("admin");
-$langs->load("install");
+$langs->load("install");
+$langs->load("errors");
if ($dolibarr_main_db_type == "mysql") $choix=1;
if ($dolibarr_main_db_type == "mysqli") $choix=1;
@@ -152,79 +153,96 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
print '
| '.$langs->trans("ServerVersion").' | ';
print ''.$version.' |
';
dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ServerVersion")." : $version");
- //print ''.join('.',$versionarray).' | ';
+
+ // Test database version
+ $versionmindb=getStaticMember(get_class($db),'versionmin');
+ //print join('.',$versionarray).' - '.join('.',$versionmindb);
+ if (count($versionmindb) && count($versionarray)
+ && versioncompare($versionarray,$versionmindb) < 0)
+ {
+ // Warning: database version too low.
+ print "| ".$langs->trans("ErrorDatabaseVersionTooLow",join('.',$versionarray),join('.',$versionmindb))." | ".$langs->trans("Error")." |
\n";
+ dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ErrorDatabaseVersionTooLow",join('.',$versionarray),join('.',$versionmindb)));
+ $ok=0;
+ }
+
}
// Force l'affichage de la progression
- print '| '.$langs->trans("PleaseBePatient").' |
';
- flush();
-
+ if ($ok)
+ {
+ print '| '.$langs->trans("PleaseBePatient").' |
';
+ flush();
+ }
/*
* Delete duplicates in table categorie_association
*/
- $couples=array();
- $filles=array();
- $sql = "SELECT fk_categorie_mere, fk_categorie_fille";
- $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
- dolibarr_install_syslog("upgrade: search duplicate sql=".$sql);
- $resql = $db->query($sql);
- if ($resql)
+ if ($ok)
{
- $num=$db->num_rows($resql);
- while ($obj=$db->fetch_object($resql))
- {
- if (! isset($filles[$obj->fk_categorie_fille])) // Only one record as child (a child has only on parent).
- {
- if ($obj->fk_categorie_mere != $obj->fk_categorie_fille)
- {
- $filles[$obj->fk_categorie_fille]=1; // Set record for this child
- $couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille]=array('mere'=>$obj->fk_categorie_mere, 'fille'=>$obj->fk_categorie_fille);
- }
- }
- }
+ $couples=array();
+ $filles=array();
+ $sql = "SELECT fk_categorie_mere, fk_categorie_fille";
+ $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
+ dolibarr_install_syslog("upgrade: search duplicate sql=".$sql);
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num=$db->num_rows($resql);
+ while ($obj=$db->fetch_object($resql))
+ {
+ if (! isset($filles[$obj->fk_categorie_fille])) // Only one record as child (a child has only on parent).
+ {
+ if ($obj->fk_categorie_mere != $obj->fk_categorie_fille)
+ {
+ $filles[$obj->fk_categorie_fille]=1; // Set record for this child
+ $couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille]=array('mere'=>$obj->fk_categorie_mere, 'fille'=>$obj->fk_categorie_fille);
+ }
+ }
+ }
- dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples));
+ dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples));
- // If there is duplicates couples or child with two parents
- if (count($couples) > 0 && $num > count($couples))
- {
- $error=0;
+ // If there is duplicates couples or child with two parents
+ if (count($couples) > 0 && $num > count($couples))
+ {
+ $error=0;
- $db->begin();
+ $db->begin();
- $sql="DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
- dolibarr_install_syslog("upgrade: delete association sql=".$sql);
- $resqld=$db->query($sql);
- if ($resqld)
- {
- foreach($couples as $key => $val)
- {
- $sql ="INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
- $sql.=" VALUES(".$val['mere'].", ".$val['fille'].")";
- dolibarr_install_syslog("upgrade: insert association sql=".$sql);
- $resqli=$db->query($sql);
- if (! $resqli) $error++;
- }
- }
+ $sql="DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
+ dolibarr_install_syslog("upgrade: delete association sql=".$sql);
+ $resqld=$db->query($sql);
+ if ($resqld)
+ {
+ foreach($couples as $key => $val)
+ {
+ $sql ="INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
+ $sql.=" VALUES(".$val['mere'].", ".$val['fille'].")";
+ dolibarr_install_syslog("upgrade: insert association sql=".$sql);
+ $resqli=$db->query($sql);
+ if (! $resqli) $error++;
+ }
+ }
- if (! $error)
- {
- print '| '.$langs->trans("RemoveDuplicates").' | ';
- print ''.$langs->trans("Success").' ('.$num.'=>'.count($couples).') |
';
- $db->commit();
- }
- else
- {
- print '| '.$langs->trans("RemoveDuplicates").' | ';
- print ''.$langs->trans("Failed").' |
';
- $db->rollback();
- }
- }
- }
- else
- {
- print ''.$langs->trans("Error").'
';
+ if (! $error)
+ {
+ print '| '.$langs->trans("RemoveDuplicates").' | ';
+ print ''.$langs->trans("Success").' ('.$num.'=>'.count($couples).') |
';
+ $db->commit();
+ }
+ else
+ {
+ print '| '.$langs->trans("RemoveDuplicates").' | ';
+ print ''.$langs->trans("Failed").' |
';
+ $db->rollback();
+ }
+ }
+ }
+ else
+ {
+ print ''.$langs->trans("Error").'
';
+ }
}
/*
@@ -232,7 +250,7 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
*/
if ($ok && preg_match('/mysql/',$db->type))
{
- $versioncommande=explode('.','4.0');
+ $versioncommande=array(4,0,0);
if (count($versioncommande) && count($versionarray)
&& versioncompare($versioncommande,$versionarray) <= 0) // Si mysql >= 4.0
{
diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang
index 8b078507d7c..cd43be5c0af 100644
--- a/htdocs/langs/en_US/install.lang
+++ b/htdocs/langs/en_US/install.lang
@@ -26,6 +26,7 @@ ErrorGoBackAndCorrectParameters=Go backward and correct wrong parameters.
ErrorWrongValueForParameter=You may have typed a wrong value for parameter '%s'.
ErrorFailedToCreateDatabase=Failed to create database '%s'.
ErrorFailedToConnectToDatabase=Failed to connect to database '%s'.
+ErrorDatabaseVersionTooLow=Database version (%s) too old. Version %s or higher is required.
ErrorPHPVersionTooLow=PHP version too old. Version %s is required.
WarningPHPVersionTooLow=PHP version too old. Version %s or more is expected. This version should allow install but is not supported.
ErrorConnectedButDatabaseNotFound=Connection to server successfull but database '%s' not found.
diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang
index 83553a53b5b..2dd0216fbc8 100644
--- a/htdocs/langs/fr_FR/install.lang
+++ b/htdocs/langs/fr_FR/install.lang
@@ -26,6 +26,7 @@ ErrorGoBackAndCorrectParameters=Revenez en arrière et corrigez les paramètres
ErrorWrongValueForParameter=Vous avez peut-être saisi une mauvaise valeur pour le paramètre '%s'.
ErrorFailedToCreateDatabase=Echec de création de la base '%s'.
ErrorFailedToConnectToDatabase=Echec de connexion à la base '%s'.
+ErrorDatabaseVersionTooLow=Version de base de donnée (%s) trop ancienne. La version %s ou supérieure est requise.
ErrorPHPVersionTooLow=Version de PHP trop ancienne. La version %s est requise.
WarningPHPVersionTooLow=Version de PHP trop ancienne. La version %s ou plus est recommandée. Cette version reste utilisable mais n'est pas supportée.
ErrorConnectedButDatabaseNotFound=Connexion au serveur réussi mais base '%s' introuvable.