This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / bin / tax_rate_location.import
1 #!/usr/bin/perl -Tw
2
3 use strict;
4 use vars qw($opt_g $opt_f);
5 use vars qw($DEBUG);
6 use Getopt::Std;
7 use FS::UID qw(adminsuidsetup);
8 use FS::Conf;
9 use FS::tax_rate_location;
10
11 getopts('f:g:');
12
13 my $user = shift or die &usage;
14 my $dbh = adminsuidsetup $user;
15
16 my ($format) = $opt_f =~ /^([-\w]+)$/;
17
18 my @list = (
19   'GEOCODE',      $opt_g, \&FS::tax_rate_location::batch_import,
20 );
21
22 my $oldAutoCommit = $FS::UID::AutoCommit;
23 local $FS::UID::AutoCommit = 0;
24
25 my $error = '';
26
27 while(@list) {
28   my ($name, $file, $method) = splice(@list, 0, 3);
29
30   my $fh;
31
32   $file =~ /^([\s\d\w.]+)$/ or die "Illegal filename: $file\n";
33   $file = $1;
34
35   open $fh, '<', $file or die "can't open $name file: $!\n";
36   $error ||= &{$method}( { filehandle => $fh, 'format' => $format, } );
37
38   die "error while processing $file: $error" if $error;
39   close $fh;
40 }
41
42 if ($error) {
43   $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
44 }else{
45   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
46 }
47
48 sub usage { die "Usage:\ntax_rates_location.import -f FORMAT -g GEOCODEFILE user\n\n"; }