Amélioration gestion erreur

This commit is contained in:
Laurent Destailleur 2006-11-30 07:17:37 +00:00
parent 635435f10e
commit 59ec5e72d3
2 changed files with 38 additions and 29 deletions

View File

@ -51,11 +51,13 @@ else if ($_POST["action"] == 'multiprix_num')
if ($_POST["action"] == 'multiprix') if ($_POST["action"] == 'multiprix')
{ {
$res=$db->DDLDescTable(MAIN_DB_PREFIX."societe","price_level"); $res=$db->DDLDescTable(MAIN_DB_PREFIX."societe","price_level");
if(! $db->fetch_row()) if(! $db->fetch_row($res))
{ {
$field_desc = array('type'=>'TINYINT','value'=>'4','default'=>'1'); $field_desc = array('type'=>'TINYINT','value'=>'4','default'=>'1');
if ($_POST["activate_multiprix"])
{
// on ajoute le champ price_level dans la table societe // on ajoute le champ price_level dans la table societe
if(! $db->DDLAddField(MAIN_DB_PREFIX."societe","price_level",$field_desc)) if ($db->DDLAddField(MAIN_DB_PREFIX."societe","price_level",$field_desc) < 0)
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
exit; exit;
@ -70,31 +72,31 @@ if ($_POST["action"] == 'multiprix')
$fields['datec'] = array('type'=>'datetime','default'=> 'null'); $fields['datec'] = array('type'=>'datetime','default'=> 'null');
$fields['fk_user_author'] = array('type'=>'int','value'=>'11','default'=> 'null'); $fields['fk_user_author'] = array('type'=>'int','value'=>'11','default'=> 'null');
$fields['price_level'] = array('type'=>'tinyint','value'=>'4','default'=> '1'); $fields['price_level'] = array('type'=>'tinyint','value'=>'4','default'=> '1');
if(! $db->DDLCreateTable($table,$fields,"rowid","InnoDB") > 0) if ($db->DDLCreateTable($table,$fields,"rowid","InnoDB") < 0)
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
print "<script language='JavaScript'>setTimeout(\"document.location='./produit.php'\",5000);</script>";
}
else
{
dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"]);
dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6");
Header("Location: produit.php");
}
}
}
else
{
dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"]);
dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6");
Header("Location: produit.php");
}
exit; exit;
}
}
}
dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"]);
dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6");
Header("Location: produit.php");
exit;
}
else
{
dolibarr_syslog("Table definition for ".MAIN_DB_PREFIX."societe already ok");
dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"]);
dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6");
Header("Location: produit.php");
exit;
}
} }
else if ($_POST["action"] == 'sousproduits') else if ($_POST["action"] == 'sousproduits')
{ {
$res=$db->DDLDescTable(MAIN_DB_PREFIX."product_association"); $res=$db->DDLDescTable(MAIN_DB_PREFIX."product_association");
if(! $db->fetch_row()) if(! $db->fetch_row($res))
{ {
$table = MAIN_DB_PREFIX."product_association"; $table = MAIN_DB_PREFIX."product_association";
$fields['fk_product_pere'] = array('type'=>'int','value'=>'11','null'=> 'not null','default'=> '0'); $fields['fk_product_pere'] = array('type'=>'int','value'=>'11','null'=> 'not null','default'=> '0');
@ -102,21 +104,24 @@ else if ($_POST["action"] == 'sousproduits')
$fields['qty'] = array('type'=>'double','default'=> 'null'); $fields['qty'] = array('type'=>'double','default'=> 'null');
$keys['idx_product_association_fk_product_pere'] = "fk_product_pere" ; $keys['idx_product_association_fk_product_pere'] = "fk_product_pere" ;
$keys['idx_product_association_fk_product_fils'] = "fk_product_fils" ; $keys['idx_product_association_fk_product_fils'] = "fk_product_fils" ;
if (! $db->DDLCreateTable($table,$fields,"","InnoDB","","",$keys) > 0) if ($db->DDLCreateTable($table,$fields,"","InnoDB","","",$keys) < 0)
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
print "<script language='JavaScript'>setTimeout(\"document.location='./produit.php'\",5000);</script>"; exit;
} }
else else
{ {
dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"]); dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"]);
Header("Location: produit.php"); Header("Location: produit.php");
exit;
} }
} }
else else
{ {
dolibarr_syslog("Table definition already ok");
dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"]); dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"]);
Header("Location: produit.php"); Header("Location: produit.php");
exit;
} }
} }
else if ($_POST["action"] == 'changeproductdesc') else if ($_POST["action"] == 'changeproductdesc')

View File

@ -126,12 +126,13 @@ if ($what == 'mysql')
print $langs->trans("BackupResult").': '; print $langs->trans("BackupResult").': ';
// Debut appel methode execution // Debut appel methode execution
$fullcommand=$command." ".$param." 2>&1"; $fullcommand=$command." ".$param." 2>&1";
if ($compression == 'none') $handle = fopen($outputfile, 'w'); if ($compression == 'none') $handle = fopen($outputfile, 'w');
if ($compression == 'gz') $handle = gzopen($outputfile, 'w'); if ($compression == 'gz') $handle = gzopen($outputfile, 'w');
if ($compression == 'bz') $handle = bzopen($outputfile, 'w'); if ($compression == 'bz') $handle = bzopen($outputfile, 'w');
dolibarr_syslog("Run command ".$fullcommand);
$handlein = popen($fullcommand, 'r'); $handlein = popen($fullcommand, 'r');
while (!feof($handlein)) while (!feof($handlein))
{ {
@ -158,7 +159,10 @@ if ($what == 'mysql')
{ {
// Renommer fichier sortie en fichier erreur // Renommer fichier sortie en fichier erreur
//print "$outputfile -> $outputerror"; //print "$outputfile -> $outputerror";
dol_delete_file($outputerror);
@rename($outputfile,$outputerror); @rename($outputfile,$outputerror);
// Si safe_mode on et command hors du parametre exec, on a un fichier out donc errormsg vide
if (! $errormsg) $errormsg=$langs->trans("ErrorFailedToRunCommand");
} }
// Fin execution commande // Fin execution commande