From 6fc0d2f03e268ec5640b2e747142ee79c7c2ff0b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Jun 2007 19:20:38 +0000 Subject: [PATCH] =?UTF-8?q?Supprime=20les=20contraintes=20en=20doublons=20?= =?UTF-8?q?(vieilles=20contraintes=20non=20nomm=E9es)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/install/upgrade.php | 56 ++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 973871c0f0b..ae3aae6c142 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -130,33 +130,49 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") //print ''.join('.',$versionarray).''; } - - // Suppression vieilles contraintes sans noms et en doubles - // Les contraintes indesirables ont un nom qui commence par 0_ ou se termine par ibfk_999 - $listtables=array('llx_product_fournisseur_price','llx_fichinter','llx_facture_fourn','llx_propal','llx_socpeople','llx_telephonie_adsl_fournisseur','llx_telephonie_client_stats','llx_telephonie_contact_facture','llx_telephonie_societe_ligne','llx_telephonie_tarif_client'); - foreach ($listtables as $val) + if ($ok) { - $sql = "SHOW CREATE TABLE ".$val; - $resql = $db->query($sql); - if (! $resql) dolibarr_print_error($db); + $versioncommande=split('\.','4.0'); + if (sizeof($versioncommande) && sizeof($versionarray) + && versioncompare($versioncommande,$versionarray) <= 0) // Si mysql >= 4.0 { - $values=$db->fetch_array($resql); - $i=0; - $createsql=$values[1]; - while (eregi('CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`',$createsql,$reg) && $i < 100) + // Suppression vieilles contraintes sans noms et en doubles + // Les contraintes indesirables ont un nom qui commence par 0_ ou se termine par ibfk_999 + $listtables=array( 'llx_product_fournisseur_price', + 'llx_fichinter', + 'llx_facture_fourn', + 'llx_propal', + 'llx_socpeople', + 'llx_telephonie_adsl_fournisseur', + 'llx_telephonie_client_stats', + 'llx_telephonie_contact_facture', + 'llx_telephonie_societe_ligne', + 'llx_telephonie_tarif_client'); + foreach ($listtables as $val) { - $sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1]; - $resqldrop = $db->query($sqldrop); - if ($resqldrop) + $sql = "SHOW CREATE TABLE ".$val; + $resql = $db->query($sql); + if (! $resql) dolibarr_print_error($db); { - print ''.$sqldrop.";\n"; + $values=$db->fetch_array($resql); + $i=0; + $createsql=$values[1]; + while (eregi('CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`',$createsql,$reg) && $i < 100) + { + $sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1]; + $resqldrop = $db->query($sqldrop); + if ($resqldrop) + { + print ''.$sqldrop.";\n"; + } + $createsql=eregi_replace('CONSTRAINT `'.$reg[1].'`','XXX',$createsql); + $i++; + } + $db->free($resql); } - $createsql=eregi_replace('CONSTRAINT `'.$reg[1].'`','XXX',$createsql); - $i++; + } - $db->free($resql); } - }