Fix: DDL changes must be on install, upgrade or module activation.

This commit is contained in:
Laurent Destailleur 2010-04-30 18:39:21 +00:00
parent 7e46e5bf54
commit 7236e28289

View File

@ -50,55 +50,12 @@ else if ($_POST["action"] == 'multiprix_num')
} }
if ($_POST["action"] == 'multiprix') if ($_POST["action"] == 'multiprix')
{ {
$res=$db->DDLDescTable(MAIN_DB_PREFIX."societe","price_level"); dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"],'chaine',0,'',$conf->entity);
if(! $db->fetch_row($res)) dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "5",'chaine',0,'',$conf->entity);
{
$field_desc = array('type'=>'TINYINT','value'=>'4','default'=>'1');
if ($_POST["activate_multiprix"])
{
// on ajoute le champ price_level dans la table societe
if ($db->DDLAddField(MAIN_DB_PREFIX."societe","price_level",$field_desc) < 0)
{
dol_print_error($db);
exit;
}
}
dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "5",'chaine',0,'',$conf->entity);
}
else
{
dol_syslog("Table definition for ".MAIN_DB_PREFIX."societe already ok");
dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "5",'chaine',0,'',$conf->entity);
}
} }
else if ($_POST["action"] == 'sousproduits') else if ($_POST["action"] == 'sousproduits')
{ {
$res=$db->DDLDescTable(MAIN_DB_PREFIX."product_association"); dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"],'chaine',0,'',$conf->entity);
if(! $db->fetch_row($res))
{
$table = MAIN_DB_PREFIX."product_association";
$fields['fk_product_pere'] = array('type'=>'int','value'=>'11','null'=> 'not null','default'=> '0');
$fields['fk_product_fils'] = array('type'=>'int','value'=>'11','null'=> 'not null','default'=> '0');
$fields['qty'] = array('type'=>'double','default'=> 'null');
$keys['idx_product_association_fk_product_pere'] = "fk_product_pere" ;
$keys['idx_product_association_fk_product_fils'] = "fk_product_fils" ;
if ($db->DDLCreateTable($table,$fields,"","InnoDB","","",$keys) < 0)
{
dol_print_error($db);
exit;
}
else
{
dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"],'chaine',0,'',$conf->entity);
}
}
else
{
dol_syslog("Table definition already ok");
dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"],'chaine',0,'',$conf->entity);
}
} }
else if ($_POST["action"] == 'viewProdDescInForm') else if ($_POST["action"] == 'viewProdDescInForm')
{ {