From 0e880cf2336a9bac72519b41e8d4aca6bc5ed493 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Mon, 25 Apr 2022 20:52:17 -1000 Subject: [PATCH] Revert "Bug 28371: Passpreviously fetched branches and itemtypes through and fetch all needed AV at once" This reverts commit 8e1d5d4b8fa416992abd072a0453d280ea34348e. Signed-off-by: Fridolin Somers --- C4/Search.pm | 4 +--- C4/XSLT.pm | 59 ++++++++++++++++++---------------------------------- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index b38fdcada8..85a02bf5a2 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1995,9 +1995,7 @@ sub searchResults { ), fix_amps => 1, hidden_items => \@hiddenitems, - xslt_variables => $xslt_variables, - branches => \%branches, - itemtypes => \%itemtypes + xslt_variables => $xslt_variables } ); } diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 4b84bb8733..ca25d0db30 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -63,7 +63,7 @@ Replaces codes with authorized values in a MARC::Record object =cut sub transformMARCXML4XSLT { - my ($biblionumber, $record, $opac, $branches, $itemtypes, $av) = @_; + my ($biblionumber, $record, $opac) = @_; my $frameworkcode = GetFrameworkCode($biblionumber) || ''; my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 }); my @fields; @@ -73,40 +73,26 @@ sub transformMARCXML4XSLT { }; if ($@) { warn "PROBLEM WITH RECORD"; next; } my $marcflavour = C4::Context->preference('marcflavour'); + my $av = getAuthorisedValues4MARCSubfields($frameworkcode); foreach my $tag ( keys %$av ) { foreach my $field ( $record->field( $tag ) ) { - if ( defined $av->{ $tag } ) { + if ( $av->{ $tag } ) { my @new_subfields = (); - my $updated = 0; for my $subfield ( $field->subfields() ) { my ( $letter, $value ) = @$subfield; - if( defined $av->{ $tag }->{ $letter } ){ - my $category = $av->{$tag}->{$letter}->{category}; - # Replace the field value with the authorised value *except* for MARC21/NORMARC field 942$n (suppression in opac) - if( $category eq 'branches' ){ - $value = defined $branches->{$value} ? $branches->{$value}: q{} ; - $updated = 1; - } - elsif( $category eq 'itemtypes' ){ - $value = defined $itemtypes->{$value}->{translated_description} ? $itemtypes->{$value}->{translated_description} : q{}; - $updated = 1; - } - elsif ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) { - my $desc_field = $opac ? "lib_opac" : "lib"; - if ( defined $av->{$tag}->{$letter}->{$category}->{$value}->{$desc_field} ) { - $value = $av->{$tag}->{$letter}->{$category}->{$value}->{$desc_field} || $value; - $updated = 1; - } - } + # Replace the field value with the authorised value *except* for MARC21 field 942$n (suppression in opac) + if ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) { + $value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib, undef, $opac ) + if $av->{ $tag }->{ $letter }; } push( @new_subfields, $letter, $value ); - } + } $field ->replace_with( MARC::Field->new( $tag, $field->indicator(1), $field->indicator(2), @new_subfields - ) ) if $updated; + ) ); } } } @@ -124,17 +110,15 @@ sub getAuthorisedValues4MARCSubfields { my ($frameworkcode) = @_; unless ( $authval_per_framework{ $frameworkcode } ) { my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield, authorised_value + my $sth = $dbh->prepare("SELECT DISTINCT tagfield, tagsubfield FROM marc_subfield_structure WHERE authorised_value IS NOT NULL AND authorised_value!='' AND frameworkcode=?"); $sth->execute( $frameworkcode ); my $av = { }; - while ( my ( $tag, $letter, $category ) = $sth->fetchrow() ) { - my $authorised_values = { map { $_->{authorised_value} => $_ } @{ Koha::AuthorisedValues->search({ category => $category })->unblessed } }; - $av->{ $tag }->{ $letter }->{category} = $category; - $av->{ $tag }->{ $letter }->{$category} = $authorised_values unless ( $category eq 'itemtypes' || $category eq 'branches' ); + while ( my ( $tag, $letter ) = $sth->fetchrow() ) { + $av->{ $tag }->{ $letter } = 1; } $authval_per_framework{ $frameworkcode } = $av; } @@ -267,11 +251,6 @@ sub XSLTParse4Display { my $hidden_items = $params->{hidden_items} || []; my $variables = $params->{xslt_variables}; my $items_rs = $params->{items_rs}; - my $branches = $params->{branches}; - my $itemtypes = $params->{itemtypes}; - - $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; die "Mandatory \$params->{xsl_syspref} was not provided, called with biblionumber $params->{biblionumber}" if not defined $params->{xsl_syspref}; @@ -279,13 +258,12 @@ sub XSLTParse4Display { my $xslfilename = get_xsl_filename( $xslsyspref); # grab the XML, run it through our stylesheet, push it out to the browser - my $authorised_values = getAuthorisedValues4MARCSubfields(""); - my $record = transformMARCXML4XSLT($biblionumber, $orig_record, undef, $branches, $itemtypes, $authorised_values ); + my $record = transformMARCXML4XSLT($biblionumber, $orig_record); my $itemsxml; if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) { $itemsxml = ""; #We don't use XSLT for items display on these pages } else { - $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs, $branches, $itemtypes); + $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs); } my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); @@ -346,7 +324,7 @@ Is only used in this module currently. =cut sub buildKohaItemsNamespace { - my ($biblionumber, $hidden_items, $items_rs, $branches, $itemtypes) = @_; + my ($biblionumber, $hidden_items, $items_rs) = @_; $hidden_items ||= []; @@ -366,6 +344,9 @@ sub buildKohaItemsNamespace { my $ccodes = { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) }; + my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' })->as_list; + + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; my $xml = ''; my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } ); my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2'; @@ -430,8 +411,8 @@ sub buildKohaItemsNamespace { else { $status = "available"; } - my $homebranch = C4::Koha::xml_escape($branches->{$item->homebranch}); - my $holdingbranch = C4::Koha::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 = 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); -- 2.39.5