Bugzilla – Attachment 155823 Details for
Bug 30825
Get rid of GetReservesControlBranch
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30825: Move holds_control_library to Koha::Policy::Holds
Bug-30825-Move-holdscontrollibrary-to-KohaPolicyHo.patch (text/plain), 9.81 KB, created by
Jonathan Druart
on 2023-09-18 14:18:35 UTC
(
hide
)
Description:
Bug 30825: Move holds_control_library to Koha::Policy::Holds
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-09-18 14:18:35 UTC
Size:
9.81 KB
patch
obsolete
>From f61dee466d6f075547e6214caca893f1783ba2df Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 7 Jun 2023 14:28:42 +0200 >Subject: [PATCH] Bug 30825: Move holds_control_library to Koha::Policy::Holds > >--- > C4/Reserves.pm | 7 ++-- > Koha/Item.pm | 22 ++---------- > Koha/Policy/Holds.pm | 58 ++++++++++++++++++++++++++++++ > opac/opac-reserve.pl | 2 +- > t/db_dependent/Koha/Item.t | 25 +------------ > t/db_dependent/Koha/Policy/Holds.t | 54 ++++++++++++++++++++++++++++ > 6 files changed, 120 insertions(+), 48 deletions(-) > create mode 100644 Koha/Policy/Holds.pm > create mode 100755 t/db_dependent/Koha/Policy/Holds.t > >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index a28e3dcba35..36257378852 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -47,6 +47,7 @@ use Koha::Libraries; > use Koha::Old::Holds; > use Koha::Patrons; > use Koha::Plugins; >+use Koha::Policy::Holds; > > use List::MoreUtils qw( any ); > >@@ -937,7 +938,7 @@ sub CheckReserves { > next if $res->{item_group_id} && ( !$item->item_group || $item->item_group->id != $res->{item_group_id} ); > next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype; > $patron //= Koha::Patrons->find( $res->{borrowernumber} ); >- my $branch = $item->holds_control_library( $patron ); >+ my $branch = Koha::Policy::Holds->holds_control_library( $item, $patron ); > my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype); > next if ($branchitemrule->{'holdallowed'} eq 'not_allowed'); > next if (($branchitemrule->{'holdallowed'} eq 'from_home_library') && ($item->homebranch ne $patron->branchcode)); >@@ -1357,7 +1358,7 @@ sub IsAvailableForItemLevelRequest { > return 0 unless $destination; > return 0 unless $destination->pickup_location; > return 0 unless $item->can_be_transferred( { to => $destination } ); >- my $reserves_control_branch = $item->holds_control_library( $patron ); >+ my $reserves_control_branch = Koha::Policy::Holds->holds_control_library( $item, $patron ); > my $branchitemrule = > C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype ); > my $home_library = Koha::Libraries->find( {branchcode => $item->homebranch} ); >@@ -1406,7 +1407,7 @@ sub ItemsAnyAvailableAndNotRestricted { > my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } )->as_list; > > foreach my $i (@items) { >- my $reserves_control_branch = $i->holds_control_library( $param->{patron} ); >+ my $reserves_control_branch = Koha::Policy::Holds->holds_control_library( $i, $param->{patron} ); > my $branchitemrule = > C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype ); > my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } ); >diff --git a/Koha/Item.pm b/Koha/Item.pm >index e98387cecb5..0d54979dd01 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -54,6 +54,7 @@ use Koha::SearchEngine::Indexer; > use Koha::StockRotationItem; > use Koha::StockRotationRotas; > use Koha::TrackedLinks; >+use Koha::Policy::Holds; > > use base qw(Koha::Object); > >@@ -483,25 +484,6 @@ sub holds { > return Koha::Holds->_new_from_dbic( $holds_rs ); > } > >-=head3 holds_control_library >- >- my $control_library = $item->holds_control_library( $patron ); >- >-Given a I<Koha::Patron> object, this method returns a library id, for >-the library that is to be used for calculating circulation rules. It relies >-on the B<ReservesControlBranch> system preference. >- >-=cut >- >-sub holds_control_library { >- my ( $self, $patron ) = @_; >- >- return ( >- C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary' ) >- ? $self->homebranch >- : $patron->branchcode; >-} >- > =head3 request_transfer > > my $transfer = $item->request_transfer( >@@ -759,7 +741,7 @@ sub pickup_locations { > > my $patron = $params->{patron}; > >- my $circ_control_branch = $self->holds_control_library( $patron ); >+ my $circ_control_branch = Koha::Policy::Holds->holds_control_library( $self, $patron ); > my $branchitemrule = > C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype ); > >diff --git a/Koha/Policy/Holds.pm b/Koha/Policy/Holds.pm >new file mode 100644 >index 00000000000..f08eee67405 >--- /dev/null >+++ b/Koha/Policy/Holds.pm >@@ -0,0 +1,58 @@ >+package Koha::Policy::Holds; >+ >+# Copyright 2023 Koha Development team >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use C4::Context; >+ >+=head1 NAME >+ >+Koha::Policy::Holds - module to deal with holds policy >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=head3 new >+ >+=cut >+ >+sub new { >+ return bless {}, shift; >+} >+ >+=head3 holds_control_library >+ >+ my $control_library = Koha::Policy::Holds->holds_control_library( $item, $patron ); >+ >+Given I<Koha::Item> and I<Koha::Patron> objects, this method returns a library id, for >+the library that is to be used for calculating circulation rules. It relies >+on the B<ReservesControlBranch> system preference. >+ >+=cut >+ >+sub holds_control_library { >+ my ( $class, $item, $patron ) = @_; >+ >+ return ( C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary' ) >+ ? $item->homebranch >+ : $patron->branchcode; >+} >+ >+1; >diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl >index 3e1878e9ccc..38150b04df9 100755 >--- a/opac/opac-reserve.pl >+++ b/opac/opac-reserve.pl >@@ -477,7 +477,7 @@ foreach my $biblioNum (@biblionumbers) { > $item_info->{hosttitle} = Koha::Biblios->find( $item_info->{biblionumber} )->title; > } > >- my $branch = $item->holds_control_library( $patron ); >+ my $branch = Koha::Policy::Holds->holds_control_library( $item, $patron ); > > my $policy_holdallowed = > CanItemBeReserved( $patron, $item, undef, { get_from_cache => 1 } )->{status} eq 'OK' && >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index d7f530da7e2..176e8feed17 100755 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > use utf8; > >-use Test::More tests => 31; >+use Test::More tests => 30; > use Test::Exception; > use Test::MockModule; > >@@ -2295,26 +2295,3 @@ subtest 'current_branchtransfers relationship' => sub { > > $schema->storage->txn_rollback; > }; >- >-subtest 'holds_control_library() tests' => sub { >- >- plan tests => 2; >- >- $schema->storage->txn_begin; >- >- my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); >- my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); >- >- my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_1->id } }); >- my $item = $builder->build_sample_item({ library => $library_2->id }); >- >- t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); >- >- is( $item->holds_control_library( $patron ), $library_2->id ); >- >- t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); >- >- is( $item->holds_control_library( $patron ), $library_1->id ); >- >- $schema->storage->txn_rollback; >-}; >diff --git a/t/db_dependent/Koha/Policy/Holds.t b/t/db_dependent/Koha/Policy/Holds.t >new file mode 100755 >index 00000000000..54e3845a916 >--- /dev/null >+++ b/t/db_dependent/Koha/Policy/Holds.t >@@ -0,0 +1,54 @@ >+#!/usr/bin/perl >+ >+# Copyright 2023 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+ >+use Koha::Database; >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'holds_control_library() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library_1->id } } ); >+ my $item = $builder->build_sample_item( { library => $library_2->id } ); >+ >+ t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); >+ >+ my $policy = Koha::Policy::Holds->new; >+ >+ is( $policy->holds_control_library( $item, $patron ), $library_2->id ); >+ >+ t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); >+ >+ is( $policy->holds_control_library( $item, $patron ), $library_1->id ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.25.1
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 30825
:
135248
|
135249
|
135250
|
135275
|
135276
|
135277
|
135281
|
135488
|
135489
|
135490
|
152100
|
152101
|
152102
|
152103
|
152104
|
155820
|
155821
|
155822
|
155823
|
155824
|
155825
|
155826
|
155827