View | Details | Raw Unified | Return to bug 12803
Collapse All | Expand All

(-)a/C4/HoldsQueue.pm (-10 / +41 lines)
Lines 29-34 use C4::Branch; Link Here
29
use C4::Circulation;
29
use C4::Circulation;
30
use C4::Members;
30
use C4::Members;
31
use C4::Biblio;
31
use C4::Biblio;
32
use C4::Dates qw/format_date/;
33
use Koha::Calendar;
34
use Koha::Database;
35
use Koha::DateUtils;
32
36
33
use List::Util qw(shuffle);
37
use List::Util qw(shuffle);
34
use List::MoreUtils qw(any);
38
use List::MoreUtils qw(any);
Lines 63-75 sub TransportCostMatrix { Link Here
63
    my $dbh   = C4::Context->dbh;
67
    my $dbh   = C4::Context->dbh;
64
    my $transport_costs = $dbh->selectall_arrayref("SELECT * FROM transport_cost",{ Slice => {} });
68
    my $transport_costs = $dbh->selectall_arrayref("SELECT * FROM transport_cost",{ Slice => {} });
65
69
70
    my $today = dt_from_string();
71
    my $calendars;
66
    my %transport_cost_matrix;
72
    my %transport_cost_matrix;
67
    foreach (@$transport_costs) {
73
    foreach (@$transport_costs) {
68
        my $from = $_->{frombranch};
74
        my $from     = $_->{frombranch};
69
        my $to = $_->{tobranch};
75
        my $to       = $_->{tobranch};
70
        my $cost = $_->{cost};
76
        my $cost     = $_->{cost};
71
        my $disabled = $_->{disable_transfer};
77
        my $disabled = $_->{disable_transfer};
72
        $transport_cost_matrix{$to}{$from} = { cost => $cost, disable_transfer => $disabled };
78
        $transport_cost_matrix{$to}{$from} = {
79
            cost             => $cost,
80
            disable_transfer => $disabled
81
        };
82
83
        if ( C4::Context->preference("HoldsQueueSkipClosed") ) {
84
            $calendars->{$from} ||= Koha::Calendar->new( branchcode => $from );
85
            $transport_cost_matrix{$to}{$from}{disable_transfer} ||=
86
              $calendars->{$from}->is_holiday( $today );
87
        }
88
73
    }
89
    }
74
    return \%transport_cost_matrix;
90
    return \%transport_cost_matrix;
75
}
91
}
Lines 601-612 sub _trim { Link Here
601
}
617
}
602
618
603
sub load_branches_to_pull_from {
619
sub load_branches_to_pull_from {
604
    my $static_branch_list = C4::Context->preference("StaticHoldsQueueWeight")
620
    my @branches_to_use;
605
      or return;
621
606
622
    my $static_branch_list = C4::Context->preference("StaticHoldsQueueWeight");
607
    my @branches_to_use = map _trim($_), split /,/, $static_branch_list;
623
    @branches_to_use = map { _trim($_) } split( /,/, $static_branch_list )
608
624
      if $static_branch_list;
609
    @branches_to_use = shuffle(@branches_to_use) if  C4::Context->preference("RandomizeHoldsQueueWeight");
625
626
    @branches_to_use =
627
      Koha::Database->new()->schema()->resultset('Branch')
628
      ->get_column('branchcode')->all()
629
      unless (@branches_to_use);
630
631
    @branches_to_use = shuffle(@branches_to_use)
632
      if C4::Context->preference("RandomizeHoldsQueueWeight");
633
634
    my $today = dt_from_string();
635
    if ( C4::Context->preference('HoldsQueueSkipClosed') ) {
636
        @branches_to_use = grep {
637
            !Koha::Calendar->new( branchcode => $_ )
638
              ->is_holiday( $today )
639
        } @branches_to_use;
640
    }
610
641
611
    return \@branches_to_use;
642
    return \@branches_to_use;
612
}
643
}
(-)a/installer/data/mysql/atomicupdate/bug_12803.sql (+2 lines)
Line 0 Link Here
1
INSERT INTO systempreferences (variable,value,explanation,type) VALUES
2
        ('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');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 149-154 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
