From 3566ef2692ffbef673f32abad6e352461258cafc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Jun 2006 00:58:51 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Possibilit=E9=20d'imposer=20la=20version?= =?UTF-8?q?=20minimale=20de=20la=20base=20dans=20les=20scripts=20de=20migr?= =?UTF-8?q?ation=20ou=20.sql.=20Pour=20cela=20il=20faut=20mettre=20devant?= =?UTF-8?q?=20l'ordre=20sql,=20la=20sequence=20--Vx.x=20pour=20executer=20?= =?UTF-8?q?l'ordre=20SQL=20uniquement=20si=20base=20en=20version=20x.x=20o?= =?UTF-8?q?u=20superieur.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/install/etape2.php | 19 +++++++++++------ htdocs/install/inc.php | 30 +++++++++++++++++++++++++-- htdocs/install/upgrade.php | 36 +++++++++++++++++++++++++++++---- htdocs/lib/functions.inc.php | 2 +- htdocs/lib/mysql.lib.php | 10 +++++++++ htdocs/lib/pgsql.lib.php | 11 ++++++++++ mysql/migration/2.0.0-2.1.0.sql | 8 ++++---- 7 files changed, 99 insertions(+), 17 deletions(-) diff --git a/htdocs/install/etape2.php b/htdocs/install/etape2.php index 3d04c1df976..6d3498f8a4b 100644 --- a/htdocs/install/etape2.php +++ b/htdocs/install/etape2.php @@ -112,8 +112,10 @@ if ($_POST["action"] == "set") if ($ok) { $version=$db->getVersion(); - print ''; - print $langs->trans("DatabaseVersion").''.$version.''; + $versionarray=$db->getVersionArray(); + print ''.$langs->trans("DatabaseVersion").''; + print ''.$version.''; + //print ''.join('.',$versionarray).''; } /************************************************************************************** @@ -213,12 +215,17 @@ if ($_POST["action"] == "set") $buf = fgets($fp, 4096); // Cas special de lignes autorisees pour certaines versions uniquement - if (eregi('^-- V([0-9]+)',$buf,$reg)) + if (eregi('^-- V([0-9\.]+)',$buf,$reg)) { - if ($reg[1] && $reg[1] <= $version) + $versioncommande=split('\.',$reg[1]); + //print var_dump($versioncommande); + //print var_dump($versionarray); + if (sizeof($versioncommande) && sizeof($versionarray) + && versioncompare($versioncommande,$versionarray) <= 0) { - $buf=eregi_replace('^-- V([0-9]+)','',$buf); - //print $buf.'
'; + // Version qualified, delete SQL comments + $buf=eregi_replace('^-- V([0-9\.]+)','',$buf); + //print "Ligne $i qualifiée par version: ".$buf.'
'; } } diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index b878a8a4eae..1f0fe410be6 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -26,6 +26,9 @@ \version $Revision$ */ +require_once('../translate.class.php'); + + // Forcage du parametrage PHP magic_quots_gpc (Sinon il faudrait a chaque POST, conditionner // la lecture de variable par stripslashes selon etat de get_magic_quotes). // En mode off (recommande il faut juste faire addslashes au moment d'un insert/update. @@ -45,9 +48,8 @@ if (get_magic_quotes_gpc()) $docurl = 'documentation'; $conffile = "../conf/conf.php"; -// Defini objet langs -require_once('../translate.class.php'); +// Defini objet langs $langs = new Translate('../langs'); $langs->setDefaultLang('auto'); $langs->setPhpLang(); @@ -103,6 +105,7 @@ function pFooter($nonext=0,$setuplang='') print ''; } + function dolibarr_syslog($message) { // Les fonctions syslog ne sont pas toujours installè± ou autoris褳 chez les hè¡¥rgeurs @@ -117,4 +120,27 @@ function dolibarr_syslog($message) // } } } + + +/** + \brief Compare 2 versions + \param versionarray1 Tableau de version (vermajeur,vermineur,autre) + \param versionarray2 Tableau de version (vermajeur,vermineur,autre) + \return int <0 si versionarray10 si versionarray1>versionarray2 +*/ +function versioncompare($versionarray1,$versionarray2) +{ + $ret=0; + $i=0; + while ($i < max(sizeof($versionarray1),sizeof($versionarray1))) + { + $operande1=isset($versionarray1[$i])?$versionarray1[$i]:0; + $operande2=isset($versionarray2[$i])?$versionarray2[$i]:0; + if ($operande1 < $operande2) { $ret = -1; break; } + if ($operande1 > $operande2) { $ret = 1; break; } + $i++; + } + return $ret; +} + ?> \ No newline at end of file diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 9f290ae039c..dcc760e7b22 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -103,7 +103,6 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") { if($db->database_selected == 1) { - dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name"); } else @@ -112,6 +111,17 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") } } + // Affiche version + if ($ok) + { + $version=$db->getVersion(); + $versionarray=$db->getVersionArray(); + print ''.$langs->trans("DatabaseVersion").''; + print ''.$version.''; + //print ''.join('.',$versionarray).''; + } + + /*************************************************************************************** * @@ -141,9 +151,27 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") while (!feof ($fp)) { $buf = fgets($fp, 4096); - $buf = ereg_replace('--(.*)','',$buf); // Delete SQL comments - //print $buf.'
'; - $buffer .= $buf; + + // Cas special de lignes autorisees pour certaines versions uniquement + if (eregi('^-- V([0-9\.]+)',$buf,$reg)) + { + $versioncommande=split('\.',$reg[1]); + //print var_dump($versioncommande); + //print var_dump($versionarray); + if (sizeof($versioncommande) && sizeof($versionarray) + && versioncompare($versioncommande,$versionarray) <= 0) + { + // Version qualified, delete SQL comments + $buf=eregi_replace('^-- V([0-9\.]+)','',$buf); + //print "Ligne $i qualifiée par version: ".$buf.'
'; + } + } + + // Ajout ligne si non commentaire + if (! eregi('^--',$buf)) $buffer .= $buf; + +// print $buf.'
'; + if (eregi(';',$buffer)) { // Found new request diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 065ba484649..f8e23c0cfdb 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -57,7 +57,7 @@ function versiontostring($versionarray) \brief Compare 2 versions \param versionarray1 Tableau de version (vermajeur,vermineur,autre) \param versionarray2 Tableau de version (vermajeur,vermineur,autre) - \return int <0 si versionarray1>versionarray2, 0 si =, >0 si versionarray1>versionarray2 + \return int <0 si versionarray10 si versionarray1>versionarray2 */ function versioncompare($versionarray1,$versionarray2) { diff --git a/htdocs/lib/mysql.lib.php b/htdocs/lib/mysql.lib.php index 90985eca035..36add016016 100644 --- a/htdocs/lib/mysql.lib.php +++ b/htdocs/lib/mysql.lib.php @@ -206,6 +206,16 @@ class DoliDb } + /** + \brief Renvoie la version du serveur dans un tableau + \return array Tableau de chaque niveau de version + */ + function getVersionArray() + { + return split('\.',$this->getVersion()); + } + + /** \brief Renvoie l'id de la connection \return string Id connection diff --git a/htdocs/lib/pgsql.lib.php b/htdocs/lib/pgsql.lib.php index 92a35c61e58..fe4899db1c0 100644 --- a/htdocs/lib/pgsql.lib.php +++ b/htdocs/lib/pgsql.lib.php @@ -177,6 +177,17 @@ class DoliDb { return '?'; } + + + /** + \brief Renvoie la version du serveur dans un tableau + \return array Tableau de chaque niveau de version + */ + function getVersionArray() + { + return split('\.',$this->getVersion()); + } + /** diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index 57be9e09ca3..25babcbfc8c 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -1,9 +1,9 @@ -- $Revision$ -- --- Attention à l ordre des requetes --- ce fichier doit être chargé sur une version 2.0.0 +-- Attention à l ordre des requetes. +-- Ce fichier doit être chargé sur une version 2.0.0 -- sans AUCUNE erreur ni warning --- +-- create table llx_paiementfourn_facturefourn @@ -290,7 +290,7 @@ alter table llx_accountingsystem_det rename to llx_accountingaccount; insert into llx_rights_def (id, libelle, module, type, bydefault, subperms, perms) values (262,'Consulter tous les clients','commercial','r',1,'voir','client'); -insert into llx_user_rights(fk_user,fk_id) select distinct fk_user, '262' from llx_user_rights where fk_id = 261; +-- V4.1 insert into llx_user_rights(fk_user,fk_id) select distinct fk_user, '262' from llx_user_rights where fk_id = 261; update llx_rights_def set subperms='creer' where subperms='supprimer' AND module='user' AND perms='self' AND id=255; alter table llx_commandedet add column rang integer DEFAULT 0;