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 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 / +35 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;
21
20
22
BEGIN {
21
BEGIN {
23
    use FindBin;
22
    use FindBin;
Lines 55-60 my $itemtype = grep { $_->{notforloan} == 1 } @item_types Link Here
55
54
56
#Set up the stage
55
#Set up the stage
57
# Sysprefs and cost matrix
56
# Sysprefs and cost matrix
57
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
58
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
58
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
59
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
59
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
60
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
60
$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'");
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->[1]->{cardnumber} eq 'CARDNUMBER2', "Holds queue filling 2nd 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
292
293
# Test skipping hold picks for closed libraries.
294
# At this point in the test, we have 2 rows in the holds queue
295
# 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed
296
# and make today a holiday for MPL. When we run it again we should only
297
# have 1 row in the holds queue
298
C4::Context->set_preference('HoldsQueueSkipClosed', 1);
299
my $today = dt_from_string();
300
C4::Calendar->new( branchcode => 'MPL' )->insert_single_holiday(
301
    day         => $today->day(),
302
    month       => $today->month(),
303
    year        => $today->year(),
304
    title       => "$today",
305
    description => "$today",
306
);
307
C4::HoldsQueue::CreateQueue();
308
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
309
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" );
310
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
311
293
$dbh->do("DELETE FROM default_circ_rules");
312
$dbh->do("DELETE FROM default_circ_rules");
294
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
313
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
295
C4::HoldsQueue::CreateQueue();
314
C4::HoldsQueue::CreateQueue();
296
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
315
$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'" );
316
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 );
317
318
# Test skipping hold picks for closed libraries without transport cost matrix
319
# At this point in the test, we have 3 rows in the holds queue
320
# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed
321
# and use our previously created holiday for MPL. 
322
# When we run it again we should only have 2 rows in the holds queue
323
C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 );
324
C4::HoldsQueue::CreateQueue();
325
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
326
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
299
327
300
# Bug 14297
328
# Bug 14297
301
$borrowernumber = AddMember(%data);
329
$borrowernumber = AddMember(%data);
302
- 

Return to bug 12803