From 77158ca2d2032cbc70e05c5ae42b8e283eb18e65 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 22 Sep 2021 16:19:21 -0300 Subject: [PATCH] Bug 29084: Update article requests-related Koha::Biblio methods to use relationships This patch makes Koha::Patron->article_requests use the underlying DBIC relationship and _new_from_dbic instead of a plain search. It also refactors 'article_requests_current' and 'article_requests_finished' to use ->article_requests, as well as the new methods introduced by bug 29082 for filtering. No behavior change should take place. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Biblio.t \ t/db_dependent/ArticleRequests.t => SUCCESS: Tests pass! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D --- Koha/Biblio.pm | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index d1d84a7631..968a370b25 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -341,67 +341,44 @@ sub article_request_type_for_items { =head3 article_requests -my @requests = $biblio->article_requests + my $article_requests = $biblio->article_requests -Returns the article requests associated with this Biblio +Returns the article requests associated with this biblio =cut sub article_requests { - my ( $self, $borrower ) = @_; - - $self->{_article_requests} ||= Koha::ArticleRequests->search( { biblionumber => $self->biblionumber() } ); + my ( $self ) = @_; - return wantarray ? $self->{_article_requests}->as_list : $self->{_article_requests}; + return Koha::ArticleRequests->_new_from_dbic( scalar $self->_result->article_requests ); } =head3 article_requests_current -my @requests = $biblio->article_requests_current + my $current_article_requests = $biblio->article_requests_current -Returns the article requests associated with this Biblio that are incomplete +Returns the article requests associated with this biblio that are incomplete =cut sub article_requests_current { - my ( $self, $borrower ) = @_; - - $self->{_article_requests_current} ||= Koha::ArticleRequests->search( - { - biblionumber => $self->biblionumber(), - -or => [ - { status => Koha::ArticleRequest::Status::Requested }, - { status => Koha::ArticleRequest::Status::Pending }, - { status => Koha::ArticleRequest::Status::Processing } - ] - } - ); + my ( $self ) = @_; - return wantarray ? $self->{_article_requests_current}->as_list : $self->{_article_requests_current}; + return $self->article_requests->filter_by_current; } =head3 article_requests_finished -my @requests = $biblio->article_requests_finished + my $finished_article_requests = $biblio->article_requests_finished -Returns the article requests associated with this Biblio that are completed +Returns the article requests associated with this biblio that are completed =cut sub article_requests_finished { my ( $self, $borrower ) = @_; - $self->{_article_requests_finished} ||= Koha::ArticleRequests->search( - { - biblionumber => $self->biblionumber(), - -or => [ - { status => Koha::ArticleRequest::Status::Completed }, - { status => Koha::ArticleRequest::Status::Canceled } - ] - } - ); - - return wantarray ? $self->{_article_requests_finished}->as_list : $self->{_article_requests_finished}; + return $self->article_requests->filter_by_finished; } =head3 items -- 2.30.2