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 66-71 my $itemtype = grep { $_->{notforloan} == 1 } @item_types Link Here
66
70
67
#Set up the stage
71
#Set up the stage
68
# Sysprefs and cost matrix
72
# Sysprefs and cost matrix
73
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
69
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
74
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
70
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
75
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
71
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
76
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
Lines 300-311 is( @$holds_queue, 2, "Holds queue filling correct number for default holds poli Link Here
300
is( $holds_queue->[0]->{cardnumber}, $borrower1->{cardnumber}, "Holds queue filling 1st correct hold for default holds policy 'from home library'");
305
is( $holds_queue->[0]->{cardnumber}, $borrower1->{cardnumber}, "Holds queue filling 1st correct hold for default holds policy 'from home library'");
301
is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
306
is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
302
307
308
# Test skipping hold picks for closed libraries.
309
# At this point in the test, we have 2 rows in the holds queue
310
# 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed
311
# and make today a holiday for MPL. When we run it again we should only
312
# have 1 row in the holds queue
313
C4::Context->set_preference('HoldsQueueSkipClosed', 1);
314
my $today = dt_from_string();
315
C4::Calendar->new( branchcode => 'MPL' )->insert_single_holiday(
316
    day         => $today->day(),
317
    month       => $today->month(),
318
    year        => $today->year(),
319
    title       => "$today",
320
    description => "$today",
321
);
322
C4::HoldsQueue::CreateQueue();
323
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
324
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" );
325
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
326
303
$dbh->do("DELETE FROM default_circ_rules");
327
$dbh->do("DELETE FROM default_circ_rules");
304
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
328
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
305
C4::HoldsQueue::CreateQueue();
329
C4::HoldsQueue::CreateQueue();
306
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
330
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
307
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
331
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
308
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
332
333
# Test skipping hold picks for closed libraries without transport cost matrix
334
# At this point in the test, we have 3 rows in the holds queue
335
# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed
336
# and use our previously created holiday for MPL.
337
# When we run it again we should only have 2 rows in the holds queue
338
C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 );
339
C4::HoldsQueue::CreateQueue();
340
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
341
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
309
342
310
# Bug 14297
343
# Bug 14297
311
$itemtype = $item_types[0]->{itemtype};
344
$itemtype = $item_types[0]->{itemtype};
312
- 

Return to bug 12803