From 84805701972fc6d580e40105f755613b4136b981 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 21 Nov 2013 11:29:59 +0100 Subject: [PATCH] Bug 11278: Adjusting bulkmarcimport.pl for customization routine and verbose printing This patch makes two adjustments: [1] For the verbose option, verbose level 2 now means print the formatted version of each record. [2] If a module LocalChanges.pm is found in misc/migration_tools, the routine "customize" in this module is called for each marc record. This allows you to make local changes to these marc records before importing them. Test plan: [1] Test the verbose option: a single -v for medium verbosity and two -v to dump a human-readable version of the record to standard output. (Do not yet copy LocalChanges.pm in the folder.) You may used the attached example file on Bugzilla: perl misc/migration_tools/bulkmarcimport.pl -file zztest01.xml -v -v -b -m XML -t | more Note the option t for test; no records will be imported. [2] Copy LocalChanges.pm in the migration_tools folder. You may use the example provided on Bugzilla (in a patch). If you use the example module, check the contents of 001, 005 and 590 fields. (The -v -v option allows you to easily check that.) Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Galen Charlton --- misc/migration_tools/bulkmarcimport.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index c725b716eb..28753b315c 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -31,6 +31,11 @@ use Getopt::Long; use IO::File; use Pod::Usage; +my $localcust= $FindBin::Bin.'/LocalChanges.pm'; +$localcust= -e $localcust? $localcust: undef; +require $localcust if $localcust; +$localcust=\&customize if $localcust; + use open qw( :std :encoding(UTF-8) ); binmode( STDOUT, ":encoding(UTF-8)" ); my ( $input_marc_file, $number, $offset) = ('',0,0); @@ -52,7 +57,7 @@ GetOptions( 't|test' => \$test_parameter, 's' => \$skip_marc8_conversion, 'c:s' => \$char_encoding, - 'v:s' => \$verbose, + 'v:i' => \$verbose, 'fk' => \$fk_off, 'm:s' => \$format, 'l:s' => \$logfile, @@ -204,9 +209,10 @@ RECORD: while ( ) { # skip if we get an empty record (that is MARC valid, but will result in AddBiblio failure last unless ( $record ); $i++; - print "."; - print "\n$i" unless $i % 100; - + if( ($verbose//1)==1 ) { #no dot for verbose==2 + print "." . ( $i % 100==0 ? "\n$i" : '' ); + } + # transcode the record to UTF8 if needed & applicable. if ($record->encoding() eq 'MARC-8' and not $skip_marc8_conversion) { # FIXME update condition @@ -218,6 +224,7 @@ RECORD: while ( ) { } } SetUTF8Flag($record); + &$localcust($record) if $localcust; my $isbn; # remove trailing - in isbn (only for biblios, of course) if ($biblios && $cleanisbn) { @@ -461,6 +468,7 @@ RECORD: while ( ) { } $dbh->commit() if (0 == $i % $commitnum); } + print $record->as_formatted()."\n" if ($verbose//0)==2; last if $i == $number; } $dbh->commit(); -- 2.39.2