From 3477f72452a2e3fbf01d47617dc0a4f2240fdf39 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 21 Aug 2014 11:22:30 -0400 Subject: [PATCH] Bug 12803 - Add ability to skip closed libraries when generating the holds queue The holds queue is typically generated many times a day in order to select items to fill holds. Often these items are to be sent to a different library. However, if the library whose item is picked to fill a hold is closed, that hold will remain unfilled even if there are other open libraries who own that item. It would be helpful if we could skip closed libraries for the purpose of selecting items to fill holds. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Create a record with two items on it, one at Branch A, and one at Branch B 4) Place a hold for pickup at Branch C 5) Generate the holds queue 6) Note which branch's item is selected for the hold 7) Enable the new system preference HoldsQueueSkipClosed 8) Add today as a holiday for that branch noted in step 6 9) Regenerate the holds queue 10) View the holds queue, notice the item selected is not from the closed branch! 11) prove t/db_dependent/HoldsQueue.t Signed-off by: Jason Robb --- C4/HoldsQueue.pm | 30 ++++++++++++++++---- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 10 ++++++ .../en/modules/admin/preferences/circulation.pref | 7 ++++- t/db_dependent/HoldsQueue.t | 26 ++++++++++++++--- 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 0d645bd..ca68a10 100755 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -30,6 +30,9 @@ use C4::Circulation; use C4::Members; use C4::Biblio; use C4::Dates qw/format_date/; +use C4::Calendar; +use Koha::Database; +use Koha::DateUtils; use List::Util qw(shuffle); use List::MoreUtils qw(any); @@ -582,12 +585,27 @@ sub _trim { } sub load_branches_to_pull_from { - my $static_branch_list = C4::Context->preference("StaticHoldsQueueWeight") - or return; - - my @branches_to_use = map _trim($_), split /,/, $static_branch_list; - - @branches_to_use = shuffle(@branches_to_use) if C4::Context->preference("RandomizeHoldsQueueWeight"); + my @branches_to_use; + + my $static_branch_list = C4::Context->preference("StaticHoldsQueueWeight"); + @branches_to_use = map { _trim($_) } split( /,/, $static_branch_list ) + if $static_branch_list; + + @branches_to_use = + Koha::Database->new()->schema()->resultset('Branch') + ->get_column('branchcode')->all() + unless (@branches_to_use); + + @branches_to_use = shuffle(@branches_to_use) + if C4::Context->preference("RandomizeHoldsQueueWeight"); + + my $today = dt_from_string(); + if ( C4::Context->preference('HoldsQueueSkipClosed') ) { + @branches_to_use = grep { + !C4::Calendar->new( branchcode => $_ ) + ->isHoliday( $today->day(), $today->month(), $today->year() ) + } @branches_to_use; + } return \@branches_to_use; } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 7eb08a8..6570148 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -132,6 +132,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('HighlightOwnItemsOnOPAC','0','','If on, and a patron is logged into the OPAC, items from his or her home library will be emphasized and shown first in search results and item details.','YesNo'), ('HighlightOwnItemsOnOPACWhich','PatronBranch','PatronBranch|OpacURLBranch','Decides which branch\'s items to emphasize. If PatronBranch, emphasize the logged in user\'s library\'s items. If OpacURLBranch, highlight the items of the Apache var BRANCHCODE defined in Koha\'s Apache configuration file.','Choice'), ('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'), +('HoldsQueueSkipClosed', '0', NULL, 'If enabled, any libraries that are closed when the holds queue is built will be ignored for the purpose of filling holds.', 'YesNo'), ('HomeOrHoldingBranch','holdingbranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check with independent branches on, and by search to determine which branch to choose for availability ','Choice'), ('HomeOrHoldingBranchReturn','homebranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check checking-in items','Choice'), ('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index de77bf3..f6cbd93 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8613,6 +8613,16 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = '3.17.00.XXX'; +if ( CheckVersion($DBversion) ) { + $dbh->do(" + INSERT INTO systempreferences (variable,value,explanation,type) VALUES + ('HoldsQueueSkipClosed', '0', 'If enabled, any libraries that are closed when the holds queue is built will be ignored for the purpose of filling holds.', 'YesNo') + "); + print "Upgrade to $DBversion done (Bug 12803 - Add ability to skip closed libraries when generating the holds queue)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 37c368c..a345503 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -429,10 +429,15 @@ Circulation: - pref: ExpireReservesMaxPickUpDelayCharge class: currency - - - Satisfy holds from the libraries + - Satisfy holds using items from the libraries - pref: StaticHoldsQueueWeight class: multi - (as branchcodes, separated by commas; if empty, uses all libraries) + - when they are + - pref: HoldsQueueSkipClosed + choices: + yes: open + no: open or closed - pref: RandomizeHoldsQueueWeight choices: yes: in random order. diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 0a96143..5c63b43 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -8,16 +8,14 @@ use Modern::Perl; -use C4::Context; - +use Test::More tests => 22; use Data::Dumper; -use Test::More tests => 21; - - +use C4::Context; use C4::Branch; use C4::ItemType; use C4::Members; +use Koha::DateUtils; BEGIN { use FindBin; @@ -298,6 +296,24 @@ $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" ); #warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue ); +# Test skipping hold picks for closed libraries. +# At this point in the test, we have 3 rows in the holds queue +# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed +# and make today a holiday for MPL. When we run it again we should only +# have 2 rows in the holds queue +C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 ); +my $today = dt_from_string(); +C4::Calendar->new( branchcode => 'MPL' )->insert_single_holiday( + day => $today->day(), + month => $today->month(), + year => $today->year(), + title => "$today", + description => "$today", +); +C4::HoldsQueue::CreateQueue(); +$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); +ok( @$holds_queue == 2, "Holds not filled with items from closed libraries" ); + # Cleanup $dbh->rollback; -- 1.7.2.5