Bugzilla – Attachment 144847 Details for
Bug 32528
Koha::Item->safe_to_delete should short-circuit earlier
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32528: Mkae safe_to_delete exit earlier on error conditions
Bug-32528-Mkae-safetodelete-exit-earlier-on-error-.patch (text/plain), 2.37 KB, created by
Nick Clemens (kidclamp)
on 2022-12-27 13:07:56 UTC
(
hide
)
Description:
Bug 32528: Mkae safe_to_delete exit earlier on error conditions
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2022-12-27 13:07:56 UTC
Size:
2.37 KB
patch
obsolete
>From c0ccd02f028730c448d3e54a6aba1246a4318445 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 26 Dec 2022 15:43:16 -0300 >Subject: [PATCH] Bug 32528: Mkae safe_to_delete exit earlier on error > conditions > >This patch makes the `Koha::Item->safe_to_delete` method return right >after one of the checked conditions is met. This way we avoid further DB >queries and processing. > >No behavior change is expected > >To test: >1. Run: > $ kshell > k$ prove t/db_dependent/Koha/Item.t >=> SUCCESS: Tests pass! >2. Apply this patch >3. Repeat 1 >=> SUCCESS: Tests STILL pass! >4. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/Item.pm | 18 ++++++------------ > 1 file changed, 6 insertions(+), 12 deletions(-) > >diff --git a/Koha/Item.pm b/Koha/Item.pm >index 1174519483..b17f97bb32 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -289,24 +289,22 @@ returns 1 if the item is safe to delete, > sub safe_to_delete { > my ($self) = @_; > >- my $error; >+ return Koha::Result::Boolean->new(0)->add_message({ message => "book_on_loan" }) >+ if $self->checkout; > >- $error = "book_on_loan" if $self->checkout; >- >- $error = "not_same_branch" >+ return Koha::Result::Boolean->new(0)->add_message({ message => "not_same_branch" }) > if defined C4::Context->userenv > and !C4::Context->IsSuperLibrarian() > and C4::Context->preference("IndependentBranches") > and ( C4::Context->userenv->{branch} ne $self->homebranch ); > >- # check it doesn't have a waiting reserve >- $error = "book_reserved" >+ return Koha::Result::Boolean->new(0)->add_message({ message => "book_reserved" }) > if $self->holds->filter_by_found->count; > >- $error = "linked_analytics" >+ return Koha::Result::Boolean->new(0)->add_message({ message => "linked_analytics" }) > if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0; > >- $error = "last_item_for_hold" >+ return Koha::Result::Boolean->new(0)->add_message({ message => "last_item_for_hold" }) > if $self->biblio->items->count == 1 > && $self->biblio->holds->search( > { >@@ -314,10 +312,6 @@ sub safe_to_delete { > } > )->count; > >- if ( $error ) { >- return Koha::Result::Boolean->new(0)->add_message({ message => $error }); >- } >- > return Koha::Result::Boolean->new(1); > } > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32528
:
144842
|
144847
|
144901
|
144925
|
144938