From 77979a03b44ff55b5aba889ca031b5251f0c3e63 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 22 Jan 2020 16:21:22 +0100 Subject: [PATCH] Bug 24467: Remove _count methods introduced for API use This patch removes some methods that were introduced for API usage in the first iteration of the object embedding development effort. Those methods were obsoleted by bug 24528, which introduces a smarter way for Koha::Object->to_api to embed *_count attributes on the output structure based on the relationships and a call to ->count. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Biblio.t => SUCCESS: Tests pass 3. Sign off :-D Signed-off-by: David Nind Signed-off-by: Josef Moravec Signed-off-by: Martin Renvoize --- Koha/Biblio.pm | 38 ++++-------------------------------- acqui/basket.pl | 4 ++-- acqui/parcel.pl | 2 +- t/db_dependent/Koha/Biblio.t | 28 ++++++++++++-------------- 4 files changed, 20 insertions(+), 52 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 9c0b6e8762..d8d1f09a3c 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -100,18 +100,18 @@ sub orders { =head3 active_orders_count -my $orders_count = $biblio->active_orders_count(); +my $active_orders = $biblio->active_orders(); -Returns the number of active acquisition orders related to this biblio. +Returns the active acquisition orders related to this biblio. An order is considered active when it is not cancelled (i.e. when datecancellation is not undef). =cut -sub active_orders_count { +sub active_orders { my ( $self ) = @_; - return $self->orders->search({ datecancellationprinted => undef })->count; + return $self->orders->search({ datecancellationprinted => undef }); } =head3 can_article_request @@ -411,20 +411,6 @@ sub items { return Koha::Items->_new_from_dbic( $items_rs ); } -=head3 items_count - -my $items_count = $biblio->items(); - -Returns the count of the the related Koha::Items object for this biblio - -=cut - -sub items_count { - my ($self) = @_; - - return $self->_result->items->count; -} - =head3 itemtype my $itemtype = $biblio->itemtype(); @@ -517,22 +503,6 @@ sub subscriptions { return $self->{_subscriptions}; } -=head3 subscriptions_count - -my $subscriptions_count = $self->subscriptions_count - -Returns the count of the the related Koha::Subscriptions object for this biblio - -IMPORTANT: this method is temporary and should not be used. - -=cut - -sub subscriptions_count { - my ($self) = @_; - - return $self->subscriptions->count; -} - =head3 has_items_waiting_or_intransit my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit diff --git a/acqui/basket.pl b/acqui/basket.pl index 65ed547452..d248f11c92 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -136,7 +136,7 @@ if ( $op eq 'delete_confirm' ) { foreach my $myorder (@orders){ my $biblionumber = $myorder->{'biblionumber'}; my $biblio = Koha::Biblios->find( $biblionumber ); - my $countbiblio = $biblio->active_orders_count; + my $countbiblio = $biblio->active_orders->count; my $ordernumber = $myorder->{'ordernumber'}; my $cnt_subscriptions = $biblio->subscriptions->count; my $itemcount = $biblio->items->count; @@ -477,7 +477,7 @@ sub get_order_infos { my $biblionumber = $order->{'biblionumber'}; if ( $biblionumber ) { # The biblio still exists my $biblio = Koha::Biblios->find( $biblionumber ); - my $countbiblio = $biblio->active_orders_count; + my $countbiblio = $biblio->active_orders->count; my $ordernumber = $order->{'ordernumber'}; my $cnt_subscriptions = $biblio->subscriptions->count; diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 8139cabfb9..3fcc211b20 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -241,7 +241,7 @@ unless( defined $invoice->{closedate} ) { my $biblionumber = $line{'biblionumber'}; my $biblio = Koha::Biblios->find( $biblionumber ); - my $countbiblio = $biblio->active_orders_count; + my $countbiblio = $biblio->active_orders->count; my $ordernumber = $line{'ordernumber'}; my $order_object = Koha::Acquisition::Orders->find($ordernumber); my $cnt_subscriptions = $biblio ? $biblio->subscriptions->count: 0; diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 363a080abf..75921933c6 100644 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -92,15 +92,15 @@ subtest 'hidden_in_opac() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'items() and items_count() tests' => sub { +subtest 'items() tests' => sub { - plan tests => 5; + plan tests => 4; $schema->storage->txn_begin; my $biblio = $builder->build_sample_biblio(); - is( $biblio->items_count, 0, 'No items, count is 0' ); + is( $biblio->items->count, 0, 'No items, count is 0' ); my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); @@ -108,7 +108,6 @@ subtest 'items() and items_count() tests' => sub { my $items = $biblio->items; is( ref($items), 'Koha::Items', 'Returns a Koha::Items resultset' ); is( $items->count, 2, 'Two items in resultset' ); - is( $biblio->items_count, $items->count, 'items_count returns the expected value' ); my @items = $biblio->items->as_list; is( scalar @items, 2, 'Same result, but in list context' ); @@ -496,19 +495,19 @@ subtest 'suggestions() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'orders() and active_orders_count() tests' => sub { +subtest 'orders() and active_orders() tests' => sub { - plan tests => 4; + plan tests => 5; $schema->storage->txn_begin; my $biblio = $builder->build_sample_biblio(); - my $orders = $biblio->orders; - my $active_orders_count = $biblio->active_orders_count; + my $orders = $biblio->orders; + my $active_orders = $biblio->active_orders; is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' ); - is( $orders->count, $active_orders_count, '->orders_count returns the count for the resultset' ); + is( $biblio->orders->count, $biblio->active_orders->count, '->orders_count returns the count for the resultset' ); # Add a couple orders foreach (1..2) { @@ -534,17 +533,18 @@ subtest 'orders() and active_orders_count() tests' => sub { ); $orders = $biblio->orders; - $active_orders_count = $biblio->active_orders_count; + $active_orders = $biblio->active_orders; is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' ); - is( $orders->count, $active_orders_count + 2, '->active_orders_count returns the rigt count' ); + is( ref($active_orders), 'Koha::Acquisition::Orders', 'Result type is correct' ); + is( $orders->count, $active_orders->count + 2, '->active_orders_count returns the rigt count' ); $schema->storage->txn_rollback; }; -subtest 'subscriptions() and subscriptions_count() tests' => sub { +subtest 'subscriptions() tests' => sub { - plan tests => 6; + plan tests => 4; $schema->storage->txn_begin; @@ -555,7 +555,6 @@ subtest 'subscriptions() and subscriptions_count() tests' => sub { 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object' ); is( $subscriptions->count, 0, 'Koha::Biblio->subscriptions should return the correct number of subscriptions'); - is( $biblio->subscriptions_count, 0, 'subscriptions_count returns the correct number' ); # Add two subscriptions foreach (1..2) { @@ -572,7 +571,6 @@ subtest 'subscriptions() and subscriptions_count() tests' => sub { 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object' ); is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions'); - is( $biblio->subscriptions_count, 2, 'subscriptions_count returns the correct number' ); $schema->storage->txn_rollback; }; -- 2.39.5