From a4a243c76fa352a14daffaef7bf5af3b4d68c633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?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 --- Koha/Biblio.pm | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 192add3d74..8d21fd26d0 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -510,33 +510,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.11.0