From c6f5e0a029d7a8d8380c054f21693a1d626ce16b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 4 May 2016 19:53:46 +0100 Subject: [PATCH] Bug 16442: C4::Ris is not plack safe C4::Ris incorrectly uses 4 package variables: - $utf: not used, can be removed - $intype: set to marcflavour once, but later it assumes that it is usmarc if not defined - $marcprint: always 0, so set it to 0 - $protoyear: only used in 1 subroutine, let's define it at this level Test plan: Just make sure the RIS export works as before this patch --- C4/Ris.pm | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/C4/Ris.pm b/C4/Ris.pm index 4833202..2303fc2 100644 --- a/C4/Ris.pm +++ b/C4/Ris.pm @@ -76,11 +76,7 @@ use Koha::SimpleMARC qw(read_field); &marc2ris ); -our $utf; -our $intype; -our $marcprint; -our $protoyear; - +our $marcprint = 0; # Debug flag; =head1 marc2bibtex - Convert from UNIMARC to RIS @@ -97,8 +93,7 @@ sub marc2ris { my $output; my $marcflavour = C4::Context->preference("marcflavour"); - $intype = lc($marcflavour); - my $marcprint = 0; # Debug flag; + my $intype = lc($marcflavour); # Let's redirect stdout open my $oldout, ">&STDOUT"; @@ -113,7 +108,6 @@ sub marc2ris { if ( $intype eq "marc21" ) { if ( $leader =~ /^.{9}a/ ) { print "---\r\nUTF-8 data\r\n" if $marcprint; - $utf = 1; } else { print "---\r\nMARC-8 data\r\n" if $marcprint; @@ -395,21 +389,13 @@ sub print_typetag { ## hints my %typehash; - - ## the ukmarc here is just a guess - if (! defined $intype) { - ## assume MARC21 as default - %typehash = %ustypehash; - } - elsif ($intype eq "marc21" || $intype eq "ukmarc") { - %typehash = %ustypehash; - } - elsif ($intype eq "unimarc") { - %typehash = %unitypehash; + my $marcflavour = C4::Context->preference("marcflavour"); + my $intype = lc($marcflavour); + if ($intype eq "unimarc") { + %typehash = %unitypehash; } else { - ## assume MARC21 as default - %typehash = %ustypehash; + %typehash = %ustypehash; } if (!defined $typeofrecord || !exists $typehash{$typeofrecord}) { @@ -482,6 +468,8 @@ sub get_author { ## the sequence of the name parts is encoded either in indicator ## 1 (marc21) or 2 (unimarc) + my $marcflavour = C4::Context->preference("marcflavour"); + my $intype = lc($marcflavour); if ($intype eq "unimarc") { $indicator = 2; } @@ -552,6 +540,8 @@ $clean_subtitle ||= q{}; $clean_title =~ s% *[/:;.]$%%; $clean_subtitle =~ s%^ *(.*) *[/:;.]$%$1%; + my $marcflavour = C4::Context->preference("marcflavour"); + my $intype = lc($marcflavour); if (length($clean_title) > 0 || (length($clean_subtitle) > 0 && $intype ne "unimarc")) { print "TI - ", $clean_title; @@ -591,6 +581,8 @@ sub print_stitle { print "T2 - ", $clean_title,"\r\n"; } + my $marcflavour = C4::Context->preference("marcflavour"); + my $intype = lc($marcflavour); if ($intype eq "unimarc") { print "Series vol(\$v): ",$titlefield->subfield('v'),"\r\n" if $marcprint; if (length($titlefield->subfield('v')) > 0) { @@ -726,6 +718,8 @@ sub print_pubinfo { my $pubsub_publisher; my $pubsub_date; + my $marcflavour = C4::Context->preference("marcflavour"); + my $intype = lc($marcflavour); if ($intype eq "unimarc") { $pubsub_place = "a"; $pubsub_publisher = "c"; @@ -758,7 +752,7 @@ sub print_pubinfo { ## the dates are free-form, so we want to extract ## a four-digit year and leave the rest as ## "other info" - $protoyear = @$tuple[1]; + my $protoyear = @$tuple[1]; print "Year (260\$c): $protoyear\r\n" if $marcprint; ## strip any separator chars at the end -- 2.7.0