From fff7c41f551d5d5f366e2e7d2b856a792ce8d0d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= <joonas.kylmala@helsinki.fi>
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 <nick@bywatersolutions.com>
Signed-off-by: Pasi Kallinen <pasi.kallinen@koha-suomi.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
Koha/Biblio.pm | 40 +++++++++++++++++++---------------------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm
index 79a5d37a61..f306d29664 100644
--- a/Koha/Biblio.pm
+++ b/Koha/Biblio.pm
@@ -511,33 +511,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.20.1