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

(-)a/C4/HoldsQueue.pm (-10 / +39 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::DateUtils;
32
34
33
use List::Util qw(shuffle);
35
use List::Util qw(shuffle);
34
use List::MoreUtils qw(any);
36
use List::MoreUtils qw(any);
Lines 63-75 sub TransportCostMatrix { Link Here
63
    my $dbh   = C4::Context->dbh;
65
    my $dbh   = C4::Context->dbh;
64
    my $transport_costs = $dbh->selectall_arrayref("SELECT * FROM transport_cost",{ Slice => {} });
66
    my $transport_costs = $dbh->selectall_arrayref("SELECT * FROM transport_cost",{ Slice => {} });
65
67
68
    my $today = dt_from_string();
69
    my $calendars;
66
    my %transport_cost_matrix;
70
    my %transport_cost_matrix;
67
    foreach (@$transport_costs) {
71
    foreach (@$transport_costs) {
68
        my $from = $_->{frombranch};
72
        my $from     = $_->{frombranch};
69
        my $to = $_->{tobranch};
73
        my $to       = $_->{tobranch};
70
        my $cost = $_->{cost};
74
        my $cost     = $_->{cost};
71
        my $disabled = $_->{disable_transfer};
75
        my $disabled = $_->{disable_transfer};
72
        $transport_cost_matrix{$to}{$from} = { cost => $cost, disable_transfer => $disabled };
76
        $transport_cost_matrix{$to}{$from} = {
77
            cost             => $cost,
78
            disable_transfer => $disabled
79
        };
80
81
        if ( C4::Context->preference("HoldsQueueSkipClosed") ) {
82
            $calendars->{$from} ||= Koha::Calendar->new( branchcode => $from );
83
            $transport_cost_matrix{$to}{$from}{disable_transfer} ||=
84
              $calendars->{$from}->is_holiday( $today );
85
        }
86
73
    }
87
    }
74
    return \%transport_cost_matrix;
88
    return \%transport_cost_matrix;
75
}
89
}
Lines 601-612 sub _trim { Link Here
601
}
615
}
602
616
603
sub load_branches_to_pull_from {
617
sub load_branches_to_pull_from {
604
    my $static_branch_list = C4::Context->preference("StaticHoldsQueueWeight")
618
    my @branches_to_use;
605
      or return;
619
606
620
    my $static_branch_list = C4::Context->preference("StaticHoldsQueueWeight");
607
    my @branches_to_use = map _trim($_), split /,/, $static_branch_list;
621
    @branches_to_use = map { _trim($_) } split( /,/, $static_branch_list )
608
622
      if $static_branch_list;
609
    @branches_to_use = shuffle(@branches_to_use) if  C4::Context->preference("RandomizeHoldsQueueWeight");
623
624
    @branches_to_use =
625
      Koha::Database->new()->schema()->resultset('Branch')
626
      ->get_column('branchcode')->all()
627
      unless (@branches_to_use);
628
629
    @branches_to_use = shuffle(@branches_to_use)
630
      if C4::Context->preference("RandomizeHoldsQueueWeight");
631
632
    my $today = dt_from_string();
633
    if ( C4::Context->preference('HoldsQueueSkipClosed') ) {
634
        @branches_to_use = grep {
635
            !Koha::Calendar->new( branchcode => $_ )
636
              ->is_holiday( $today )
637
        } @branches_to_use;
638
    }
610
639
611
    return \@branches_to_use;
640
    return \@branches_to_use;
612
}
641
}
(-)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 160-165 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
160
('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'),
160
('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'),
161
('HoldFeeMode','not_always','always|not_always','Set the hold fee mode','Choice'),
161
('HoldFeeMode','not_always','always|not_always','Set the hold fee mode','Choice'),
162
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
162
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
163
('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'),
163
('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'),
164
('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'),
164
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
165
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
165
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
166
('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 488-497 Circulation: Link Here
488
            - pref: ExpireReservesMaxPickUpDelayCharge
488
            - pref: ExpireReservesMaxPickUpDelayCharge
489
              class: currency
489
              class: currency
490
        -
490
        -
491
            - Satisfy holds from the libraries
491
            - Satisfy holds using items from the libraries
492
            - pref: StaticHoldsQueueWeight
492
            - pref: StaticHoldsQueueWeight
493
              class: multi
493
              class: multi
494
            - (as branchcodes, separated by commas; if empty, uses all libraries)
494
            - (as branchcodes, separated by commas; if empty, uses all libraries)
495
            - when they are
496
            - pref: HoldsQueueSkipClosed
497
              choices:
498
                  yes: open
499
                  no: open or closed
495
            - pref: RandomizeHoldsQueueWeight
500
            - pref: RandomizeHoldsQueueWeight
496
              choices:
501
              choices:
497
                  yes: in random order.
502
                  yes: in random order.
(-)a/t/db_dependent/HoldsQueue.t (-6 / +38 lines)
Lines 8-24 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 => 23;
16
17
use C4::Branch;
14
use C4::Branch;
18
use C4::ItemType;
15
use C4::ItemType;
19
use C4::Members;
16
use C4::Members;
20
use Koha::Database;
17
use Koha::Database;
21
18
19
use C4::Calendar;
20
use C4::Context;
21
use C4::Branch;
22
use C4::ItemType;
23
use C4::Members;
24
use Koha::DateUtils;
25
22
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
23
27
24
BEGIN {
28
BEGIN {
Lines 67-72 my $itemtype = $for_loan[0]->{itemtype}; Link Here
67
71
68
#Set up the stage
72
#Set up the stage
69
# Sysprefs and cost matrix
73
# Sysprefs and cost matrix
74
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
70
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
75
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
71
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
76
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
72
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
77
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
Lines 301-312 is( @$holds_queue, 2, "Holds queue filling correct number for default holds poli Link Here
301
is( $holds_queue->[0]->{cardnumber}, $borrower1->{cardnumber}, "Holds queue filling 1st correct hold for default holds policy 'from home library'");
306
is( $holds_queue->[0]->{cardnumber}, $borrower1->{cardnumber}, "Holds queue filling 1st correct hold for default holds policy 'from home library'");
302
is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
307
is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
303
308
309
# Test skipping hold picks for closed libraries.
310
# At this point in the test, we have 2 rows in the holds queue
311
# 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed
312
# and make today a holiday for MPL. When we run it again we should only
313
# have 1 row in the holds queue
314
C4::Context->set_preference('HoldsQueueSkipClosed', 1);
315
my $today = dt_from_string();
316
C4::Calendar->new( branchcode => 'MPL' )->insert_single_holiday(
317
    day         => $today->day(),
318
    month       => $today->month(),
319
    year        => $today->year(),
320
    title       => "$today",
321
    description => "$today",
322
);
323
C4::HoldsQueue::CreateQueue();
324
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
325
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" );
326
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
327
304
$dbh->do("DELETE FROM default_circ_rules");
328
$dbh->do("DELETE FROM default_circ_rules");
305
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
329
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
306
C4::HoldsQueue::CreateQueue();
330
C4::HoldsQueue::CreateQueue();
307
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
331
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
308
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
332
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
309
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
333
334
# Test skipping hold picks for closed libraries without transport cost matrix
335
# At this point in the test, we have 3 rows in the holds queue
336
# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed
337
# and use our previously created holiday for MPL.
338
# When we run it again we should only have 2 rows in the holds queue
339
C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 );
340
C4::HoldsQueue::CreateQueue();
341
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
342
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
310
343
311
# Bug 14297
344
# Bug 14297
312
$itemtype = $item_types[0]->{itemtype};
345
$itemtype = $item_types[0]->{itemtype};
313
- 

Return to bug 12803