add -s flag to skip CDR files that error out, RT#20763
[freeside.git] / FS / bin / freeside-cdr-sftp_and_import
index 9aacd67..722bf73 100755 (executable)
@@ -116,31 +116,39 @@ foreach my $filename ( @$ls ) {
   $import_options->{'cdrtypenum'} = $opt_c if $opt_c;
   
   my $error = FS::cdr::batch_import($import_options);
+
   if ( $error ) {
-    unlink "$cachedir/$filename";
-    unlink "$cachedir/$ungziped" if $opt_g;
-    die $error;
-  }
 
-  if ( $opt_d ) {
-    if($opt_m eq 'ftp') {
-      my $ftp = ftp();
-      $ftp->rename($filename, "$opt_d/$file_timestamp")
-        or do {
-          unlink "$cachedir/$filename";
-          unlink "$cachedir/$ungziped" if $opt_g;
-          die "Can't move $filename to $opt_d: ".$ftp->message . "\n";
-        };
+    if ( $opt_s ) {
+      warn "$ungzipped: $error\n";
+    } else {
+      unlink "$cachedir/$filename";
+      unlink "$cachedir/$ungziped" if $opt_g;
+      die $error;
     }
-    else {
-      my $sftp = sftp();
-      $sftp->rename($filename, "$opt_d/$file_timestamp")
-        or do {
-          unlink "$cachedir/$filename";
-          unlink "$cachedir/$ungziped" if $opt_g;
-          die "can't move $filename to $opt_d: ". $sftp->error . "\n";
-        };
+
+  } else {
+
+    if ( $opt_d ) {
+      if ( $opt_m eq 'ftp') {
+        my $ftp = ftp();
+        $ftp->rename($filename, "$opt_d/$file_timestamp")
+          or do {
+            unlink "$cachedir/$filename";
+            unlink "$cachedir/$ungziped" if $opt_g;
+            die "Can't move $filename to $opt_d: ".$ftp->message . "\n";
+          };
+      } else {
+        my $sftp = sftp();
+        $sftp->rename($filename, "$opt_d/$file_timestamp")
+          or do {
+            unlink "$cachedir/$filename";
+            unlink "$cachedir/$ungziped" if $opt_g;
+            die "can't move $filename to $opt_d: ". $sftp->error . "\n";
+          };
+      }
     }
+
   }
 
   unlink "$cachedir/$filename";