bug 1372: count MARC records correctly
authorGalen Charlton <galen.charlton@liblime.com>
Fri, 8 Feb 2008 22:55:41 +0000 (16:55 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Sat, 9 Feb 2008 02:22:43 +0000 (20:22 -0600)
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/ImportBatch.pm
misc/stage_biblios_file.pl
tools/stage-marc-import.pl

index 0c93ccd..283de04 100644 (file)
@@ -266,6 +266,9 @@ sub  BatchStageMarcRecords {
     # FIXME - for now, we're dealing only with bibs
     my $rec_num = 0;
     foreach my $marc_blob (split(/\x1D/, $marc_records)) {
+        $marc_blob =~ s/^\s+//g;
+        $marc_blob =~ s/\s+$//g;
+        next unless $marc_blob;
         $rec_num++;
         if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
             &$progress_callback($rec_num);
index 671bc86..cf140c2 100755 (executable)
@@ -54,6 +54,10 @@ sub process_batch {
     $/ = "\035";
     my $num_input_records = 0;
     while (<IN>) {
+        s/^\s+//;
+        s/\s+$//;
+        next unless $_; # skip if record has only whitespace, as might occur
+                        # if file includes newlines between each MARC record
         $marc_records .= $_; # FIXME - this sort of string concatenation
                              # is probably rather inefficient
         $num_input_records++;
index e75019a..3075c52 100755 (executable)
@@ -75,7 +75,10 @@ if ($completedJobID) {
     my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID);
     my $fh = $uploaded_file->fh();
        my $marcrecord='';
+    $/ = "\035";
        while (<$fh>) {
+        s/^\s+//;
+        s/\s+$//;
                $marcrecord.=$_;
        }