From 5da5a2bbc53613c511ba9e7e1a93d9f71e993160 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 19 May 2021 10:19:33 +0000 Subject: [PATCH] Bug 28384: Add 'no_items' option to TransformMarcToKoha This patch adds a new option 'no_items' and uses it in the C4::Search::searchResults routine. We don't use the item info fetched here, so skipping those lines saves us time. Additionally, I fix an incorrect FIXME comment, and pass the ISBN returned by the routine above into GetNormalizedISBN to save another lookup TO test: 1 - Enable AmazonCoverImages system preference 2 - Search staff client with a term that returns books with covers 3 - Apply patch 4 - prove -v t/db_dependent/Biblio/TransformMarcToKoha.t 5 - Confirm searching works 6 - Confirm Amazon images display (normalized_isbn is used for these) Signed-off-by: David Nind Signed-off-by: Marcel de Rooy [EDIT] Amended, replacing a tab character. Signed-off-by: Jonathan Druart --- C4/Biblio.pm | 2 ++ C4/Search.pm | 8 ++++---- t/db_dependent/Biblio/TransformMarcToKoha.t | 11 ++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 45d1b31887..8aeef65c96 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2347,6 +2347,8 @@ sub TransformMarcToKoha { my %tables = ( biblio => 1, biblioitems => 1, items => 1 ); if( $limit_table eq 'items' ) { %tables = ( items => 1 ); + } elsif ( $limit_table eq 'no_items' ){ + %tables = ( biblio => 1, biblioitems => 1 ); } # The next call acknowledges Default as the authoritative framework diff --git a/C4/Search.pm b/C4/Search.pm index 18ea9f02af..03f7ecf591 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1637,12 +1637,12 @@ sub searchResults { } # handle which records to actually retrieve - my $times; + my $times; # Times is which record to process up to if ( $hits && $offset + $results_per_page <= $hits ) { $times = $offset + $results_per_page; } else { - $times = $hits; # FIXME: if $hits is undefined, why do we want to equal it? + $times = $hits; # If less hits than results_per_page+offset we go to the end } my $marcflavour = C4::Context->preference("marcflavour"); @@ -1696,13 +1696,13 @@ sub searchResults { : GetFrameworkCode($marcrecord->subfield($bibliotag,$bibliosubf)); SetUTF8Flag($marcrecord); - my $oldbiblio = TransformMarcToKoha( $marcrecord, $fw ); + my $oldbiblio = TransformMarcToKoha( $marcrecord, $fw, 'no_items' ); $oldbiblio->{result_number} = $i + 1; $oldbiblio->{normalized_upc} = GetNormalizedUPC( $marcrecord,$marcflavour); $oldbiblio->{normalized_ean} = GetNormalizedEAN( $marcrecord,$marcflavour); $oldbiblio->{normalized_oclc} = GetNormalizedOCLCNumber($marcrecord,$marcflavour); - $oldbiblio->{normalized_isbn} = GetNormalizedISBN(undef,$marcrecord,$marcflavour); + $oldbiblio->{normalized_isbn} = GetNormalizedISBN($oldbiblio->{isbn},$marcrecord,$marcflavour); # Use existing ISBN from record if we got one $oldbiblio->{content_identifier_exists} = 1 if ($oldbiblio->{normalized_isbn} or $oldbiblio->{normalized_oclc} or $oldbiblio->{normalized_ean} or $oldbiblio->{normalized_upc}); # edition information, if any diff --git a/t/db_dependent/Biblio/TransformMarcToKoha.t b/t/db_dependent/Biblio/TransformMarcToKoha.t index 60d7a95833..1a08ded4f0 100755 --- a/t/db_dependent/Biblio/TransformMarcToKoha.t +++ b/t/db_dependent/Biblio/TransformMarcToKoha.t @@ -111,7 +111,7 @@ subtest 'Testing _adjust_pubyear' => sub { }; subtest 'Test repeatable subfields' => sub { - plan tests => 2; + plan tests => 5; # Make 510x repeatable and 510y not Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '510' })->delete; @@ -125,6 +125,15 @@ subtest 'Test repeatable subfields' => sub { my $result = C4::Biblio::TransformMarcToKoha( $marc ); is( $result->{test}, '1 | 2', 'Check 510x for two values' ); is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' ); + + Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '510', tagsubfield => 'a', kohafield => 'biblio.field1' })->store; + Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); + $marc->append_fields( MARC::Field->new( '510', '', '', a => '1' ) ); # actually, we should only have one $y (BZ 24652) + + $result = C4::Biblio::TransformMarcToKoha( $marc, '', 'no_items' ); + is( $result->{test}, undef, 'Item field not returned when "no_items" passed' ); + is( $result->{norepeat}, undef, 'Item field not returned when "no_items" passed' ); + is( $result->{field1}, 1, 'Biblio field returned when "no_items" passed' ); }; # Cleanup -- 2.39.5