diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS.pm | 2 | ||||
-rw-r--r-- | FS/FS/Mason.pm | 1 | ||||
-rw-r--r-- | FS/FS/Record.pm | 62 | ||||
-rw-r--r-- | FS/FS/Schema.pm | 25 | ||||
-rw-r--r-- | FS/FS/Upgrade.pm | 3 | ||||
-rw-r--r-- | FS/FS/cdr.pm | 8 | ||||
-rw-r--r-- | FS/FS/cdr_batch.pm | 128 | ||||
-rw-r--r-- | FS/MANIFEST | 2 | ||||
-rwxr-xr-x | FS/bin/freeside-cdr-sftp_and_import | 8 | ||||
-rw-r--r-- | FS/t/cdr_batch.t | 5 |
10 files changed, 207 insertions, 37 deletions
@@ -146,6 +146,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 6e6072ef7..e732eb77d 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -183,6 +183,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 cdcea2bbc..b7c867981 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2196,9 +2196,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', @@ -2211,16 +2212,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/FS/cdr_batch.pm b/FS/FS/cdr_batch.pm new file mode 100644 index 000000000..59cfd2c7c --- /dev/null +++ b/FS/FS/cdr_batch.pm @@ -0,0 +1,128 @@ +package FS::cdr_batch; + +use strict; +use base qw( FS::Record ); +#use FS::Record qw( qsearch qsearchs ); + +=head1 NAME + +FS::cdr_batch - Object methods for cdr_batch records + +=head1 SYNOPSIS + + use FS::cdr_batch; + + $record = new FS::cdr_batch \%hash; + $record = new FS::cdr_batch { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::cdr_batch object represents a CDR batch. FS::cdr_batch inherits from +FS::Record. The following fields are currently supported: + +=over 4 + +=item cdrbatchnum + +primary key + +=item cdrbatch + +cdrbatch + +=item _date + +_date + + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new batch. To add the batch to the database, see L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I<hash> method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'cdr_batch'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +# the insert method can be inherited from FS::Record + +=item delete + +Delete this record from the database. + +=cut + +# the delete method can be inherited from FS::Record + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid batch. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('cdrbatchnum') + || $self->ut_textn('cdrbatch') + || $self->ut_numbern('_date') + ; + return $error if $error; + + $self->_date(time) unless $self->_date; + + $self->SUPER::check; +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::cdr>, L<FS::Record>, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index f5511f04d..56436792f 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -453,3 +453,5 @@ FS/cust_attachment.pm t/cust_attachment.t FS/cust_statement.pm t/cust_statement.t +FS/cdr_batch.pm +t/cdr_batch.t 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; diff --git a/FS/t/cdr_batch.t b/FS/t/cdr_batch.t new file mode 100644 index 000000000..673a7bd84 --- /dev/null +++ b/FS/t/cdr_batch.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::cdr_batch; +$loaded=1; +print "ok 1\n"; |