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 <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 029d7bacf0)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2022-05-25 15:51:41 +01:00 committed by Lucas Gass
parent 2ad8c15dbf
commit 248dc2787e
2 changed files with 33 additions and 11 deletions

View file

@ -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 $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..';
my @marcnotes;
#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 };

View file

@ -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' );