From 9b09b2558bd9715a0d4258df407af5d5aabd3e0c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Wed, 10 Jun 2020 20:20:19 +0300 Subject: [PATCH] Bug 11175: (follow-up) Return empty array if no components Signed-off-by: Nick Clemens Signed-off-by: Pasi Kallinen Signed-off-by: Martin Renvoize Signed-off-by: Andrew Nugged Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- Koha/Biblio.pm | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 2d35c94734..7748710b5b 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -492,33 +492,31 @@ sub components { return if (C4::Context->preference('marcflavour') ne 'MARC21'); - if (!defined($self->{_components})) { - my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $self->id }); - my $pf001 = $marc->field('001') || undef; - my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); - - if (defined($pf001)) { - my $pf003 = $marc->field('003') || undef; - my $searchstr; - - if (!defined($pf003)) { - # search for 773$w='Host001' - $searchstr = "rcn='".$pf001->data()."'"; - } else { - # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001') - $searchstr = "(rcn='".$pf001->data()."' and cni='".$pf003->data()."')"; - $searchstr .= " or rcn='".$pf003->data()." ".$pf001->data()."'"; - } + my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $self->id }); + my $pf001 = $marc->field('001') || undef; + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); - my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, undef ); + if (defined($pf001)) { + my $pf003 = $marc->field('003') || undef; + my $searchstr; - $self->{_components} = $results if ( defined($results) && scalar(@$results) ); + if (!defined($pf003)) { + # search for 773$w='Host001' + $searchstr = "rcn='".$pf001->data()."'"; } else { - warn "Record $self->id has no 001"; + # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001') + $searchstr = "(rcn='".$pf001->data()."' and cni='".$pf003->data()."')"; + $searchstr .= " or rcn='".$pf003->data()." ".$pf001->data()."'"; } + + my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, undef ); + + $self->{_components} = $results if ( defined($results) && scalar(@$results) ); + } else { + warn "Record $self->id has no 001"; } - return $self->{_components}; + return $self->{_components} || (); } =head3 subscriptions -- 2.39.5