summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2014-12-30 16:02:14 -0800
committerMark Wells <mark@freeside.biz>2014-12-30 16:05:00 -0800
commitf25c596ba479c7c5cebcfd4447bb0db9c70a1e06 (patch)
tree8d21cc106e6d088bb4a34e8f53a967a54ed214ec /FS
parentde5fa0a86c7ea64d699c68d3e39219b63e4614f8 (diff)
import deployment zone census block list, #32625
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Record.pm20
-rw-r--r--FS/FS/deploy_zone.pm51
2 files changed, 65 insertions, 6 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 462376691..f2236b019 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -1584,7 +1584,7 @@ Table name (required).
=item params
-Listref of field names for static fields. They will be given values from the
+Arrayref of field names for static fields. They will be given values from the
PARAMS hashref and passed as a "params" hashref to batch_import.
=item formats
@@ -1633,13 +1633,15 @@ format_types).
=back
-PARAMS is a base64-encoded Storable string containing the POSTed data as
-a hash ref. It normally contains at least one field, "uploaded files",
-generated by /elements/file-upload.html and containing the list of uploaded
-files. Currently only supports a single file named "file".
+PARAMS is a hashref (or base64-encoded Storable hashref) containing the
+POSTed data. It must contain the field "uploaded files", generated by
+/elements/file-upload.html and containing the list of uploaded files.
+Currently only supports a single file named "file".
=cut
+# uploaded_files is kind of bizarre; fix that some time
+
use Storable qw(thaw);
use Data::Dumper;
use MIME::Base64;
@@ -1650,7 +1652,13 @@ sub process_batch_import {
my @pass_params = $opt->{params} ? @{ $opt->{params} } : ();
my %formats = %{ $opt->{formats} };
- my $param = thaw(decode_base64(shift));
+ my $param = shift;
+ # because some job-spawning code (JSRPC) pre-freezes the arguments,
+ # and then the 'frozen' attribute doesn't get set, and thus $job->args
+ # doesn't know to thaw them, we have to do this everywhere.
+ if (!ref $param) {
+ $param = thaw(decode_base64($param));
+ }
warn Dumper($param) if $DEBUG;
my $files = $param->{'uploaded_files'}
diff --git a/FS/FS/deploy_zone.pm b/FS/FS/deploy_zone.pm
index 6142b9181..38dd7dc2d 100644
--- a/FS/FS/deploy_zone.pm
+++ b/FS/FS/deploy_zone.pm
@@ -3,6 +3,8 @@ package FS::deploy_zone;
use strict;
use base qw( FS::o2m_Common FS::Record );
use FS::Record qw( qsearch qsearchs dbh );
+use Storable qw(thaw);
+use MIME::Base64;
=head1 NAME
@@ -265,6 +267,55 @@ sub deploy_zone_vertex {
});
}
+=back
+
+=head2 SUBROUTINES
+
+=over 4
+
+=item process_batch_import JOB, PARAMS
+
+=cut
+
+sub process_batch_import {
+ eval {
+ use FS::deploy_zone_block;
+ use FS::deploy_zone_vertex;
+ };
+ my $job = shift;
+ my $param = shift;
+ if (!ref($param)) {
+ $param = thaw(decode_base64($param));
+ }
+
+ # even if creating a new zone, the deploy_zone object should already
+ # be inserted by this point
+ my $zonenum = $param->{zonenum}
+ or die "zonenum required";
+ my $zone = FS::deploy_zone->by_key($zonenum)
+ or die "deploy_zone #$zonenum not found";
+ my $opt;
+ if ( $zone->zonetype eq 'B' ) {
+ $opt = { 'table' => 'deploy_zone_block',
+ 'params' => [ 'zonenum', 'censusyear' ],
+ 'formats' => { 'plain' => [ 'censusblock' ] },
+ 'default_csv' => 1,
+ };
+ $job->update_statustext('1,Inserting census blocks');
+ } elsif ( $zone->zonetype eq 'P' ) {
+ $opt = { 'table' => 'deploy_zone_vertex',
+ 'params' => [ 'zonenum' ],
+ 'formats' => { 'plain' => [ 'latitude', 'longitude' ] },
+ 'default_csv' => 1,
+ };
+ } else {
+ die "don't know how to import to zonetype ".$zone->zonetype;
+ }
+
+ FS::Record::process_batch_import( $job, $opt, $param );
+
+}
+
=head1 BUGS
=head1 SEE ALSO