From 004524584ba2c54380a2bc30616afd2c543c060c Mon Sep 17 00:00:00 2001 From: Frederic Demians Date: Wed, 16 Apr 2008 18:51:17 +0200 Subject: [PATCH] Tweak bullmarcimport.pl * Add a new parameter -o to begin importing input file after skiping n records. * Enclose input file reading in an eval directive to avoid abording import if few records are corrupted: they are now skipped. * Help formating. Signed-off-by: Joshua Ferraro --- misc/migration_tools/bulkmarcimport.pl | 75 +++++++++++++++----------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index 019167f4e9..b4b84bbf35 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -2,7 +2,8 @@ # Import an iso2709 file into Koha 3 use strict; -# use warnings; +#use warnings; +#use diagnostics; BEGIN { # find Koha's Perl modules # test carefully before changing this @@ -28,7 +29,7 @@ use IO::File; binmode(STDOUT, ":utf8"); -my ( $input_marc_file, $number) = ('',0); +my ( $input_marc_file, $number, $offset) = ('',0,0); my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format); $|=1; @@ -37,6 +38,7 @@ GetOptions( 'commit:f' => \$commit, 'file:s' => \$input_marc_file, 'n:f' => \$number, + 'o|offset:f' => \$offset, 'h' => \$version, 'd' => \$delete, 't' => \$test_parameter, @@ -49,28 +51,33 @@ GetOptions( if ($version || ($input_marc_file eq '')) { print <warnings_off(); $batch->strict_off(); my $i=0; -my $commitnum = 50; +my $commitnum = $commit ? $commit : 50; -if ($commit) { - -$commitnum = $commit; +# Skip file offset +if ( $offset ) { + print "Skipping file offset: $offset records\n"; + $batch->next() while ($offset--); } $dbh->{AutoCommit} = 0; -RECORD: while ( my $record = $batch->next() ) { +RECORD: while ( ) { + my $record; + eval { $record = $batch->next() }; + if ( $@ ) { + print "Bad MARC record: skipped\n"; + next; + } + last unless ( $record ); $i++; print "."; print "\r$i" unless $i % 100; - + if ($record->encoding() eq 'MARC-8' and not $skip_marc8_conversion) { # FIXME update condition my ($guessed_charset, $charset_errors); -- 2.39.5