From 0b31c92fc33a65adece4be6437640aabb4fce605 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 21 Aug 2014 12:31:57 -0400 Subject: [PATCH] Bug 12803 - Enable feature when using Transport Cost Matrix Test plan: repeat test plan for first patch, but use transport cost matrix --- C4/HoldsQueue.pm | 20 ++++++++++++++++---- t/db_dependent/HoldsQueue.t | 36 ++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index ca68a10..7090c08 100755 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -67,13 +67,25 @@ sub TransportCostMatrix { my $dbh = C4::Context->dbh; my $transport_costs = $dbh->selectall_arrayref("SELECT * FROM transport_cost",{ Slice => {} }); + my $today = dt_from_string(); + my $calendars; my %transport_cost_matrix; foreach (@$transport_costs) { - my $from = $_->{frombranch}; - my $to = $_->{tobranch}; - my $cost = $_->{cost}; + my $from = $_->{frombranch}; + my $to = $_->{tobranch}; + my $cost = $_->{cost}; my $disabled = $_->{disable_transfer}; - $transport_cost_matrix{$to}{$from} = { cost => $cost, disable_transfer => $disabled }; + $transport_cost_matrix{$to}{$from} = { + cost => $cost, + disable_transfer => $disabled + }; + + if ( C4::Context->preference("HoldsQueueSkipClosed") ) { + $calendars->{$from} ||= C4::Calendar->new( branchcode => $from ); + $transport_cost_matrix{$to}{$from}{disable_transfer} ||= + $calendars->{$from}->isHoliday( $today->day(), $today->month(), $today->year() ); + } + } return \%transport_cost_matrix; } diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 5c63b43..c9aa435 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -8,7 +8,7 @@ use Modern::Perl; -use Test::More tests => 22; +use Test::More tests => 23; use Data::Dumper; use C4::Context; @@ -53,6 +53,7 @@ my $itemtype = grep { $_->{notforloan} == 1 } @item_types #Set up the stage # Sysprefs and cost matrix +C4::Context->set_preference('HoldsQueueSkipClosed', 0); $dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef, join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code)); $dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'"); @@ -289,19 +290,12 @@ ok( @$holds_queue == 2, "Holds queue filling correct number for default holds po ok( $holds_queue->[0]->{cardnumber} eq 'CARDNUMBER1', "Holds queue filling 1st correct hold for default holds policy 'from home library'"); ok( $holds_queue->[1]->{cardnumber} eq 'CARDNUMBER2', "Holds queue filling 2nd correct hold for default holds policy 'from home library'"); -$dbh->do("DELETE FROM default_circ_rules"); -$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); -C4::HoldsQueue::CreateQueue(); -$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 +# At this point in the test, we have 2 rows in the holds queue +# 1 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 ); +# have 1 row 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(), @@ -312,6 +306,24 @@ C4::Calendar->new( branchcode => 'MPL' )->insert_single_holiday( ); C4::HoldsQueue::CreateQueue(); $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); +ok( @$holds_queue == 1, "Holds not filled with items from closed libraries" ); +C4::Context->set_preference('HoldsQueueSkipClosed', 0); + +$dbh->do("DELETE FROM default_circ_rules"); +$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); +C4::HoldsQueue::CreateQueue(); +$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 without transport cost matrix +# 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 use our previously created holiday for MPL. +# When we run it again we should only have 2 rows in the holds queue +C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 ); +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 -- 1.7.2.5