Fix: Gestion erreur

This commit is contained in:
Laurent Destailleur 2007-11-09 02:43:44 +00:00
parent 096eca502c
commit 7a2bf7a5ef

View File

@ -118,11 +118,13 @@ if ($what == 'mysql')
$paramcrypted=$param." -p".eregi_replace('.','*',$dolibarr_main_db_pass); $paramcrypted=$param." -p".eregi_replace('.','*',$dolibarr_main_db_pass);
$paramclear=$param." -p".$dolibarr_main_db_pass; $paramclear=$param." -p".$dolibarr_main_db_pass;
$relativepathfile='/admin/temp/'.$file; $relativepathdir='/admin/temp';
$relativepathfile=$relativepathdir.'/'.$file;
// for compression format, we add extension // for compression format, we add extension
if ($compression == 'gz') $relativepathfile.='.gz'; if ($compression == 'gz') $relativepathfile.='.gz';
if ($compression == 'bz') $relativepathfile.='.bz2'; if ($compression == 'bz') $relativepathfile.='.bz2';
$relativepatherr=$relativepathfile.'.err'; $relativepatherr=$relativepathfile.'.err';
$outputdir=DOL_DATA_ROOT.$relativepathdir;
$outputfile=DOL_DATA_ROOT.$relativepathfile; $outputfile=DOL_DATA_ROOT.$relativepathfile;
$outputerror=DOL_DATA_ROOT.$relativepatherr; $outputerror=DOL_DATA_ROOT.$relativepatherr;
@ -133,6 +135,10 @@ if ($what == 'mysql')
print $langs->trans("BackupResult").': '; print $langs->trans("BackupResult").': ';
$errormsg='';
$result=create_exdir($outputdir);
// Debut appel methode execution // Debut appel methode execution
$fullcommandcrypted=$command." ".$paramcrypted." 2>&1"; $fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
$fullcommandclear=$command." ".$paramclear." 2>&1"; $fullcommandclear=$command." ".$paramclear." 2>&1";
@ -140,36 +146,47 @@ if ($what == 'mysql')
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 ".$fullcommandcrypted); if ($handle)
$handlein = popen($fullcommandclear, 'r');
while (!feof($handlein))
{ {
$read = fgets($handlein); dolibarr_syslog("Run command ".$fullcommandcrypted);
fwrite($handle,$read); $handlein = popen($fullcommandclear, 'r');
while (!feof($handlein))
{
$read = fgets($handlein);
fwrite($handle,$read);
}
pclose($handlein);
if ($compression == 'none') fclose($handle);
if ($compression == 'gz') gzclose($handle);
if ($compression == 'bz') bzclose($handle);
}
else
{
dolibarr_syslog("Failed to open file $outputfile",LOG_ERR);
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
} }
pclose($handlein);
if ($compression == 'none') fclose($handle);
if ($compression == 'gz') gzclose($handle);
if ($compression == 'bz') bzclose($handle);
// Get errorstring // Get errorstring
$errormsg='';
if ($compression == 'none') $handle = fopen($outputfile, 'r'); if ($compression == 'none') $handle = fopen($outputfile, 'r');
if ($compression == 'gz') $handle = gzopen($outputfile, 'r'); if ($compression == 'gz') $handle = gzopen($outputfile, 'r');
if ($compression == 'bz') $handle = bzopen($outputfile, 'r'); if ($compression == 'bz') $handle = bzopen($outputfile, 'r');
$errormsg = fgets($handle,10); if ($hanlde)
if ($compression == 'none') fclose($handle);
if ($compression == 'gz') gzclose($handle);
if ($compression == 'bz') bzclose($handle);
if (eregi('^-- MySql',$errormsg)) $errormsg=''; // Pas erreur
else
{ {
// Renommer fichier sortie en fichier erreur $errormsg = fgets($handle,10);
//print "$outputfile -> $outputerror"; if ($compression == 'none') fclose($handle);
dol_delete_file($outputerror); if ($compression == 'gz') gzclose($handle);
@rename($outputfile,$outputerror); if ($compression == 'bz') bzclose($handle);
// Si safe_mode on et command hors du parametre exec, on a un fichier out donc errormsg vide if (eregi('^-- MySql',$errormsg)) $errormsg=''; // Pas erreur
if (! $errormsg) $errormsg=$langs->trans("ErrorFailedToRunExternalCommand"); else
{
// Renommer fichier sortie en fichier erreur
//print "$outputfile -> $outputerror";
dol_delete_file($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("ErrorFailedToRunExternalCommand");
}
} }
// Fin execution commande // Fin execution commande