summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2011-09-22 00:26:12 +0000
committerivan <ivan>2011-09-22 00:26:12 +0000
commit1c2e93cb1f48747a070894391aa3cffd24d583b7 (patch)
tree1a67c4d02430df2e3079f4a3ca86e6324c8ff27b
parenta6df3bedc91aba52e5010241f1b94a780d478b5c (diff)
add datestamp to batch name derived from filename, remove temp files for all errors that abort processing, RT#14385
-rwxr-xr-xFS/bin/freeside-cdr-sftp_and_import27
1 files changed, 20 insertions, 7 deletions
diff --git a/FS/bin/freeside-cdr-sftp_and_import b/FS/bin/freeside-cdr-sftp_and_import
index 1d052ea5c..d28a63c06 100755
--- a/FS/bin/freeside-cdr-sftp_and_import
+++ b/FS/bin/freeside-cdr-sftp_and_import
@@ -2,6 +2,7 @@
use strict;
use Getopt::Std;
+use Date::Format;
use Net::SFTP::Foreign::Compat;
use Net::FTP;
use FS::UID qw(adminsuidsetup datasrc);
@@ -107,24 +108,36 @@ foreach my $filename ( @$ls ) {
my $import_options = {
'file' => "$cachedir/$ungziped",
'format' => $format,
- 'batch_namevalue' => $filename,
+ 'batch_namevalue' => $filename.'-'.str2time('%Y-%m-%d'),
'empty_ok' => 1,
};
$import_options->{'cdrtypenum'} = $opt_c if $opt_c;
my $error = FS::cdr::batch_import($import_options);
- die $error if $error;
+ 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/$filename")
- or die "Can't move $filename to $opt_d: ".$ftp->message . "\n";
+ 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/$filename")
- or die "can't move $filename to $opt_d: ". $sftp->error . "\n";
+ or do {
+ unlink "$cachedir/$filename";
+ unlink "$cachedir/$ungziped" if $opt_g;
+ die "can't move $filename to $opt_d: ". $sftp->error . "\n";
+ };
}
}
@@ -146,12 +159,12 @@ use vars qw( $sftp $ftp );
sub ftp {
return $ftp if $ftp && $ftp->pwd;
- my ($hostname, $user) = reverse split('@', $servername);
- my ($user, $pass) = split(':', $user);
+ my ($hostname, $userpass) = reverse split('@', $servername);
+ my ($ftp_user, $ftp_pass) = split(':', $userpass);
my $ftp = Net::FTP->new($hostname, %options)
or die "FTP connection to '$hostname' failed.";
- $ftp->login($user, $pass) or die "FTP login failed: ".$ftp->message;
+ $ftp->login($ftp_user, $ftp_pass) or die "FTP login failed: ".$ftp->message;
$ftp->cwd($opt_r) or die "can't chdir to $opt_r\n" if $opt_r;
return $ftp;
}