Bug 8727 Minor stylistic change to help text
[koha_fer] / misc / migration_tools / bulkauthimport.pl
index 85233ba..2709db9 100755 (executable)
@@ -2,6 +2,7 @@
 # small script that import an iso2709 file into koha 2.0
 
 use strict;
+#use warnings; FIXME - Bug 2505
 BEGIN {
     # find Koha's Perl modules
     # test carefully before changing this
@@ -19,14 +20,15 @@ use C4::Context;
 use C4::Charset;
 use C4::AuthoritiesMarc;
 use Time::HiRes qw(gettimeofday);
-
 use Getopt::Long;
+use IO::File;
+
 my ( $input_marc_file, $number) = ('',0);
 my ($version, $delete, $test_parameter,$char_encoding, $verbose, $format, $commit);
 $| = 1;
 GetOptions(
     'file:s'    => \$input_marc_file,
-    'n' => \$number,
+    'n:i' => \$number,
     'h' => \$version,
     'd' => \$delete,
     't' => \$test_parameter,
@@ -72,6 +74,7 @@ my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
 $char_encoding = 'MARC21' unless ($char_encoding);
 print "CHAR : $char_encoding\n" if $verbose;
 my $starttime = gettimeofday;
+my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
 my $batch;
 if ($format =~ /XML/i) {
     # ugly hack follows -- MARC::File::XML, when used by MARC::Batch,
@@ -84,9 +87,9 @@ if ($format =~ /XML/i) {
     #       extract the records, not using regexes to look
     #       for <record>.*</record>.
     $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
-    $batch = MARC::Batch->new( 'XML', $input_marc_file );
+    $batch = MARC::Batch->new( 'XML', $fh );
 } else {
-    $batch = MARC::Batch->new( 'USMARC', $input_marc_file );
+    $batch = MARC::Batch->new( 'USMARC', $fh );
 }
 $batch->warnings_off();
 $batch->strict_off();
@@ -119,10 +122,10 @@ RECORD: while ( my $record = $batch->next() ) {
         $authtypecode="CORPO_NAME" if ($record->field('110'));
         $authtypecode="MEETI_NAME" if ($record->field('111'));
         $authtypecode="UNIF_TITLE" if ($record->field('130'));
-        $authtypecode="CHRON_TERM" if ($record->field('148'));
-        $authtypecode="TOPIC_TERM" if ($record->field('150'));
-        $authtypecode="GEOGR_NAME" if ($record->field('151'));
-        $authtypecode="GENRE/FORM" if ($record->field('155'));
+        $authtypecode="CHRON_TERM" if ($record->field('148') or $record->field('182'));
+        $authtypecode="TOPIC_TERM" if ($record->field('150') or $record->field('180'));
+        $authtypecode="GEOGR_NAME" if ($record->field('151') or $record->field('181'));
+        $authtypecode="GENRE/FORM" if ($record->field('155') or $record->field('185'));
         next unless $authtypecode; # skip invalid records FIXME: far too simplistic
     }
     else {
@@ -142,8 +145,10 @@ RECORD: while ( my $record = $batch->next() ) {
         warn "ADDED authority NB $authid in DB\n" if $verbose;
         $dbh->commit() if (0 == $i % $commitnum);
     }
+
+    last if $i ==  $number;
 }
 $dbh->commit();
 
 my $timeneeded = gettimeofday - $starttime;
-print "$i MARC record done in $timeneeded seconds\n";
+print "\n$i MARC record done in $timeneeded seconds\n";