149
('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'),
149
('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'),
150
('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'),
150
('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'),
151
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
151
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
152
('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'),
152
('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'),
153
('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'),
153
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
154
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
154
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
155
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-1 / +6 lines)
Lines 480-489 Circulation: Link Here
480
            - pref: ExpireReservesMaxPickUpDelayCharge
480
            - pref: ExpireReservesMaxPickUpDelayCharge
481
              class: currency
481
              class: currency
482
        -
482
        -
483
            - Satisfy holds from the libraries
483
            - Satisfy holds using items from the libraries
484
            - pref: StaticHoldsQueueWeight
484
            - pref: StaticHoldsQueueWeight
485
              class: multi
485
              class: multi
486
            - (as branchcodes, separated by commas; if empty, uses all libraries)
486
            - (as branchcodes, separated by commas; if empty, uses all libraries)
487
            - when they are
488
            - pref: HoldsQueueSkipClosed
489
              choices:
490
                  yes: open
491
                  no: open or closed
487
            - pref: RandomizeHoldsQueueWeight
492
            - pref: RandomizeHoldsQueueWeight
488
              choices:
493
              choices:
489
                  yes: in random order.
494
                  yes: in random order.
(-)a/t/db_dependent/HoldsQueue.t (-8 / +36 lines)
Lines 8-23 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use C4::Context;
11
use Test::More tests => 24;
12
13
use Data::Dumper;
12
use Data::Dumper;
14
13
15
use Test::More tests => 22;
14
use C4::Calendar;
16
15
use C4::Context;
17
18
use C4::Branch;
16
use C4::Branch;
19
use C4::ItemType;
17
use C4::ItemType;
20
use C4::Members;
18
use C4::Members;
19
use Koha::DateUtils;
20
use Koha::Cache;
21
21
22
BEGIN {
22
BEGIN {
23
    use FindBin;
23
    use FindBin;
Lines 55-60 my $itemtype = grep { $_->{notforloan} == 1 } @item_types Link Here
55
55
56
#Set up the stage
56
#Set up the stage
57
# Sysprefs and cost matrix
57
# Sysprefs and cost matrix
58
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
58
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
59
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
59
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
60
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
60
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
61
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
Lines 290-301 ok( @$holds_queue == 2, "Holds queue filling correct number for default holds po Link Here
290
ok( $holds_queue->[0]->{cardnumber} eq 'CARDNUMBER1', "Holds queue filling 1st correct hold for default holds policy 'from home library'");
291
ok( $holds_queue->[0]->{cardnumber} eq 'CARDNUMBER1', "Holds queue filling 1st correct hold for default holds policy 'from home library'");
291
ok( $holds_queue->[1]->{cardnumber} eq 'CARDNUMBER2', "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
292
ok( $holds_queue->[1]->{cardnumber} eq 'CARDNUMBER2', "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
292
293
294
# Test skipping hold picks for closed libraries.
295
# At this point in the test, we have 2 rows in the holds queue
296
# 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed
297
# and make today a holiday for MPL. When we run it again we should only
298
# have 1 row in the holds queue
299
C4::Context->set_preference('HoldsQueueSkipClosed', 1);
300
my $today = dt_from_string();
301
C4::Calendar->new( branchcode => 'MPL' )->insert_single_holiday(
302
    day         => $today->day(),
303
    month       => $today->month(),
304
    year        => $today->year(),
305
    title       => "$today",
306
    description => "$today",
307
);
308
C4::HoldsQueue::CreateQueue();
309
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
310
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" );
311
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
312
293
$dbh->do("DELETE FROM default_circ_rules");
313
$dbh->do("DELETE FROM default_circ_rules");
294
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
314
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
295
C4::HoldsQueue::CreateQueue();
315
C4::HoldsQueue::CreateQueue();
296
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
316
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
297
ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
317
is( scalar( @$holds_queue ), 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
298
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
318
319
# Test skipping hold picks for closed libraries without transport cost matrix
320
# At this point in the test, we have 3 rows in the holds queue
321
# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed
322
# and use our previously created holiday for MPL. 
323
# When we run it again we should only have 2 rows in the holds queue
324
C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 );
325
C4::HoldsQueue::CreateQueue();
326
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
327
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
299
328
300
# Bug 14297
329
# Bug 14297
301
$borrowernumber = AddMember(%data);
330
$borrowernumber = AddMember(%data);
302
- 

Return to bug 12803