diff options
author | ivan <ivan> | 2010-08-25 09:25:56 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-08-25 09:25:56 +0000 |
commit | 678a99d01de1bd98dd49110d3862d173918fc9b8 (patch) | |
tree | fab1645414fbca952012bed22973ae61d1bc81bc /FS | |
parent | b731fd6e97ffc88d9ab7826a1d0ae5ccf1ba3d6c (diff) |
roll back the import transaction on fatal parsing errors on CDR import, so the cdr_batch record gets removed and db doesn't throw a dup key error, RT#9135
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Record.pm | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 71cc69ca9..6b05d2dac 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -1871,7 +1871,13 @@ sub batch_import { while ( scalar(@later) ) { my $sub = shift @later; my $data = shift @later; - &{$sub}($record, $data, $conf, $param); # $record->&{$sub}($data, $conf); + eval { + &{$sub}($record, $data, $conf, $param); # $record->&{$sub}($data, $conf) + }; + if ( $@ ) { + $dbh->rollback if $oldAutoCommit; + return "can't insert record". ( $line ? " for $line" : '' ). ": $@"; + } last if exists( $param->{skiprow} ); } next if exists( $param->{skiprow} ); @@ -1902,9 +1908,12 @@ sub batch_import { } - $dbh->commit or die $dbh->errstr if $oldAutoCommit;; + unless ( $imported || $param->{empty_ok} ) { + $dbh->rollback if $oldAutoCommit; + return "Empty file!"; + } - return "Empty file!" unless $imported || $param->{empty_ok}; + $dbh->commit or die $dbh->errstr if $oldAutoCommit;; ''; #no error |