From 7d1e4955feeccdc10b3933875493d03c64984a62 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 19 Jul 2023 10:52:40 +0100 Subject: [PATCH] Revert "Bug 33496: Add 'host_items' param to Koha::Biblio->items" This reverts commit aac8c1e36ea84deed0f4b9ad59f9f1bd44ba607f. --- Koha/Biblio.pm | 35 ++++++++--------------------------- t/db_dependent/Koha/Biblio.t | 14 +------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index c17c4359f0..85a72400be 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -471,17 +471,11 @@ Returns the related Koha::Items object for this biblio =cut sub items { - my ($self,$params) = @_; + my ($self) = @_; my $items_rs = $self->_result->items; - return Koha::Items->_new_from_dbic( $items_rs ) unless $params->{host_items}; - - my $host_itemnumbers = $self->_host_itemnumbers(); - my $params = { -or => [biblionumber => $self->id] }; - push @{$params->{'-or'}}, itemnumber => { -in => $host_itemnumbers } if $host_itemnumbers; - - return Koha::Items->search($params); + return Koha::Items->_new_from_dbic( $items_rs ); } =head3 host_items @@ -498,25 +492,12 @@ sub host_items { return Koha::Items->new->empty unless C4::Context->preference('EasyAnalyticalRecords'); - my $host_itemnumbers = $self->_host_itemnumbers; - - return Koha::Items->search( { itemnumber => { -in => $host_itemnumbers } } ); -} - -=head3 _host_itemnumbers - -my $host_itemnumber = $biblio->_host_itemnumbers(); - -Return the itemnumbers for analytical items on this record - -=cut - -sub _host_itemnumbers { - my ($self) = @_; - my $marcflavour = C4::Context->preference("marcflavour"); my $analyticfield = '773'; - if ( $marcflavour eq 'UNIMARC' ) { + if ( $marcflavour eq 'MARC21' ) { + $analyticfield = '773'; + } + elsif ( $marcflavour eq 'UNIMARC' ) { $analyticfield = '461'; } my $marc_record = $self->metadata->record; @@ -524,9 +505,9 @@ sub _host_itemnumbers { foreach my $field ( $marc_record->field($analyticfield) ) { push @itemnumbers, $field->subfield('9'); } - return \@itemnumbers; -} + return Koha::Items->search( { itemnumber => { -in => \@itemnumbers } } ); +} =head3 itemtype diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 09e747e6b2..ee3a7290ac 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -783,7 +783,7 @@ subtest 'get_marc_notes() UNIMARC tests' => sub { }; subtest 'host_items() tests' => sub { - plan tests => 7; + plan tests => 6; $schema->storage->txn_begin; @@ -819,18 +819,6 @@ subtest 'host_items() tests' => sub { is( ref($host_items), 'Koha::Items' ); is( $host_items->count, 0 ); - subtest 'test host_items param in items()' => sub { - plan tests => 4; - - my $items = $biblio->items; - is( $items->count, 1, "Without host_items param we only get the items on the biblio"); - $items = $biblio->items({ host_items => 1 }); - is( $items->count, 3, "With param host_items we get the biblio items plus analytics"); - is( ref($items), 'Koha::Items', "We correctly get an Items object"); - is_deeply( [ $items->get_column('itemnumber') ], - [ $item_1->itemnumber, $host_item_1->itemnumber, $host_item_2->itemnumber ] ); - }; - $schema->storage->txn_rollback; }; -- 2.20.1