summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
Diffstat (limited to 'FS')
-rw-r--r--FS/FS.pm2
-rw-r--r--FS/FS/Mason.pm1
-rw-r--r--FS/FS/Record.pm62
-rw-r--r--FS/FS/Schema.pm25
-rw-r--r--FS/FS/Upgrade.pm3
-rw-r--r--FS/FS/cdr.pm8
-rw-r--r--FS/MANIFEST2
-rwxr-xr-xFS/bin/freeside-cdr-sftp_and_import8
8 files changed, 74 insertions, 37 deletions
diff --git a/FS/FS.pm b/FS/FS.pm
index 9ec2602cd..c6f9eceaf 100644
--- a/FS/FS.pm
+++ b/FS/FS.pm
@@ -150,6 +150,8 @@ L<FS::phone_avail> - Phone number availability cache
L<FS::cdr> - Call Detail Record class
+L<FS::cdr_batch> - Call Detail Record batch class
+
L<FS::cdr_calltype> - CDR calltype class
L<FS::cdr_carrier> - CDR carrier class
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index 460e1c334..bef005881 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -185,6 +185,7 @@ if ( -e $addl_handler_use_file ) {
use FS::XMLRPC;
use FS::payby;
use FS::cdr;
+ use FS::cdr_batch;
use FS::inventory_class;
use FS::inventory_item;
use FS::pkg_category;
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 88d8ca9a3..e02a2cff8 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -1547,7 +1547,7 @@ sub process_batch_import {
my($job, $opt) = ( shift, shift );
my $table = $opt->{table};
- my @pass_params = @{ $opt->{params} };
+ my @pass_params = $opt->{params} ? @{ $opt->{params} } : ();
my %formats = %{ $opt->{formats} };
my $param = thaw(decode_base64(shift));
@@ -1561,24 +1561,30 @@ sub process_batch_import {
my $dir = '%%%FREESIDE_CACHE%%%/cache.'. $FS::UID::datasrc. '/';
my $file = $dir. $files{'file'};
- my $error =
- FS::Record::batch_import( {
- #class-static
- table => $table,
- formats => \%formats,
- format_types => $opt->{format_types},
- format_headers => $opt->{format_headers},
- format_sep_chars => $opt->{format_sep_chars},
- format_fixedlength_formats => $opt->{format_fixedlength_formats},
- #per-import
- job => $job,
- file => $file,
- #type => $type,
- format => $param->{format},
- params => { map { $_ => $param->{$_} } @pass_params },
- #?
- default_csv => $opt->{default_csv},
- } );
+ my %iopt = (
+ #class-static
+ table => $table,
+ formats => \%formats,
+ format_types => $opt->{format_types},
+ format_headers => $opt->{format_headers},
+ format_sep_chars => $opt->{format_sep_chars},
+ format_fixedlength_formats => $opt->{format_fixedlength_formats},
+ #per-import
+ job => $job,
+ file => $file,
+ #type => $type,
+ format => $param->{format},
+ params => { map { $_ => $param->{$_} } @pass_params },
+ #?
+ default_csv => $opt->{default_csv},
+ );
+
+ if ( $opt->{'batch_namecol'} ) {
+ $iopt{'batch_namevalue'} = $param->{ $opt->{'batch_namecol'} };
+ $iopt{$_} = $opt->{$_} foreach qw( batch_keycol batch_table batch_namecol );
+ }
+
+ my $error = FS::Record::batch_import( \%iopt );
unlink $file;
@@ -1731,6 +1737,24 @@ sub batch_import {
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+
+ if ( $param->{'batch_namecol'} && $param->{'batch_namevalue'} ) {
+ my $batch_col = $param->{'batch_keycol'};
+
+ my $batch_class = 'FS::'. $param->{'batch_table'};
+ my $batch = $batch_class->new({
+ $param->{'batch_namecol'} => $param->{'batch_namevalue'}
+ });
+ my $error = $batch->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't insert batch record: $error";
+ }
+ #primary key via dbdef? (so the column names don't have to match)
+ my $batch_value = $batch->get( $param->{'batch_keycol'} );
+
+ $params->{ $batch_col } = $batch_value;
+ }
my $line;
my $imported = 0;
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 2910c170c..f4cbe1d30 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2235,9 +2235,10 @@ sub tables_hashref {
#an indexed place to put big numbers
'cdrid', 'bigint', 'NULL', '', '', '',
- #i should become a table
+ #old
'cdrbatch', 'varchar', 'NULL', 255, '', '',
- #'cdrbatchnum', 'int', 'NULL', '', '', '',
+ #new
+ 'cdrbatchnum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'acctid',
@@ -2250,16 +2251,16 @@ sub tables_hashref {
],
},
- #'cdr_batch' => {
- # 'columns' => [
- # 'cdrbatchnum', 'serial', '', '', '', '',
- # 'cdrbatch', 'varchar', 'NULL', 255, '', '',
- # '_date', @date_type, '', '',
- # ],
- # 'primary_key' => 'cdrbatchnum',
- # 'unique' => [ [ 'cdrbatch' ] ],
- # 'index' => [],
- #},
+ 'cdr_batch' => {
+ 'columns' => [
+ 'cdrbatchnum', 'serial', '', '', '', '',
+ 'cdrbatch', 'varchar', 'NULL', 255, '', '',
+ '_date', @date_type, '', '',
+ ],
+ 'primary_key' => 'cdrbatchnum',
+ 'unique' => [ [ 'cdrbatch' ] ],
+ 'index' => [],
+ },
'cdr_termination' => {
'columns' => [
diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index e5cd5d32b..c39680ef7 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -138,6 +138,9 @@ sub upgrade_data {
#add weights to pkg_category
'pkg_category' => [],
+ #cdrbatch fixes
+ 'cdr' => [],
+
;
\%hash;
diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index cd4285428..b9a4e41db 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -763,7 +763,11 @@ Set true to prevent throwing an error on empty imports
=cut
my %import_options = (
- 'table' => 'cdr',
+ 'table' => 'cdr',
+
+ 'batch_keycol' => 'cdrbatchnum',
+ 'batch_table' => 'cdr_batch',
+ 'batch_namecol' => 'cdrbatch',
'formats' => { map { $_ => $cdr_info{$_}->{'import_fields'}; }
keys %cdr_info
@@ -810,7 +814,7 @@ sub process_batch_import {
my $job = shift;
my $opt = _import_options;
- $opt->{'params'} = [ 'format', 'cdrbatch' ];
+# $opt->{'params'} = [ 'format', 'cdrbatch' ];
FS::Record::process_batch_import( $job, $opt, @_ );
diff --git a/FS/MANIFEST b/FS/MANIFEST
index b84ba525b..8a02a1338 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -453,6 +453,8 @@ FS/cust_attachment.pm
t/cust_attachment.t
FS/cust_statement.pm
t/cust_statement.t
+FS/cdr_batch.pm
+t/cdr_batch.t
FS/cust_class.pm
t/cust_class.t
FS/cust_category.pm
diff --git a/FS/bin/freeside-cdr-sftp_and_import b/FS/bin/freeside-cdr-sftp_and_import
index e87698fc5..d90695f8f 100755
--- a/FS/bin/freeside-cdr-sftp_and_import
+++ b/FS/bin/freeside-cdr-sftp_and_import
@@ -84,10 +84,10 @@ foreach my $filename ( @$ls ) {
warn "Processing $filename\n" if $opt_v;
my $error = FS::cdr::batch_import( {
- 'file' => "$cachedir/$filename",
- 'format' => $format,
- 'params' => { 'cdrbatch' => $filename, },
- 'empty_ok' => 1,
+ 'file' => "$cachedir/$filename",
+ 'format' => $format,
+ 'batch_namevalue' => $filename,
+ 'empty_ok' => 1,
} );
die $error if $error;