From c673787bf1ac56408e589ed20ea63404e9181574 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 15 Nov 2012 13:50:11 -0800 Subject: [PATCH] better error handling when sending a spool by email, #17620 --- FS/FS/Cron/upload.pm | 23 +++++++++++++++++++---- FS/FS/Misc.pm | 1 + FS/FS/upload_target.pm | 7 ------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/FS/FS/Cron/upload.pm b/FS/FS/Cron/upload.pm index a9094c0b0..08819fce9 100644 --- a/FS/FS/Cron/upload.pm +++ b/FS/FS/Cron/upload.pm @@ -318,7 +318,13 @@ sub spool_upload { system($command) and die "$command failed\n"; my $error = $upload_target->put($zipfile); - die $error if $error; + if ( $error ) { + foreach ( qw ( header detail ) ) { + rename "$dir/$file-$date-$_.csv", + "$dir/$file-$_.csv"; + die $error; + } + } send_report('bridgestone-confirm_template', { @@ -373,7 +379,7 @@ sub spool_upload { my $zipfile = "$basename" . '.zip'; my $command = "cd $dir; zip $zipfile $regfile $bigfile"; system($command) and die "'$command' failed\n"; - $upload_target->put("$dir/$zipfile"); + my $error = $upload_target->put("$dir/$zipfile"); for (values %sum) { $_ = sprintf('%.2f', $_); @@ -384,15 +390,24 @@ sub spool_upload { agentnum => $agentnum, count => \%count, sum => \%sum, + error => $error, } ); + + if ( $error ) { + rename "$dir/$file-$date.csv", "$dir/$file.csv"; + die $error; + } - } else { # not bridgestone or ics + } else { # not bridgestone or ics # this is the usual case my $error = $upload_target->put("$file-$date.csv"); - die $error if $error; + if ( $error ) { + rename "$dir/$file-$date.csv", "$dir/$file.csv"; + die $error; + } } diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index a1c15fdf8..096ec8a4c 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -274,6 +274,7 @@ sub send_email { }); $cust_msg->insert; # ignore errors } + $error; } diff --git a/FS/FS/upload_target.pm b/FS/FS/upload_target.pm index 8466a6229..f3486d393 100644 --- a/FS/FS/upload_target.pm +++ b/FS/FS/upload_target.pm @@ -182,13 +182,6 @@ sub put { } } - - - - - - - =item connect Creates a Net::FTP or Net::SFTP::Foreign object (according to the setting -- 2.11.0