From e6e3df084e0c8d20c9ba4d8e189c2de8906235fb Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Mon, 6 May 2019 20:31:03 +0000 Subject: [PATCH] Bug 21280: (QA follow-up) Use constant instead of Readonly in MarcEditor Signed-off-by: Josef Moravec --- Koha/MarcEditor.pm | 31 ++++++++++++++++--------------- authorities/authorities.pl | 2 +- cataloguing/addbiblio.pl | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Koha/MarcEditor.pm b/Koha/MarcEditor.pm index 594d0c5..b7c94c0 100644 --- a/Koha/MarcEditor.pm +++ b/Koha/MarcEditor.pm @@ -21,8 +21,7 @@ package Koha::MarcEditor; use Modern::Perl; -use Readonly; - +use C4::Biblio; use C4::ClassSource; use C4::Context; @@ -31,8 +30,10 @@ use Koha::DateUtils; use base qw(Class::Accessor); # Constants to refer to the standard editor types -Readonly our $EDITOR_BIBLIO => 'biblio'; -Readonly our $EDITOR_AUTHORITY => 'authority'; +use constant { + EDITOR_BIBLIO => 'biblio', + EDITOR_AUTHORITY => 'authority', +}; =head1 NAME @@ -47,7 +48,7 @@ Koha::MarcEditor - Koha MARC Editor class =head2 new my $editor = Koha::MarcEditor->new({ - type => $Koha::MarcEditor::EDITOR_BIBLIO, + type => Koha::MarcEditor::EDITOR_BIBLIO, tags => $self->{tags}, used_tags => $tagsUsedLib, mandatory_z3950 => $mandatory_z3950, @@ -152,7 +153,7 @@ sub build_tabs { } next if ( $self->{tags}->{$tag}->{$subfield}->{tab} ne $tabloop ); next if $self->{tags}->{$tag}->{$subfield}->{hidden} && $subfield ne '9' - && $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY; + && $self->{type} eq Koha::MarcEditor::EDITOR_AUTHORITY; next if ( $self->{tags}->{$tag}->{$subfield}->{kohafield} eq 'biblio.biblionumber' ); @@ -171,7 +172,7 @@ sub build_tabs { next if ( length $subfield != 1 ); next if ( $self->{tags}->{$tag}->{$subfield}->{tab} ne $tabloop ); next if $self->{tags}->{$tag}->{$subfield}->{hidden} && $subfield ne '9' - && $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY; + && $self->{type} eq Koha::MarcEditor::EDITOR_AUTHORITY; push( @subfields_data, $self->_create_input( @@ -188,11 +189,11 @@ sub build_tabs { next if ( $self->{tags}->{$tag}->{$subfield}->{tab} ne $tabloop ); next if ( $tag < 10 ); next if $self->{tags}->{$tag}->{$subfield}->{hidden} && $subfield ne '9' - && $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY; + && $self->{type} eq Koha::MarcEditor::EDITOR_AUTHORITY; next if ( ( $self->{tags}->{$tag}->{$subfield}->{hidden} <= -4 ) or ( $self->{tags}->{$tag}->{$subfield}->{hidden} >= 5 ) ) - and $self->{type} ne $Koha::MarcEditor::EDITOR_AUTHORITY + and $self->{type} ne Koha::MarcEditor::EDITOR_AUTHORITY and not ( $subfield eq "9" and exists($self->{tags}->{$tag}->{'a'}->{authtypecode}) and defined($self->{tags}->{$tag}->{'a'}->{authtypecode}) and @@ -239,11 +240,11 @@ sub build_tabs { foreach my $subfield ( sort( keys %{ $self->{tags}->{$tag} } ) ) { next if ( length $subfield != 1 ); next if $self->{tags}->{$tag}->{$subfield}->{hidden} && $subfield ne '9' - && $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY; + && $self->{type} eq Koha::MarcEditor::EDITOR_AUTHORITY; next if ( ( $self->{tags}->{$tag}->{$subfield}->{hidden} <= -4 ) or ( $self->{tags}->{$tag}->{$subfield}->{hidden} >= 5 ) ) - and $self->{type} ne $Koha::MarcEditor::EDITOR_AUTHORITY + and $self->{type} ne Koha::MarcEditor::EDITOR_AUTHORITY and not ( $subfield eq "9" and exists($self->{tags}->{$tag}->{'a'}->{authtypecode}) and defined($self->{tags}->{$tag}->{'a'}->{authtypecode}) and @@ -365,7 +366,7 @@ sub _build_authorized_values_list { $value = $default_source unless $value; } else { - my $branch_limit = $self->{type} ne $Koha::MarcEditor::EDITOR_AUTHORITY && C4::Context->userenv + my $branch_limit = $self->{type} ne Koha::MarcEditor::EDITOR_AUTHORITY && C4::Context->userenv ? C4::Context->userenv->{'branch'} : ''; my $query; @@ -459,7 +460,7 @@ sub _create_input { $subfield_data{z3950_mandatory} = $self->{mandatory_z3950}->{$tag.$subfield}; } - if ($self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY) { + if ($self->{type} eq Koha::MarcEditor::EDITOR_AUTHORITY) { # Authority subfield is hidden unless mandatory or contains something. $subfield_data{visibility} = "display:none;" if( $tagdef->{$subfield}->{hidden} and $value ne '' @@ -485,7 +486,7 @@ sub _create_input { # it's a subfield $9 linking to an authority record - see bug 2206 } - elsif ($self->{type} eq $Koha::MarcEditor::EDITOR_BIBLIO and + elsif ($self->{type} eq Koha::MarcEditor::EDITOR_BIBLIO and $subfield eq "9" and exists($tagdef->{'a'}->{authtypecode}) and defined($tagdef->{'a'}->{authtypecode}) and @@ -505,7 +506,7 @@ sub _create_input { } elsif ( $tagdef->{$subfield}->{authtypecode} ) { # when authorities auto-creation is allowed, do not set readonly - my $is_readonly = $self->{type} eq $Koha::MarcEditor::EDITOR_BIBLIO && !C4::Context->preference("BiblioAddsAuthorities"); + my $is_readonly = $self->{type} eq Koha::MarcEditor::EDITOR_BIBLIO && !C4::Context->preference("BiblioAddsAuthorities"); $subfield_data{marc_value} = { type => 'text', diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 9db6fe6..cec9d94 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -132,7 +132,7 @@ if ($breedingid) { my $editor = Koha::MarcEditor->new({ - type => $Koha::MarcEditor::EDITOR_AUTHORITY, + type => Koha::MarcEditor::EDITOR_AUTHORITY, tags => GetTagsLabels(1,$authtypecode), mandatory_z3950 => GetMandatoryFieldZ3950($authtypecode) }); diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index afcbd6c..9181952 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -261,7 +261,7 @@ $template->param( ); my $editor = Koha::MarcEditor->new({ - type => $Koha::MarcEditor::EDITOR_BIBLIO, + type => Koha::MarcEditor::EDITOR_BIBLIO, tags => GetMarcStructure( 1, $frameworkcode ), used_tags => GetUsedMarcStructure( $frameworkcode ), mandatory_z3950 => GetMandatoryFieldZ3950($frameworkcode), -- 2.1.4