From c8167ae70710cdd72c8fdbf48049bc54701bb91b 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 (cherry picked from commit 029d7bacf01ac9debe4ca21150d9c9c572f090da) Signed-off-by: Lucas Gass (cherry picked from commit 248dc2787eaa496dfd1c0984fab49d8d76efc6fd) Signed-off-by: Arthur Suzuki --- Koha/Biblio.pm | 22 ++++++++++++++++------ t/db_dependent/Koha/Biblio.t | 23 ++++++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index c6899e4faf..848e292f54 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 ); @@ -41,6 +40,7 @@ use Koha::Item::Transfer::Limits; use Koha::Items; use Koha::Libraries; use Koha::Old::Checkouts; +use Koha::RecordProcessor; use Koha::Suggestions; use Koha::Subscriptions; use Koha::SearchEngine; @@ -924,11 +924,22 @@ sub get_marc_notes { my ( $self, $params ) = @_; my $marcflavour = $params->{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, @@ -940,9 +951,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 206606b295..c18ed47c1b 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -671,7 +671,7 @@ subtest 'subscriptions() tests' => sub { }; subtest 'get_marc_notes() MARC21 tests' => sub { - plan tests => 13; + plan tests => 14; $schema->storage->txn_begin; @@ -684,15 +684,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-"); @@ -706,10 +717,12 @@ 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({ marcflavour => 'MARC21', opac => 1 }); is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); -- 2.39.5