[freeside-commits] freeside/FS/FS Record.pm, 1.207, 1.208 Schema.pm, 1.228, 1.229 Mason.pm, 1.49, 1.50 cust_pkg.pm, 1.166, 1.167
Ivan,,,
ivan at wavetail.420.am
Sun Aug 8 18:03:51 PDT 2010
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv22268/FS/FS
Modified Files:
Record.pm Schema.pm Mason.pm cust_pkg.pm
Log Message:
package web import from CSV/XLS, RT#9529
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.228
retrieving revision 1.229
diff -u -w -d -r1.228 -r1.229
--- Schema.pm 7 Aug 2010 07:39:05 -0000 1.228
+++ Schema.pm 9 Aug 2010 01:03:49 -0000 1.229
@@ -1289,6 +1289,7 @@
'pkgnum', 'serial', '', '', '', '',
'custnum', 'int', '', '', '', '',
'pkgpart', 'int', '', '', '', '',
+ 'pkgbatch', 'varchar', 'NULL', $char_d, '', '',
'locationnum', 'int', 'NULL', '', '', '',
'otaker', 'varchar', 'NULL', 32, '', '',
'usernum', 'int', 'NULL', '', '', '',
@@ -1310,7 +1311,8 @@
],
'primary_key' => 'pkgnum',
'unique' => [],
- 'index' => [ ['custnum'], ['pkgpart'], [ 'locationnum' ], [ 'usernum' ],
+ 'index' => [ ['custnum'], ['pkgpart'], [ 'pkgbatch' ], [ 'locationnum' ],
+ [ 'usernum' ],
[ 'start_date' ], ['setup'], ['last_bill'], ['bill'],
['susp'], ['adjourn'], ['expire'], ['cancel'],
['change_date'],
Index: Mason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Mason.pm,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -w -d -r1.49 -r1.50
--- Mason.pm 7 Aug 2010 07:39:05 -0000 1.49
+++ Mason.pm 9 Aug 2010 01:03:49 -0000 1.50
@@ -3,6 +3,7 @@
use strict;
use vars qw( @ISA @EXPORT_OK $addl_handler_use );
use Exporter;
+use Carp;
use File::Slurp qw( slurp );
use HTML::Mason 1.27; #http://www.masonhq.com/?ApacheModPerl2Redirect
use HTML::Mason::Interp;
@@ -146,6 +147,7 @@
use FS::cust_location;
use FS::cust_pay;
use FS::cust_pkg;
+ use FS::cust_pkg::Import;
use FS::part_pkg_taxclass;
use FS::cust_pkg_reason;
use FS::cust_refund;
@@ -361,6 +363,7 @@
sub include {
use vars qw($m);
+ #carp #should just switch to <& &> syntax
$m->scomp(@_);
}
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -w -d -r1.166 -r1.167
--- cust_pkg.pm 28 Jul 2010 23:16:30 -0000 1.166
+++ cust_pkg.pm 9 Aug 2010 01:03:49 -0000 1.167
@@ -2624,6 +2624,15 @@
}
##
+ # custbatch
+ ##
+
+ if ( $params->{'pkgbatch'} =~ /^([\w\/\-\:\.]+)$/ and $1 ) {
+ push @where,
+ "cust_pkg.pkgbatch = '$1'";
+ }
+
+ ##
# parse status
##
Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Record.pm,v
retrieving revision 1.207
retrieving revision 1.208
diff -u -w -d -r1.207 -r1.208
--- Record.pm 4 Aug 2010 19:14:49 -0000 1.207
+++ Record.pm 9 Aug 2010 01:03:49 -0000 1.208
@@ -1611,6 +1611,8 @@
=item table
+=item format - usual way to specify import, with this format string selecting data from the formats and format_* info hashes
+
=item formats
=item format_types
@@ -1623,6 +1625,10 @@
=item format_row_callbacks
+=item fields - Alternate way to specify import, specifying import fields directly as a listref
+
+=item postinsert_callback
+
=item params
=item job
@@ -1635,8 +1641,6 @@
csv, xls or fixedlength
-=item format
-
=item empty_ok
=back
@@ -1647,53 +1651,77 @@
my $param = shift;
warn "$me batch_import call with params: \n". Dumper($param)
- ;# if $DEBUG;
+ if $DEBUG;
my $table = $param->{table};
- my $formats = $param->{formats};
my $job = $param->{job};
my $file = $param->{file};
- my $format = $param->{'format'};
my $params = $param->{params} || {};
+ my( $type, $header, $sep_char, $fixedlength_format, $row_callback, @fields );
+ my $postinsert_callback = '';
+ if ( $param->{'format'} ) {
+
+ my $format = $param->{'format'};
+ my $formats = $param->{formats};
die "unknown format $format" unless exists $formats->{ $format };
- my $type = $param->{'format_types'}
+ $type = $param->{'format_types'}
? $param->{'format_types'}{ $format }
: $param->{type} || 'csv';
- 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'}
+ $header = $param->{'format_headers'}
? $param->{'format_headers'}{ $param->{'format'} }
: 0;
- my $sep_char = $param->{'format_sep_chars'}
+ $sep_char = $param->{'format_sep_chars'}
? $param->{'format_sep_chars'}{ $param->{'format'} }
: ',';
- my $fixedlength_format =
+ $fixedlength_format =
$param->{'format_fixedlength_formats'}
? $param->{'format_fixedlength_formats'}{ $param->{'format'} }
: '';
- my $row_callback =
+ $row_callback =
$param->{'format_row_callbacks'}
? $param->{'format_row_callbacks'}{ $param->{'format'} }
: '';
- my @fields = @{ $formats->{ $format } };
+ @fields = @{ $formats->{ $format } };
+
+ } elsif ( $param->{'fields'} ) {
+
+ $type = ''; #infer from filename
+ $header = 0;
+ $sep_char = ',';
+ $fixedlength_format = '';
+ $row_callback = '';
+ @fields = @{ $param->{'fields'} };
+
+ $postinsert_callback = $param->{'postinsert_callback'}
+ if $param->{'postinsert_callback'}
+
+ } else {
+ die "neither format nor fields specified";
+ }
+
+ #my $file = $param->{file};
+
+ 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 $row = 0;
my $count;
@@ -1757,6 +1785,7 @@
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ #my $params = $param->{params} || {};
if ( $param->{'batch_namecol'} && $param->{'batch_namevalue'} ) {
my $batch_col = $param->{'batch_keycol'};
@@ -1775,6 +1804,7 @@
$params->{ $batch_col } = $batch_value;
}
+ #my $job = $param->{job};
my $line;
my $imported = 0;
my( $last, $min_sec ) = ( time, 5 ); #progressbar foo
@@ -1832,6 +1862,7 @@
}
+ #my $table = $param->{table};
my $class = "FS::$table";
my $record = $class->new( \%hash );
@@ -1855,6 +1886,15 @@
$row++;
$imported++;
+ if ( $postinsert_callback ) {
+ my $error = &{$postinsert_callback}($record, $param);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "postinsert_callback error". ( $line ? " for $line" : '' ).
+ ": $error";
+ }
+ }
+
if ( $job && time - $min_sec > $last ) { #progress bar
$job->update_statustext( int(100 * $imported / $count) );
$last = time;
More information about the freeside-commits
mailing list