diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 3a0800ed771..973871c0f0b 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -131,6 +131,34 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") } + // 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) + { + $sql = "SHOW CREATE TABLE ".$val; + $resql = $db->query($sql); + if (! $resql) dolibarr_print_error($db); + { + $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 '