diff --git a/htdocs/install/check.php b/htdocs/install/check.php
index ff0462e6545..cb5847cffc0 100644
--- a/htdocs/install/check.php
+++ b/htdocs/install/check.php
@@ -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 '
';
if ($allowupgrade)
{
- print ''.$langs->trans("Start").'';
+ // If it's not last updagre script, action = upgrade_tmp, if last action = upgrade
+ print ''.$langs->trans("Start").'';
}
else
{
diff --git a/htdocs/install/etape5.php b/htdocs/install/etape5.php
index d907c418c22..067b09e21d1 100644
--- a/htdocs/install/etape5.php
+++ b/htdocs/install/etape5.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2004-2008 Laurent Destailleur
+ * Copyright (C) 2004-2009 Laurent Destailleur
* Copyright (C) 2004 Benoit Mortier
* Copyright (C) 2004 Sebastien DiCintio
* Copyright (C) 2005-2009 Regis Houssin
@@ -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 '';
$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")." ";
+ print $langs->trans("ErrorFailedToConnect")." ";
}
}
// 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")." ";
+ }
}
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))
{
diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php
index 1e7b92c3b1c..c38608e1f4c 100644
--- a/htdocs/install/upgrade.php
+++ b/htdocs/install/upgrade.php
@@ -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;
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index cc10370a473..af0a578eac5 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -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 ''.$langs->trans('DataMigration').'';
diff --git a/htdocs/lib/admin.lib.php b/htdocs/lib/admin.lib.php
index d4e43a6ab3d..c59c1e4594d 100644
--- a/htdocs/lib/admin.lib.php
+++ b/htdocs/lib/admin.lib.php
@@ -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 versionarray1versionarray2 (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;
}
|