New: Add a test during upgrade if database version is too low.
This commit is contained in:
parent
5536df6941
commit
1ccb8f3363
@ -49,6 +49,7 @@ $versionto=GETPOST("versionto",'',3)?GETPOST("versionto",'',3):(empty($argv[2])?
|
|||||||
|
|
||||||
$langs->load("admin");
|
$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 == "mysql") $choix=1;
|
||||||
if ($dolibarr_main_db_type == "mysqli") $choix=1;
|
if ($dolibarr_main_db_type == "mysqli") $choix=1;
|
||||||
@ -152,79 +153,96 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
|
|||||||
print '<tr><td>'.$langs->trans("ServerVersion").'</td>';
|
print '<tr><td>'.$langs->trans("ServerVersion").'</td>';
|
||||||
print '<td align="right">'.$version.'</td></tr>';
|
print '<td align="right">'.$version.'</td></tr>';
|
||||||
dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ServerVersion")." : $version");
|
dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ServerVersion")." : $version");
|
||||||
//print '<td align="right">'.join('.',$versionarray).'</td></tr>';
|
|
||||||
|
// 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 "<tr><td>".$langs->trans("ErrorDatabaseVersionTooLow",join('.',$versionarray),join('.',$versionmindb))."</td><td align=\"right\">".$langs->trans("Error")."</td></tr>\n";
|
||||||
|
dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ErrorDatabaseVersionTooLow",join('.',$versionarray),join('.',$versionmindb)));
|
||||||
|
$ok=0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force l'affichage de la progression
|
// Force l'affichage de la progression
|
||||||
print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>';
|
if ($ok)
|
||||||
flush();
|
{
|
||||||
|
print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>';
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete duplicates in table categorie_association
|
* Delete duplicates in table categorie_association
|
||||||
*/
|
*/
|
||||||
$couples=array();
|
if ($ok)
|
||||||
$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);
|
$couples=array();
|
||||||
while ($obj=$db->fetch_object($resql))
|
$filles=array();
|
||||||
{
|
$sql = "SELECT fk_categorie_mere, fk_categorie_fille";
|
||||||
if (! isset($filles[$obj->fk_categorie_fille])) // Only one record as child (a child has only on parent).
|
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
|
||||||
{
|
dolibarr_install_syslog("upgrade: search duplicate sql=".$sql);
|
||||||
if ($obj->fk_categorie_mere != $obj->fk_categorie_fille)
|
$resql = $db->query($sql);
|
||||||
{
|
if ($resql)
|
||||||
$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);
|
$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 there is duplicates couples or child with two parents
|
||||||
if (count($couples) > 0 && $num > count($couples))
|
if (count($couples) > 0 && $num > count($couples))
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
$sql="DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
|
$sql="DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
|
||||||
dolibarr_install_syslog("upgrade: delete association sql=".$sql);
|
dolibarr_install_syslog("upgrade: delete association sql=".$sql);
|
||||||
$resqld=$db->query($sql);
|
$resqld=$db->query($sql);
|
||||||
if ($resqld)
|
if ($resqld)
|
||||||
{
|
{
|
||||||
foreach($couples as $key => $val)
|
foreach($couples as $key => $val)
|
||||||
{
|
{
|
||||||
$sql ="INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
|
$sql ="INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
|
||||||
$sql.=" VALUES(".$val['mere'].", ".$val['fille'].")";
|
$sql.=" VALUES(".$val['mere'].", ".$val['fille'].")";
|
||||||
dolibarr_install_syslog("upgrade: insert association sql=".$sql);
|
dolibarr_install_syslog("upgrade: insert association sql=".$sql);
|
||||||
$resqli=$db->query($sql);
|
$resqli=$db->query($sql);
|
||||||
if (! $resqli) $error++;
|
if (! $resqli) $error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
print '<tr><td>'.$langs->trans("RemoveDuplicates").'</td>';
|
print '<tr><td>'.$langs->trans("RemoveDuplicates").'</td>';
|
||||||
print '<td align="right">'.$langs->trans("Success").' ('.$num.'=>'.count($couples).')</td></tr>';
|
print '<td align="right">'.$langs->trans("Success").' ('.$num.'=>'.count($couples).')</td></tr>';
|
||||||
$db->commit();
|
$db->commit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print '<tr><td>'.$langs->trans("RemoveDuplicates").'</td>';
|
print '<tr><td>'.$langs->trans("RemoveDuplicates").'</td>';
|
||||||
print '<td align="right">'.$langs->trans("Failed").'</td></tr>';
|
print '<td align="right">'.$langs->trans("Failed").'</td></tr>';
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print '<div class="error">'.$langs->trans("Error").'</div>';
|
print '<div class="error">'.$langs->trans("Error").'</div>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -232,7 +250,7 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
|
|||||||
*/
|
*/
|
||||||
if ($ok && preg_match('/mysql/',$db->type))
|
if ($ok && preg_match('/mysql/',$db->type))
|
||||||
{
|
{
|
||||||
$versioncommande=explode('.','4.0');
|
$versioncommande=array(4,0,0);
|
||||||
if (count($versioncommande) && count($versionarray)
|
if (count($versioncommande) && count($versionarray)
|
||||||
&& versioncompare($versioncommande,$versionarray) <= 0) // Si mysql >= 4.0
|
&& versioncompare($versioncommande,$versionarray) <= 0) // Si mysql >= 4.0
|
||||||
{
|
{
|
||||||
|
|||||||
@ -26,6 +26,7 @@ ErrorGoBackAndCorrectParameters=Go backward and correct wrong parameters.
|
|||||||
ErrorWrongValueForParameter=You may have typed a wrong value for parameter '%s'.
|
ErrorWrongValueForParameter=You may have typed a wrong value for parameter '%s'.
|
||||||
ErrorFailedToCreateDatabase=Failed to create database '%s'.
|
ErrorFailedToCreateDatabase=Failed to create database '%s'.
|
||||||
ErrorFailedToConnectToDatabase=Failed to connect to 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.
|
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.
|
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.
|
ErrorConnectedButDatabaseNotFound=Connection to server successfull but database '%s' not found.
|
||||||
|
|||||||
@ -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'.
|
ErrorWrongValueForParameter=Vous avez peut-être saisi une mauvaise valeur pour le paramètre '%s'.
|
||||||
ErrorFailedToCreateDatabase=Echec de création de la base '%s'.
|
ErrorFailedToCreateDatabase=Echec de création de la base '%s'.
|
||||||
ErrorFailedToConnectToDatabase=Echec de connexion à 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.
|
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.
|
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.
|
ErrorConnectedButDatabaseNotFound=Connexion au serveur réussi mais base '%s' introuvable.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user