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 &marc2ris
); );
our $utf; our $marcprint = 0; # Debug flag;
our $intype;
our $marcprint;
our $protoyear;
=head1 marc2bibtex - Convert from UNIMARC to RIS =head1 marc2bibtex - Convert from UNIMARC to RIS
@ -97,8 +93,7 @@ sub marc2ris {
my $output; my $output;
my $marcflavour = C4::Context->preference("marcflavour"); my $marcflavour = C4::Context->preference("marcflavour");
$intype = lc($marcflavour); my $intype = lc($marcflavour);
my $marcprint = 0; # Debug flag;
# Let's redirect stdout # Let's redirect stdout
open my $oldout, ">&STDOUT"; open my $oldout, ">&STDOUT";
@ -113,7 +108,6 @@ sub marc2ris {
if ( $intype eq "marc21" ) { if ( $intype eq "marc21" ) {
if ( $leader =~ /^.{9}a/ ) { if ( $leader =~ /^.{9}a/ ) {
print "<marc>---\r\n<marc>UTF-8 data\r\n" if $marcprint; print "<marc>---\r\n<marc>UTF-8 data\r\n" if $marcprint;
$utf = 1;
} }
else { else {
print "<marc>---\r\n<marc>MARC-8 data\r\n" if $marcprint; print "<marc>---\r\n<marc>MARC-8 data\r\n" if $marcprint;
@ -395,21 +389,13 @@ sub print_typetag {
## hints ## hints
my %typehash; my %typehash;
my $marcflavour = C4::Context->preference("marcflavour");
## the ukmarc here is just a guess my $intype = lc($marcflavour);
if (! defined $intype) { if ($intype eq "unimarc") {
## assume MARC21 as default %typehash = %unitypehash;
%typehash = %ustypehash;
}
elsif ($intype eq "marc21" || $intype eq "ukmarc") {
%typehash = %ustypehash;
}
elsif ($intype eq "unimarc") {
%typehash = %unitypehash;
} }
else { else {
## assume MARC21 as default %typehash = %ustypehash;
%typehash = %ustypehash;
} }
if (!defined $typeofrecord || !exists $typehash{$typeofrecord}) { if (!defined $typeofrecord || !exists $typehash{$typeofrecord}) {
@ -482,6 +468,8 @@ sub get_author {
## the sequence of the name parts is encoded either in indicator ## the sequence of the name parts is encoded either in indicator
## 1 (marc21) or 2 (unimarc) ## 1 (marc21) or 2 (unimarc)
my $marcflavour = C4::Context->preference("marcflavour");
my $intype = lc($marcflavour);
if ($intype eq "unimarc") { if ($intype eq "unimarc") {
$indicator = 2; $indicator = 2;
} }
@ -552,6 +540,8 @@ $clean_subtitle ||= q{};
$clean_title =~ s% *[/:;.]$%%; $clean_title =~ s% *[/:;.]$%%;
$clean_subtitle =~ s%^ *(.*) *[/:;.]$%$1%; $clean_subtitle =~ s%^ *(.*) *[/:;.]$%$1%;
my $marcflavour = C4::Context->preference("marcflavour");
my $intype = lc($marcflavour);
if (length($clean_title) > 0 if (length($clean_title) > 0
|| (length($clean_subtitle) > 0 && $intype ne "unimarc")) { || (length($clean_subtitle) > 0 && $intype ne "unimarc")) {
print "TI - ", $clean_title; print "TI - ", $clean_title;
@ -591,6 +581,8 @@ sub print_stitle {
print "T2 - ", $clean_title,"\r\n"; print "T2 - ", $clean_title,"\r\n";
} }
my $marcflavour = C4::Context->preference("marcflavour");
my $intype = lc($marcflavour);
if ($intype eq "unimarc") { if ($intype eq "unimarc") {
print "<marc>Series vol(\$v): ",$titlefield->subfield('v'),"\r\n" if $marcprint; print "<marc>Series vol(\$v): ",$titlefield->subfield('v'),"\r\n" if $marcprint;
if (length($titlefield->subfield('v')) > 0) { if (length($titlefield->subfield('v')) > 0) {
@ -726,6 +718,8 @@ sub print_pubinfo {
my $pubsub_publisher; my $pubsub_publisher;
my $pubsub_date; my $pubsub_date;
my $marcflavour = C4::Context->preference("marcflavour");
my $intype = lc($marcflavour);
if ($intype eq "unimarc") { if ($intype eq "unimarc") {
$pubsub_place = "a"; $pubsub_place = "a";
$pubsub_publisher = "c"; $pubsub_publisher = "c";
@ -758,7 +752,7 @@ sub print_pubinfo {
## the dates are free-form, so we want to extract ## the dates are free-form, so we want to extract
## a four-digit year and leave the rest as ## a four-digit year and leave the rest as
## "other info" ## "other info"
$protoyear = @$tuple[1]; my $protoyear = @$tuple[1];
print "<marc>Year (260\$c): $protoyear\r\n" if $marcprint; print "<marc>Year (260\$c): $protoyear\r\n" if $marcprint;
## strip any separator chars at the end ## strip any separator chars at the end