X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=4f0984c7496e686e580911ad1d7965a7432395bc;hb=387c96b0d8f224f3ade27bed9348f37b432bbb8a;hp=ab4ea2a5bf7b9a96dee10db2fd34a8f72485de08;hpb=bdfbb5a929adcaa493d046145bec6d6914e9611b;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index ab4ea2a5b..4f0984c74 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -350,7 +350,8 @@ sub qsearch { my @bind_type = (); my $dbh = dbh; foreach my $stable ( @stable ) { - my $record = shift @record; + #stop altering the caller's hashref + my $record = { %{ shift(@record) || {} } };#and be liberal in receipt my $select = shift @select; my $extra_sql = shift @extra_sql; my $extra_param = shift @extra_param; @@ -1871,7 +1872,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 +1909,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 @@ -2178,7 +2188,7 @@ May be null. If there is an error, returns the error, otherwise returns false. sub ut_textn { my($self,$field)=@_; - return $self->setfield($field, '') if $self-getfield($field) =~ /^$/; + return $self->setfield($field, '') if $self->getfield($field) =~ /^$/; $self->ut_text($field); }