Installer suggest successive migrate choices when there is several version late.

This commit is contained in:
Laurent Destailleur 2009-08-14 00:30:43 +00:00
parent 4cd2c1ad9e
commit 3d32f8b29a
5 changed files with 66 additions and 23 deletions

View File

@ -336,8 +336,10 @@ else
);
$foundrecommandedchoice=0;
$count=0;
foreach ($migrationscript as $migarray)
{
$count++;
$versionfrom=$migarray['from'];
$versionto=$migarray['to'];
$newversionfrom=eregi_replace('\.[0-9]+$','.*',$versionfrom);
@ -351,8 +353,6 @@ else
{
$dolibarrversionfromarray=split('[\.-]',$versionfrom);
$dolibarrversiontoarray=split('[\.-]',$versionto);
// If last upgrade was an alpha or beta, we increase target version to 1 to select this one.
if (isset($conf->global->MAIN_VERSION_LAST_UPGRADE) && eregi('beta|alpha',$conf->global->MAIN_VERSION_LAST_UPGRADE)) $dolibarrversiontoarray[2]=(isset($dolibarrversiontoarray[2]) ? ($dolibarrversiontoarray[2]+1) : 1);
// Now we check if this is the first qualified choice
if ($allowupgrade && empty($foundrecommandedchoice) && versioncompare($dolibarrversiontoarray,$dolibarrlastupgradeversionarray) > 0)
{
@ -371,7 +371,8 @@ else
print '<td align="center">';
if ($allowupgrade)
{
print '<a href="upgrade.php?action=upgrade&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'">'.$langs->trans("Start").'</a>';
// If it's not last updagre script, action = upgrade_tmp, if last action = upgrade
print '<a href="upgrade.php?action=upgrade'.($count<sizeof($migrationscript)?'_'.$versionto:'').'&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'">'.$langs->trans("Start").'</a>';
}
else
{

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
@ -28,15 +28,21 @@
*/
include_once("./inc.php");
if (file_exists($conffile)) include_once($conffile);
require_once($dolibarr_main_document_root . "/lib/databases/".$dolibarr_main_db_type.".lib.php");
$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto');
$langs->setDefaultLang($setuplang);
// TODO Send value from migrate choice
$targetversion=DOL_VERSION;
if (isset($_REQUEST["targetversion"])) $targetversion=$_REQUEST["targetversion"];
// Define targetversion used to update MAIN_VERSION_LAST_INSTALL for first install
// or MAIN_VERSION_LAST_UPGRADE for upgrade.
$targetversion=DOL_VERSION; // It it's last upgrade
if (isset($_POST["action"]) && eregi('upgrade',$_POST["action"])) // If it's an old upgrade
{
$tmp=split('_',$_POST["action"],2);
if ($tmp[0]=='upgrade' && ! empty($tmp[1])) $targetversion=$tmp[1];
}
$langs->load("admin");
$langs->load("install");
@ -91,7 +97,7 @@ if ($_POST["action"] == "set")
pHeader($langs->trans("SetupEnd"),"etape5");
if ($_POST["action"] == "set" || $_POST["action"] == "upgrade")
if ($_POST["action"] == "set" || eregi('upgrade',$_POST["action"]))
{
print '<table cellspacing="0" cellpadding="2" width="100%">';
$error=0;
@ -111,6 +117,7 @@ if ($_POST["action"] == "set" || $_POST["action"] == "upgrade")
$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,$conf->db->port);
$ok = 0;
// If first install
@ -180,16 +187,42 @@ if ($_POST["action"] == "set" || $_POST["action"] == "upgrade")
}
else
{
print $langs->trans("Error")."<br>";
print $langs->trans("ErrorFailedToConnect")."<br>";
}
}
// If upgrade
elseif ($_POST["action"] == "upgrade")
elseif (eregi('upgrade',$_POST["action"]))
{
dolibarr_install_syslog('install/etape5.php set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion, LOG_DEBUG);
$db->query("DELETE FROM llx_const WHERE name='MAIN_VERSION_LAST_UPGRADE'");
$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values('MAIN_VERSION_LAST_UPGRADE','".$targetversion."','chaine',0,'Dolibarr version for last upgrade',0)");
$conf->global->MAIN_VERSION_LAST_UPGRADE=$targetversion;
if ($db->connected == 1)
{
$conf->setValues($db);
// Define if we need to update the MAIN_VERSION_LAST_UPGRADE value in database
$tagdatabase=false;
if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE)) $tagdatabase=true; // We don't know what it was before, so now we consider we are version choosed.
else
{
$mainversionlastupgradearray=split('[\.-]',$conf->global->MAIN_VERSION_LAST_UPGRADE);
$targetversionarray=split('[\.-]',$targetversion);
if (versioncompare($targetversionarray,$mainversionlastupgradearray) > 0) $tagdatabase=true;
}
if ($tagdatabase)
{
dolibarr_install_syslog('install/etape5.php set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion, LOG_DEBUG);
$db->query("DELETE FROM llx_const WHERE name='MAIN_VERSION_LAST_UPGRADE'");
$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values('MAIN_VERSION_LAST_UPGRADE','".$targetversion."','chaine',0,'Dolibarr version for last upgrade',0)");
$conf->global->MAIN_VERSION_LAST_UPGRADE=$targetversion;
}
else
{
dolibarr_install_syslog('install/etape5.php We run an upgrade to version '.$targetversion.' but database was already upgraded to '.$conf->global->MAIN_VERSION_LAST_UPGRADE.'. We keep MAIN_VERSION_LAST_UPGRADE as it is.', LOG_DEBUG);
}
}
else
{
print $langs->trans("ErrorFailedToConnect")."<br>";
}
}
else
{
@ -250,7 +283,7 @@ if ($_POST["action"] == "set")
}
}
// If upgrade
elseif ($_POST["action"] == "upgrade")
elseif (eregi('upgrade',$_POST["action"]))
{
if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION))
{

View File

@ -65,12 +65,12 @@ if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initial
* View
*/
pHeader('',"upgrade2","upgrade");
pHeader('',"upgrade2",$_REQUEST['action']);
$actiondone=0;
// Action to launch the repair or migrate script
if (! isset($_GET["action"]) || $_GET["action"] == "upgrade" || $_GET["action"] == "repair")
if (! isset($_GET["action"]) || eregi('upgrade',$_GET["action"]) || $_GET["action"] == "repair")
{
$actiondone=1;

View File

@ -65,10 +65,15 @@ dolibarr_install_syslog("upgrade2: Entering upgrade2.php page");
if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initialized",LOG_ERR);
pHeader('','etape5','upgrade');
/*
* Actions
*/
pHeader('','etape5',$_REQUEST["action"]);
if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
if (isset($_POST['action']) && eregi('upgrade',$_POST["action"]))
{
print '<h3>'.$langs->trans('DataMigration').'</h3>';

View File

@ -43,22 +43,26 @@ function versiontostring($versionarray)
* \brief Compare 2 versions
* \param versionarray1 Array of version (vermajor,verminor,patch)
* \param versionarray2 Array of version (vermajor,verminor,patch)
* \return int -3,-2,-1 if versionarray1<versionarray2 (value depends on level of difference)
* \return int -4,-3,-2,-1 if versionarray1<versionarray2 (value depends on level of difference)
* 0 if =
* 1,2,3 if versionarray1>versionarray2 (value depends on level of difference)
* 1,2,3,4 if versionarray1>versionarray2 (value depends on level of difference)
*/
function versioncompare($versionarray1,$versionarray2)
{
$ret=0;
$level=0;
while ($level < max(sizeof($versionarray1),sizeof($versionarray1)))
while ($level < max(sizeof($versionarray1),sizeof($versionarray2)))
{
$operande1=isset($versionarray1[$level])?$versionarray1[$level]:0;
$operande2=isset($versionarray2[$level])?$versionarray2[$level]:0;
if (eregi('beta|alpha',$operande1)) $operande1=-1;
if (eregi('beta|alpha',$operande2)) $operande2=-1;
$level++;
//print 'level '.$level.' '.$operande1.'-'.$operande2;
if ($operande1 < $operande2) { $ret = -$level; break; }
if ($operande1 > $operande2) { $ret = $level; break; }
}
//print join('.',$versionarray1).'('.sizeof($versionarray1).') / '.join('.',$versionarray2).'('.sizeof($versionarray2).') => '.$ret;
return $ret;
}