From 8788e2f2666c42fd4930e859245cb5116382209e 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 Content-Type: text/plain; charset=utf-8 This patch makes two adjustments: [1] For the verbose option, verbose level 2 now means print the formatted marcxml per 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: do no use -v on the command line, use -v 1 and -v 2 on the command line. (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 2 -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 verbose 2 option allows you to easily check that.) --- misc/migration_tools/bulkmarcimport.pl | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index 9ca7b31..13de020 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, @@ -202,9 +207,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 @@ -216,6 +222,7 @@ RECORD: while ( ) { } } SetUTF8Flag($record); + &$localcust($record) if $localcust; my $isbn; # remove trailing - in isbn (only for biblios, of course) if ($biblios && $cleanisbn) { @@ -457,6 +464,7 @@ RECORD: while ( ) { } $dbh->commit() if (0 == $i % $commitnum); } + print $record->as_formatted()."\n" if ($verbose//0)==2; last if $i == $number; } $dbh->commit(); -- 1.7.7.6