[freeside-commits] freeside/FS/FS Record.pm, 1.175, 1.176 cdr.pm, 1.27, 1.28
Ivan,,,
ivan at wavetail.420.am
Fri Jan 2 14:04:00 PST 2009
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv27550/FS/FS
Modified Files:
Record.pm cdr.pm
Log Message:
add troop CDRs, RT#4413
Index: cdr.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cdr.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- cdr.pm 31 Dec 2008 03:28:56 -0000 1.27
+++ cdr.pm 2 Jan 2009 22:03:57 -0000 1.28
@@ -672,7 +672,7 @@
=over 4
-=item filehandle
+=item file
=item format
@@ -680,35 +680,56 @@
=cut
-sub process_batch_import {
- my $job = shift;
- my $opt = {
- 'table' => 'cdr',
- 'params' => [ 'format', 'cdrbatch' ],
+my %import_options = (
+ 'table' => 'cdr',
- 'formats' => { map { $_ => $cdr_info{$_}->{'import_fields'}; }
- keys %cdr_info
- },
+ 'formats' => { map { $_ => $cdr_info{$_}->{'import_fields'}; }
+ keys %cdr_info
+ },
- #drop the || 'csv' to allow auto xls for csv types?
- 'format_types' => { map { $_ => ( lc($cdr_info{$_}->{'type'}) || 'csv' ); }
+ #drop the || 'csv' to allow auto xls for csv types?
+ 'format_types' => { map { $_ => ( lc($cdr_info{$_}->{'type'}) || 'csv' ); }
+ keys %cdr_info
+ },
+
+ 'format_headers' => { map { $_ => ( $cdr_info{$_}->{'header'} || 0 ); }
keys %cdr_info
},
- 'format_headers' => { map { $_ => ( $cdr_info{$_}->{'header'} || 0 ); }
+ 'format_sep_chars' => { map { $_ => $cdr_info{$_}->{'sep_char'}; }
keys %cdr_info
},
- 'format_sep_chars' => { map { $_ => $cdr_info{$_}->{'sep_char'}; }
- keys %cdr_info
- },
+ 'format_fixedlength_formats' =>
+ { map { $_ => $cdr_info{$_}->{'fixedlength_format'}; }
+ keys %cdr_info
+ },
+);
- 'format_fixedlength_formats' =>
- { map { $_ => $cdr_info{$_}->{'fixedlength_format'}; }
- keys %cdr_info
- },
- };
+sub _import_options {
+ \%import_options;
+}
+
+sub batch_import {
+ my $opt = shift;
+
+ my $iopt = _import_options;
+ $opt->{$_} = $iopt->{$_} foreach keys %$iopt;
+
+ FS::Record::batch_import( $opt );
+
+}
+
+=item process_batch_import
+
+=cut
+
+sub process_batch_import {
+ my $job = shift;
+
+ my $opt = _import_options;
+ $opt->{'params'} = [ 'format', 'cdrbatch' ];
FS::Record::process_batch_import( $job, $opt, @_ );
Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Record.pm,v
retrieving revision 1.175
retrieving revision 1.176
diff -u -d -r1.175 -r1.176
--- Record.pm 31 Dec 2008 22:04:45 -0000 1.175
+++ Record.pm 2 Jan 2009 22:03:57 -0000 1.176
@@ -1431,47 +1431,23 @@
my $dir = '%%%FREESIDE_CACHE%%%/cache.'. $FS::UID::datasrc. '/';
my $file = $dir. $files{'file'};
- my $type = $opt->{'format_types'}
- ? $opt->{'format_types'}{ $param->{'format'} }
- : '';
-
- unless ( $type ) {
- if ( $file =~ /\.(\w+)$/i ) {
- $type = lc($1);
- } else {
- #or error out???
- warn "can't parse file type from filename $file; defaulting to CSV";
- $type = 'csv';
- }
- $type = 'csv'
- if $opt->{'default_csv'} && $type ne 'xls';
- }
-
- my $header = $opt->{'format_headers'}
- ? $opt->{'format_headers'}{ $param->{'format'} }
- : 0;
-
- my $sep_char = $opt->{'format_sep_chars'}
- ? $opt->{'format_sep_chars'}{ $param->{'format'} }
- : ',';
-
- my $fixedlength_format =
- $opt->{'format_fixedlength_formats'}
- ? $opt->{'format_fixedlength_formats'}{ $param->{'format'} }
- : '';
-
my $error =
FS::Record::batch_import( {
- table => $table,
- formats => \%formats,
- job => $job,
- file => $file,
- type => $type,
- format => $param->{format},
- header => $header,
- sep_char => $sep_char,
- fixedlength_format => $fixedlength_format,
- params => { map { $_ => $param->{$_} } @pass_params },
+ #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},
} );
unlink $file;
@@ -1489,13 +1465,21 @@
=item formats
+=item format_types
+
+=item format_headers
+
+=item format_sep_chars
+
+=item format_fixedlength_formats
+
=item params
=item job
FS::queue object, will be updated with progress
-=item filename
+=item file
=item type
@@ -1503,12 +1487,6 @@
=item format
-=item header
-
-=item sep_char
-
-=item fixedlength_format
-
=item empty_ok
=back
@@ -1521,19 +1499,46 @@
warn "$me batch_import call with params: \n". Dumper($param)
if $DEBUG;
- my $table = $param->{table};
- my $formats = $param->{formats};
- my $params = $param->{params};
+ my $table = $param->{table};
+ my $formats = $param->{formats};
- my $job = $param->{job};
+ my $job = $param->{job};
+ my $file = $param->{file};
+ my $format = $param->{'format'};
+ my $params = $param->{params};
- my $filename = $param->{file};
- my $type = $param->{type} || 'csv';
+ die "unknown format $format" unless exists $formats->{ $format };
- my $format = $param->{'format'};
+ my $type = $param->{'format_types'}
+ ? $param->{'format_types'}{ $format }
+ : $param->{type} || 'csv';
- die "unknown format $format" unless exists $formats->{ $format };
- my @fields = @{ $formats->{ $format } };
+ unless ( $type ) {
+ if ( $file =~ /\.(\w+)$/i ) {
+ $type = lc($1);
+ } else {
+ #or error out???
+ warn "can't parse file type from filename $file; defaulting to CSV";
+ $type = 'csv';
+ }
+ $type = 'csv'
+ if $param->{'default_csv'} && $type ne 'xls';
+ }
+
+ my $header = $param->{'format_headers'}
+ ? $param->{'format_headers'}{ $param->{'format'} }
+ : 0;
+
+ my $sep_char = $param->{'format_sep_chars'}
+ ? $param->{'format_sep_chars'}{ $param->{'format'} }
+ : ',';
+
+ my $fixedlength_format =
+ $param->{'format_fixedlength_formats'}
+ ? $param->{'format_fixedlength_formats'}{ $param->{'format'} }
+ : '';
+
+ my @fields = @{ $formats->{ $format } };
my $row = 0;
my $count;
@@ -1544,24 +1549,21 @@
if ( $type eq 'csv' ) {
my %attr = ();
- foreach ( grep exists($param->{$_}), qw( sep_char ) ) {
- $attr{$_} = $param->{$_};
- }
-
+ $attr{sep_char} = $sep_char if $sep_char;
$parser = new Text::CSV_XS \%attr;
} elsif ( $type eq 'fixedlength' ) {
eval "use Parse::FixedLength;";
die $@ if $@;
- $parser = new Parse::FixedLength $param->{'fixedlength_format'};
+ $parser = new Parse::FixedLength $fixedlength_format;
} else {
die "Unknown file type $type\n";
}
- @buffer = split(/\r?\n/, slurp($filename) );
- splice(@buffer, 0, ($param->{'header'} || 0) );
+ @buffer = split(/\r?\n/, slurp($file) );
+ splice(@buffer, 0, ($header || 0) );
$count = scalar(@buffer);
} elsif ( $type eq 'xls' ) {
@@ -1574,14 +1576,14 @@
# formats bill_west and troop use it, not other excel-parsing things
#die $@ if $@;
- my $excel = Spreadsheet::ParseExcel::Workbook->new->Parse($filename);
+ my $excel = Spreadsheet::ParseExcel::Workbook->new->Parse($file);
$parser = $excel->{Worksheet}[0]; #first sheet
$count = $parser->{MaxRow} || $parser->{MinRow};
$count++;
- $row = $param->{'header'} || 0;
+ $row = $header || 0;
} else {
die "Unknown file type $type\n";
@@ -1647,6 +1649,7 @@
#&{$field}(\%hash, $value);
push @later, $field, $value;
} else {
+ #??? $hash{$field} = $value if length($value);
$hash{$field} = $value if defined($value) && length($value);
}
More information about the freeside-commits
mailing list