projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
RT#30825: Modernize Bulk payment importing
[freeside.git]
/
FS
/
FS
/
Record.pm
diff --git
a/FS/FS/Record.pm
b/FS/FS/Record.pm
index
0810a7e
..
0f3685b
100644
(file)
--- a/
FS/FS/Record.pm
+++ b/
FS/FS/Record.pm
@@
-45,7
+45,7
@@
our $nowarn_classload = 0;
our $no_update_diff = 0;
our $no_history = 0;
our $no_update_diff = 0;
our $no_history = 0;
-our $qsearch_qualify_columns =
0
;
+our $qsearch_qualify_columns =
1
;
our $no_check_foreign = 1; #well, not inefficiently in perl by default anymore
our $no_check_foreign = 1; #well, not inefficiently in perl by default anymore
@@
-489,6
+489,8
@@
sub qsearch {
$sth->finish;
$sth->finish;
+ #below was refactored out to _from_hashref, this should use it at some point
+
my @return;
if ( eval 'scalar(@FS::'. $table. '::ISA);' ) {
if ( eval 'FS::'. $table. '->can(\'new\')' eq \&new ) {
my @return;
if ( eval 'scalar(@FS::'. $table. '::ISA);' ) {
if ( eval 'FS::'. $table. '->can(\'new\')' eq \&new ) {
@@
-876,6
+878,7
@@
sub qsearchs { # $result_record = &FS::Record:qsearchs('table',\%hash);
my $table = $_[0];
my(@result) = qsearch(@_);
cluck "warning: Multiple records in scalar search ($table)"
my $table = $_[0];
my(@result) = qsearch(@_);
cluck "warning: Multiple records in scalar search ($table)"
+ #.join(' / ', map "$_=>".$_[1]->{$_}, keys %{ $_[1] } )
if scalar(@result) > 1;
#should warn more vehemently if the search was on a primary key?
scalar(@result) ? ($result[0]) : ();
if scalar(@result) > 1;
#should warn more vehemently if the search was on a primary key?
scalar(@result) ? ($result[0]) : ();
@@
-1800,6
+1803,7
@@
sub process_batch_import {
format_xml_formats => $opt->{format_xml_formats},
format_asn_formats => $opt->{format_asn_formats},
format_row_callbacks => $opt->{format_row_callbacks},
format_xml_formats => $opt->{format_xml_formats},
format_asn_formats => $opt->{format_asn_formats},
format_row_callbacks => $opt->{format_row_callbacks},
+ format_hash_callbacks => $opt->{format_hash_callbacks},
#per-import
job => $job,
file => $file,
#per-import
job => $job,
file => $file,
@@
-1808,7
+1812,9
@@
sub process_batch_import {
params => { map { $_ => $param->{$_} } @pass_params },
#?
default_csv => $opt->{default_csv},
params => { map { $_ => $param->{$_} } @pass_params },
#?
default_csv => $opt->{default_csv},
+ preinsert_callback => $opt->{preinsert_callback},
postinsert_callback => $opt->{postinsert_callback},
postinsert_callback => $opt->{postinsert_callback},
+ insert_args_callback => $opt->{insert_args_callback},
);
if ( $opt->{'batch_namecol'} ) {
);
if ( $opt->{'batch_namecol'} ) {
@@
-1845,6
+1851,8
@@
Class method for batch imports. Available params:
=item format_row_callbacks
=item format_row_callbacks
+=item format_hash_callbacks - After parsing, before object creation
+
=item fields - Alternate way to specify import, specifying import fields directly as a listref
=item preinsert_callback
=item fields - Alternate way to specify import, specifying import fields directly as a listref
=item preinsert_callback
@@
-1887,7
+1895,7
@@
sub batch_import {
my( $type, $header, $sep_char,
$fixedlength_format, $xml_format, $asn_format,
my( $type, $header, $sep_char,
$fixedlength_format, $xml_format, $asn_format,
- $parser_opt, $row_callback, @fields );
+ $parser_opt, $row_callback,
$hash_callback,
@fields );
my $postinsert_callback = '';
$postinsert_callback = $param->{'postinsert_callback'}
my $postinsert_callback = '';
$postinsert_callback = $param->{'postinsert_callback'}
@@
-1895,6
+1903,9
@@
sub batch_import {
my $preinsert_callback = '';
$preinsert_callback = $param->{'preinsert_callback'}
if $param->{'preinsert_callback'};
my $preinsert_callback = '';
$preinsert_callback = $param->{'preinsert_callback'}
if $param->{'preinsert_callback'};
+ my $insert_args_callback = '';
+ $insert_args_callback = $param->{'insert_args_callback'}
+ if $param->{'insert_args_callback'};
if ( $param->{'format'} ) {
if ( $param->{'format'} ) {
@@
-1940,6
+1951,11
@@
sub batch_import {
? $param->{'format_row_callbacks'}{ $param->{'format'} }
: '';
? $param->{'format_row_callbacks'}{ $param->{'format'} }
: '';
+ $hash_callback =
+ $param->{'format_hash_callbacks'}
+ ? $param->{'format_hash_callbacks'}{ $param->{'format'} }
+ : '';
+
@fields = @{ $formats->{ $format } };
} elsif ( $param->{'fields'} ) {
@fields = @{ $formats->{ $format } };
} elsif ( $param->{'fields'} ) {
@@
-1949,6
+1965,7
@@
sub batch_import {
$sep_char = ',';
$fixedlength_format = '';
$row_callback = '';
$sep_char = ',';
$fixedlength_format = '';
$row_callback = '';
+ $hash_callback = '';
@fields = @{ $param->{'fields'} };
} else {
@fields = @{ $param->{'fields'} };
} else {
@@
-2174,6
+2191,8
@@
sub batch_import {
$hash{custnum} = $2;
}
$hash{custnum} = $2;
}
+ %hash = &{$hash_callback}(%hash) if $hash_callback;
+
#my $table = $param->{table};
my $class = "FS::$table";
#my $table = $param->{table};
my $class = "FS::$table";
@@
-2204,7
+2223,12
@@
sub batch_import {
next if exists $param->{skiprow} && $param->{skiprow};
}
next if exists $param->{skiprow} && $param->{skiprow};
}
- my $error = $record->insert;
+ my @insert_args = ();
+ if ( $insert_args_callback ) {
+ @insert_args = &{$insert_args_callback}($record, $param);
+ }
+
+ my $error = $record->insert(@insert_args);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;