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,6 +146,8 @@ 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');
if ($handle)
{
dolibarr_syslog("Run command ".$fullcommandcrypted); dolibarr_syslog("Run command ".$fullcommandcrypted);
$handlein = popen($fullcommandclear, 'r'); $handlein = popen($fullcommandclear, 'r');
while (!feof($handlein)) while (!feof($handlein))
@ -148,15 +156,23 @@ if ($what == 'mysql')
fwrite($handle,$read); fwrite($handle,$read);
} }
pclose($handlein); pclose($handlein);
if ($compression == 'none') fclose($handle); if ($compression == 'none') fclose($handle);
if ($compression == 'gz') gzclose($handle); if ($compression == 'gz') gzclose($handle);
if ($compression == 'bz') bzclose($handle); if ($compression == 'bz') bzclose($handle);
}
else
{
dolibarr_syslog("Failed to open file $outputfile",LOG_ERR);
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
}
// 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');
if ($hanlde)
{
$errormsg = fgets($handle,10); $errormsg = fgets($handle,10);
if ($compression == 'none') fclose($handle); if ($compression == 'none') fclose($handle);
if ($compression == 'gz') gzclose($handle); if ($compression == 'gz') gzclose($handle);
@ -171,6 +187,7 @@ if ($what == 'mysql')
// Si safe_mode on et command hors du parametre exec, on a un fichier out donc errormsg vide // Si safe_mode on et command hors du parametre exec, on a un fichier out donc errormsg vide
if (! $errormsg) $errormsg=$langs->trans("ErrorFailedToRunExternalCommand"); if (! $errormsg) $errormsg=$langs->trans("ErrorFailedToRunExternalCommand");
} }
}
// Fin execution commande // Fin execution commande
} }