better error handling when sending a spool by email, #17620
authorMark Wells <mark@freeside.biz>
Thu, 15 Nov 2012 21:50:11 +0000 (13:50 -0800)
committerMark Wells <mark@freeside.biz>
Thu, 15 Nov 2012 21:50:30 +0000 (13:50 -0800)
FS/FS/Cron/upload.pm
FS/FS/Misc.pm
FS/FS/upload_target.pm

index a9094c0..08819fc 100644 (file)
@@ -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;
+      }
 
     }
 
index a1c15fd..096ec8a 100644 (file)
@@ -274,6 +274,7 @@ sub send_email {
     });
     $cust_msg->insert; # ignore errors
   }
+  $error;
    
 }
 
index 8466a62..f3486d3 100644 (file)
@@ -182,13 +182,6 @@ sub put {
   }
 }
 
-
-
-
-
-
-
-
 =item connect
 
 Creates a Net::FTP or Net::SFTP::Foreign object (according to the setting