summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2008-12-09 01:46:53 +0000
committerivan <ivan>2008-12-09 01:46:53 +0000
commitde1e1a1c2563a9741a5be44f997889f7c37c36ed (patch)
treea2a9f5df86d825cf706a82d30995a96710a38800 /FS
parent6115c160d19e6c82e3f713d0d79128fbf45e46da (diff)
use common base for inventory import too, fixes problems with errors due to dos line endings and allows Excel upload, RT#4346
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Record.pm2
-rw-r--r--FS/FS/inventory_item.pm58
2 files changed, 13 insertions, 47 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 4b6684d8e..80ab564f1 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -1339,6 +1339,8 @@ sub process_batch_import {
warn "can't parse file type from filename $file; defaulting to CSV";
$type = 'csv';
}
+ $type = 'csv' unless $type eq 'xls';
+ $opt->{'default_csv'} && $type ne 'xls';
my $error =
FS::Record::batch_import( {
diff --git a/FS/FS/inventory_item.pm b/FS/FS/inventory_item.pm
index 7fa350f2a..3bba1cdda 100644
--- a/FS/FS/inventory_item.pm
+++ b/FS/FS/inventory_item.pm
@@ -129,61 +129,25 @@ sub cust_svc {
=back
-=head1 CLASS METHODS
+=head1 SUBROUTINES
=over 4
-=item batch_import
+=item process_batch_import
=cut
-sub batch_import {
- my $param = shift;
+sub process_batch_import {
+ my $job = shift;
- my $fh = $param->{filehandle};
+ my $opt = { 'table' => 'inventory_item',
+ #'params' => [ 'itembatch', 'classnum', ],
+ 'params' => [ 'classnum', ],
+ 'formats' => { 'default' => [ 'item' ] },
+ 'default_csv' => 1,
+ };
- my $imported = 0;
-
- local $SIG{HUP} = 'IGNORE';
- local $SIG{INT} = 'IGNORE';
- local $SIG{QUIT} = 'IGNORE';
- local $SIG{TERM} = 'IGNORE';
- local $SIG{TSTP} = 'IGNORE';
- local $SIG{PIPE} = 'IGNORE';
-
- my $oldAutoCommit = $FS::UID::AutoCommit;
- local $FS::UID::AutoCommit = 0;
- my $dbh = dbh;
-
- my $line;
- while ( defined($line=<$fh>) ) {
-
- chomp $line;
-
- my $inventory_item = new FS::inventory_item {
- 'classnum' => $param->{'classnum'},
- 'item' => $line,
- };
-
- my $error = $inventory_item->insert;
-
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
-
- #or just skip?
- #next;
- }
-
- $imported++;
- }
-
- $dbh->commit or die $dbh->errstr if $oldAutoCommit;
-
- #might want to disable this if we skip records for any reason...
- return "Empty file!" unless $imported;
-
- '';
+ FS::Record::process_batch_import( $job, $opt, @_ );
}