From df03d073b731036a49507f61cdcc402f83d505db Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 26 Apr 2022 10:42:54 +0000 Subject: [PATCH] Bug 28371: (follow-up) Fetch values if not passed There are two places where transformMARC4XSLT is called ouside of XSLTParse4Display ILS-DI if expanding avs get_marc_notes The first was pushed after the initial patches here (bug 26195) The second will only take effect if a notes field is mapped to an av This patch adds a fallback in transformMARC4XSLT to cover these uses and fixes a wrong call in tests --- C4/XSLT.pm | 6 ++++++ t/db_dependent/XSLT.t | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 4b84bb8733..c4a5ec44b9 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -73,6 +73,12 @@ sub transformMARCXML4XSLT { }; if ($@) { warn "PROBLEM WITH RECORD"; next; } my $marcflavour = C4::Context->preference('marcflavour'); + + # FIXME: This should properly use the cache in the future, but is here to save on performance where possible + $av = getAuthorisedValues4MARCSubfields("") unless $av; + $branches = { map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' })->as_list } unless $branches; + $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } } unless $itemtypes; + foreach my $tag ( keys %$av ) { foreach my $field ( $record->field( $tag ) ) { if ( defined $av->{ $tag } ) { diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index a33d8a7e56..18279b7a25 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -79,10 +79,10 @@ subtest 'transformMARCXML4XSLT tests' => sub { $av->{952}->{a}->{$auth_val->category}->{$auth_val->authorised_value}->{lib} = ""; $record->field(952)->update( a => $auth_val->authorised_value, c => $branch_2->branchcode, d => $itemtype_2->itemtype ); - C4::XSLT::transformMARCXML4XSLT( 3, $record, $branches, $itemtypes, $av ); + C4::XSLT::transformMARCXML4XSLT( 3, $record, 0, $branches, $itemtypes, $av ); is($record->subfield( '952', 'a' ),$auth_val->authorised_value,'952$a is not transformed when value found but blank'); - is($record->subfield( '952', 'c' ),$branch_2->branchcode,'952$c is returned unaltered invalid branchcode'); - is($record->subfield( '952', 'd' ),$itemtype_2->itemtype,'952$d is returned unaltered when invalid itemtype'); + is($record->subfield( '952', 'c' ),"",'952$c is returned blank when invalid branchcode'); + is($record->subfield( '952', 'd' ),"",'952$d is returned blank when invalid itemtype'); }; -- 2.30.2