Bug 16442: Make C4::Ris 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

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-05-04 19:53:46 +01:00 committed by Brendan Gallagher
parent 7e30240e69
commit 87b181c6d4

View file

@ -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 "<marc>---\r\n<marc>UTF-8 data\r\n" if $marcprint;
$utf = 1;
}
else {
print "<marc>---\r\n<marc>MARC-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 "<marc>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 "<marc>Year (260\$c): $protoyear\r\n" if $marcprint;
## strip any separator chars at the end