projects
/
freeside.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a6df3be
)
add datestamp to batch name derived from filename, remove temp files for all errors...
author
ivan
<ivan>
Thu, 22 Sep 2011 00:26:12 +0000
(
00:26
+0000)
committer
ivan
<ivan>
Thu, 22 Sep 2011 00:26:12 +0000
(
00:26
+0000)
FS/bin/freeside-cdr-sftp_and_import
patch
|
blob
|
history
diff --git
a/FS/bin/freeside-cdr-sftp_and_import
b/FS/bin/freeside-cdr-sftp_and_import
index
1d052ea
..
d28a63c
100755
(executable)
--- 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 strict;
use Getopt::Std;
+use Date::Format;
use Net::SFTP::Foreign::Compat;
use Net::FTP;
use FS::UID qw(adminsuidsetup datasrc);
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,
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);
'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")
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")
}
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;
sub ftp {
return $ftp if $ftp && $ftp->pwd;
- my ($hostname, $user) = reverse split('@', $servername);
- my ($
user, $pass) = split(':', $user
);
+ my ($hostname, $user
pass
) = reverse split('@', $servername);
+ my ($
ftp_user, $ftp_pass) = split(':', $userpass
);
my $ftp = Net::FTP->new($hostname, %options)
or die "FTP connection to '$hostname' failed.";
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;
}
$ftp->cwd($opt_r) or die "can't chdir to $opt_r\n" if $opt_r;
return $ftp;
}