[freeside-commits] freeside/FS/FS Record.pm, 1.170, 1.171 inventory_item.pm, 1.3, 1.4

Ivan,,, ivan at wavetail.420.am
Mon Dec 8 17:46:55 PST 2008


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv25262/FS/FS

Modified Files:
	Record.pm inventory_item.pm 
Log Message:
use common base for inventory import too, fixes problems with errors due to dos line endings and allows Excel upload, RT#4346

Index: inventory_item.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/inventory_item.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- inventory_item.pm	16 Jul 2006 00:55:05 -0000	1.3
+++ inventory_item.pm	9 Dec 2008 01:46:52 -0000	1.4
@@ -129,61 +129,25 @@
 
 =back
 
-=head1 CLASS METHODS
+=head1 SUBROUTINES
 
 =over 4
 
-=item batch_import
+=item process_batch_import
 
 =cut
 
-sub batch_import {
-  my $param = shift;
-
-  my $fh = $param->{filehandle};
-
-  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;
+sub process_batch_import {
+  my $job = shift;
 
-  #might want to disable this if we skip records for any reason...
-  return "Empty file!" unless $imported;
+  my $opt = { 'table'   => 'inventory_item',
+              #'params'  => [ 'itembatch', 'classnum', ],
+              'params'  => [ 'classnum', ],
+              'formats' => { 'default' => [ 'item' ] },
+              'default_csv' => 1,
+            };
 
-  '';
+  FS::Record::process_batch_import( $job, $opt, @_ );
 
 }
 

Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Record.pm,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- Record.pm	26 Nov 2008 00:20:30 -0000	1.170
+++ Record.pm	9 Dec 2008 01:46:52 -0000	1.171
@@ -1339,6 +1339,8 @@
     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( {



More information about the freeside-commits mailing list