Bug 11278: Followup for customize command line parameter

The initial patch for this bug did not include a specific command line
option for customization. If a module LocalChanges.pm existed, it would
be used without asking.
This patch adds a command line option enabling the customization option
and offering the extra possibility of using another module name. If no file
name is passed, we default to LocalChanges.
Without the -custom option, behavior is as it was.
Also some POD lines are added to document the feature.

Test plan:
[1] Make a LocalChanges.pm in migration_tools. Verify that it is not used,
    if you do not enable the -cust parameter.
[2] Run the script again with -cust. Verify that it is called now.
[3] Copy LocalChanges.pm to Whatever.pm. Make some change. Run with
    -cust Whatever and verify that the new module is used.
[4] Copy Whatever.pm to another dir, make some change. Run with -cust and the
    full name. Verify that the latest change was used.
[5] Run without any option. Check the pod documentation.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Marcel de Rooy 2013-11-25 14:24:42 +01:00 committed by Galen Charlton
parent 8480570197
commit 9f45310d76

View file

@ -31,11 +31,6 @@ use Getopt::Long;
use IO::File; use IO::File;
use Pod::Usage; 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) ); use open qw( :std :encoding(UTF-8) );
binmode( STDOUT, ":encoding(UTF-8)" ); binmode( STDOUT, ":encoding(UTF-8)" );
my ( $input_marc_file, $number, $offset) = ('',0,0); my ( $input_marc_file, $number, $offset) = ('',0,0);
@ -44,6 +39,7 @@ my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append );
my $cleanisbn = 1; my $cleanisbn = 1;
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
my $framework = ''; my $framework = '';
my $localcust;
$|=1; $|=1;
@ -79,6 +75,7 @@ GetOptions(
'yaml:s' => \$yamlfile, 'yaml:s' => \$yamlfile,
'dedupbarcode' => \$dedup_barcode, 'dedupbarcode' => \$dedup_barcode,
'framework=s' => \$framework, 'framework=s' => \$framework,
'custom:s' => \$localcust,
); );
$biblios ||= !$authorities; $biblios ||= !$authorities;
$insert ||= !$update; $insert ||= !$update;
@ -94,6 +91,24 @@ if ($version || ($input_marc_file eq '')) {
exit; exit;
} }
if(defined $localcust) { #local customize module
if(!-e $localcust) {
$localcust= $localcust||'LocalChanges'; #default name
$localcust=~ s/^.*\/([^\/]+)$/$1/; #extract file name only
$localcust=~ s/\.pm$//; #remove extension
my $fqcust= $FindBin::Bin."/$localcust.pm"; #try migration_tools dir
if(-e $fqcust) {
$localcust= $fqcust;
}
else {
print "WARNING: customize module $localcust.pm not found!\n";
exit;
}
}
require $localcust if $localcust;
$localcust=\&customize if $localcust;
}
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $heading_fields=get_heading_fields(); my $heading_fields=get_heading_fields();
@ -748,6 +763,14 @@ This is the code for the framework that the requested records will have attached
to them when they are created. If not specified, then the default framework to them when they are created. If not specified, then the default framework
will be used. will be used.
=item B<-custom>=I<MODULE>
This parameter allows you to use a local module with a customize subroutine
that is called for each MARC record.
If no filename is passed, LocalChanges.pm is assumed to be in the
migration_tools subdirectory. You may pass an absolute file name or a file name
from the migration_tools directory.
=back =back
=cut =cut