From 029d7bacf01ac9debe4ca21150d9c9c572f090da Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 25 May 2022 15:51:41 +0100 Subject: [PATCH] Bug 30744: Use RecordProcessor in get_marc_notes This patch utilises RecordProcessor to filter the MARC::Record for the right interface prior to constructing the marc notes array. We also remove the use of C4::XSLT for replacing AV values in the MARC fields in preference to using the RecordProcessor filter. Signed-off-by: David Nind Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/Biblio.pm | 22 ++++++++++++++++------ t/db_dependent/Koha/Biblio.t | 22 +++++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 4f77b5c914..c6924e146c 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -24,7 +24,6 @@ use URI; use URI::Escape qw( uri_escape_utf8 ); use C4::Koha qw( GetNormalizedISBN ); -use C4::XSLT qw( transformMARCXML4XSLT ); use Koha::Database; use Koha::DateUtils qw( dt_from_string ); @@ -42,6 +41,7 @@ use Koha::Items; use Koha::Libraries; use Koha::Old::Checkouts; use Koha::Recalls; +use Koha::RecordProcessor; use Koha::Suggestions; use Koha::Subscriptions; use Koha::SearchEngine; @@ -933,11 +933,22 @@ sub get_marc_notes { my ( $self, $params ) = @_; my $marcflavour = C4::Context->preference('marcflavour'); - my $opac = $params->{opac}; + my $opac = $params->{opac} // '0'; + my $interface = $params->{opac} ? 'opac' : 'intranet'; - my $scope = $marcflavour eq "UNIMARC"? '3..': '5..'; - my @marcnotes; + my $record = $params->{record} // $self->metadata->record; + my $record_processor = Koha::RecordProcessor->new( + { + filters => [ 'ViewPolicy', 'ExpandCodedFields' ], + options => { + interface => $interface, + frameworkcode => $self->frameworkcode + } + } + ); + $record_processor->process($record); + my $scope = $marcflavour eq "UNIMARC"? '3..': '5..'; #MARC21 specs indicate some notes should be private if first indicator 0 my %maybe_private = ( 541 => 1, @@ -949,9 +960,8 @@ sub get_marc_notes { my %hiddenlist = map { $_ => 1 } split( /,/, C4::Context->preference('NotesToHide')); - my $record = $params->{record} // $self->metadata->record; - $record = transformMARCXML4XSLT( $self->biblionumber, $record, $opac ); + my @marcnotes; foreach my $field ( $record->field($scope) ) { my $tag = $field->tag(); next if $hiddenlist{ $tag }; diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 890d4e9b90..dc9f0b9bcc 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -679,7 +679,7 @@ subtest 'subscriptions() tests' => sub { }; subtest 'get_marc_notes() MARC21 tests' => sub { - plan tests => 13; + plan tests => 14; $schema->storage->txn_begin; @@ -692,15 +692,26 @@ subtest 'get_marc_notes() MARC21 tests' => sub { MARC::Field->new( '505', '', '', a => 'Note2', u => 'http://someserver.com' ), MARC::Field->new( '520', '', '', a => 'Note3 skipped' ), MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ), - MARC::Field->new( '541', '', '', a => 'Note5' ), + MARC::Field->new( '544', '', '', a => 'Note5' ), MARC::Field->new( '590', '', '', a => 'CODE' ), + MARC::Field->new( '545', '', '', a => 'Invisible on OPAC' ), ); Koha::AuthorisedValueCategory->new({ category_name => 'TEST' })->store; - Koha::AuthorisedValue->new({ category => 'TEST', authorised_value => 'CODE', lib => 'Description should show', lib_opac => 'Description should show OPAC' })->store; + Koha::AuthorisedValue->new( + { + category => 'TEST', + authorised_value => 'CODE', + lib => 'Description should show', + lib_opac => 'Description should show OPAC' + } + )->store; my $mss = Koha::MarcSubfieldStructures->find({tagfield => "590", tagsubfield => "a", frameworkcode => $biblio->frameworkcode }); $mss->update({ authorised_value => "TEST" }); + $mss = Koha::MarcSubfieldStructures->find({tagfield => "545", tagsubfield => "a", frameworkcode => $biblio->frameworkcode }); + $mss->update({ hidden => 1 }); + my $cache = Koha::Caches->get_instance; $cache->clear_from_cache("MarcStructure-0-"); $cache->clear_from_cache("MarcStructure-1-"); @@ -714,10 +725,11 @@ subtest 'get_marc_notes() MARC21 tests' => sub { is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' ); - is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Not shows if not opac" ); + is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Note shows if not opac (Hidden by Indicator)" ); is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' ); is( $notes->[5]->{marcnote}, 'Description should show', 'Authorised value is correctly parsed to show description rather than code' ); - is( @$notes, 6, 'No more notes' ); + is( $notes->[6]->{marcnote}, 'Invisible on OPAC', 'Note shows if not opac (Hidden by framework)' ); + is( @$notes, 7, 'No more notes' ); $notes = $biblio->get_marc_notes({ opac => 1 }); is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); -- 2.39.5