From 17a1b0cec5b65176b166327400ba103567e83994 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 21 Jul 2021 17:01:23 +1200 Subject: [PATCH] Bug 28734: Parse display in $biblio->get_marc_notes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1. Go to Koha Administration, MARC bibliographic frameworks 2. Edit a framework, find tag 590, edit the $z subfield to use an authorised value. 3. Do a catalogue search and edit a record using this framework. Edit 590$z and select an authorised value. Save the record. 4. Add the record to your cart. 5. View your cart. Click More Details. 6. Scroll down to the Notes section. Notice the authorised value code is displayed instead of the description. 7. Apply the patch, restart services. 8. Refresh your cart. Click More Details again if you need to. 9. Scroll down to the Notes section. The description of the authorised value should now be displayed. Sponsored-by: Catalyst IT Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: David Nind Signed-off-by: Joonas Kylmälä Bug 28734: (follow-up) Use transformMARCXML4XSLT and tests Confirm the following tests pass: - t/db_dependent/Koha/Biblio.t - t/db_dependent/XSLT.t Signed-off-by: David Nind Signed-off-by: Joonas Kylmälä Bug 28734: (QA follow-up) Fix test imports and readability Signed-off-by: Joonas Kylmälä Bug 28734: (QA follow-up) Update documentation about function usage We are now using the function from Koha::Biblio. Signed-off-by: Joonas Kylmälä Bug 28734: Remove unadvertised changes 1. Using $frameworkcode instead of the default '' is an unadvertised change. It would make sense to use $frameworkcode, but actually we must remove this parameter and always use the default, as we decided to make the default authoritative. I would prefer to not introduce this change, just in case.. 2. Restore good import (use plurals) Signed-off-by: Jonathan Druart --- C4/XSLT.pm | 19 ++++++++----------- Koha/Biblio.pm | 6 +++++- t/db_dependent/Koha/Biblio.t | 19 ++++++++++++++++--- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index a96d60b1ec..864158714a 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -31,8 +31,6 @@ use Koha::ItemTypes; use Koha::XSLT::Base; use Koha::Libraries; - - my $engine; #XSLT Handler object my %authval_per_framework; # Cache for tagfield-tagsubfield to decode per framework. @@ -60,12 +58,11 @@ C4::XSLT - Functions for displaying XSLT-generated content =head2 transformMARCXML4XSLT Replaces codes with authorized values in a MARC::Record object -Is only used in this module currently. =cut sub transformMARCXML4XSLT { - my ($biblionumber, $record) = @_; + my ($biblionumber, $record, $opac) = @_; my $frameworkcode = GetFrameworkCode($biblionumber) || ''; my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 }); my @fields; @@ -84,7 +81,7 @@ sub transformMARCXML4XSLT { my ( $letter, $value ) = @$subfield; # Replace the field value with the authorised value *except* for MARC21/NORMARC field 942$n (suppression in opac) if ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) { - $value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib ) + $value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib, undef, $opac ) if $av->{ $tag }->{ $letter }; } push( @new_subfields, $letter, $value ); @@ -397,13 +394,13 @@ sub buildKohaItemsNamespace { else { $status = "available"; } - my $homebranch = xml_escape($branches{$item->homebranch}); - my $holdingbranch = xml_escape($branches{$item->holdingbranch}); + my $homebranch = C4::Koha::xml_escape($branches{$item->homebranch}); + my $holdingbranch = C4::Koha::xml_escape($branches{$item->holdingbranch}); my $resultbranch = C4::Context->preference('OPACResultsLibrary') eq 'homebranch' ? $homebranch : $holdingbranch; - my $location = xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location); - my $ccode = xml_escape($item->ccode && exists $ccodes->{$item->ccode} ? $ccodes->{$item->ccode} : $item->ccode); - my $itemcallnumber = xml_escape($item->itemcallnumber); - my $stocknumber = xml_escape($item->stocknumber); + my $location = C4::Koha::xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location); + my $ccode = C4::Koha::xml_escape($item->ccode && exists $ccodes->{$item->ccode} ? $ccodes->{$item->ccode} : $item->ccode); + my $itemcallnumber = C4::Koha::xml_escape($item->itemcallnumber); + my $stocknumber = C4::Koha::xml_escape($item->stocknumber); $xml .= "" . "$homebranch" diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 26ee7abd96..4cd70ef388 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -24,6 +24,7 @@ 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 ); @@ -829,7 +830,10 @@ sub get_marc_notes { my %hiddenlist = map { $_ => 1 } split( /,/, C4::Context->preference('NotesToHide')); - foreach my $field ( $self->metadata->record->field($scope) ) { + my $record = $self->metadata->record; + $record = transformMARCXML4XSLT( $self->biblionumber, $record, $opac ); + + foreach my $field ( $record->field($scope) ) { my $tag = $field->tag(); next if $hiddenlist{ $tag }; next if $opac && $maybe_private{$tag} && !$field->indicator(1); diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 83de0634c6..d4c9e56e81 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -22,6 +22,9 @@ use Test::More tests => 14; use C4::Biblio qw( AddBiblio ModBiblio ); use Koha::Database; use Koha::Acquisition::Orders; +use Koha::AuthorisedValueCategories; +use Koha::AuthorisedValues; +use Koha::MarcSubfieldStructures; use t::lib::TestBuilder; use t::lib::Mocks; @@ -580,7 +583,7 @@ subtest 'subscriptions() tests' => sub { }; subtest 'get_marc_notes() MARC21 tests' => sub { - plan tests => 11; + plan tests => 13; $schema->storage->txn_begin; @@ -594,22 +597,32 @@ subtest 'get_marc_notes() MARC21 tests' => sub { 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( '590', '', '', a => 'CODE' ), ); + + 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; + my $mss = Koha::MarcSubfieldStructures->find({tagfield => "590", tagsubfield => "a", frameworkcode => $biblio->frameworkcode }); + $mss->update({ authorised_value => "TEST" }); + C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); $biblio = Koha::Biblios->find( $biblio->biblionumber); + my $notes = $biblio->get_marc_notes({ marcflavour => 'MARC21' }); 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->[4]->{marcnote}, 'Note5', 'Fifth note' ); - is( @$notes, 5, 'No more notes' ); + is( $notes->[5]->{marcnote}, 'Description should show', 'Authorised value is correctly parsed to show description rather than code' ); + is( @$notes, 6, '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' ); is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' ); is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' ); - is( @$notes, 4, 'No more notes' ); + is( $notes->[4]->{marcnote}, 'Description should show OPAC', 'Authorised value is correctly parsed for OPAC to show description rather than code' ); + is( @$notes, 5, 'No more notes' ); $schema->storage->txn_rollback; }; -- 2.39.5