[Koha-patches] [PATCH] bug 2677: restore RandomizeHoldsQueueWeight and StaticHoldsQueueWeight
Galen Charlton
galen.charlton at liblime.com
Wed Oct 15 15:52:34 CEST 2008
Restoring the functionality of these sysprefs as part of the
rework of build_holds_queue.pl:
* StaticHoldsQueueWeight is an ordered list of library codes.
The order of the libraries in this list determines the order
of libraries in which available items will be chosen to be
targeted to holds. Note that if this list does not include
a library, items from that library will never be targeted to
holds and staff will never be asked to retrieve items for
title-level holds from those libraries.
* RandomizeHoldsQueueWeight is a Boolean parameter, indicating
whether to randomize the libraries in the StaticHoldsQueueWeight
list.
If neither RandomizeHoldsQueueWeight nor StaticHoldsQueueWeight is
set, then the libraries will be used to target items to holds in
alphabetical order by library code.
---
misc/cronjobs/holds/build_holds_queue.pl | 49 ++++++++++++++++++++++++++----
1 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/misc/cronjobs/holds/build_holds_queue.pl b/misc/cronjobs/holds/build_holds_queue.pl
index 26a2dba..e9054da 100755
--- a/misc/cronjobs/holds/build_holds_queue.pl
+++ b/misc/cronjobs/holds/build_holds_queue.pl
@@ -20,7 +20,8 @@ use C4::Branch;
use C4::Circulation;
use C4::Members;
use C4::Biblio;
-use Data::Dumper;
+
+use List::Util qw(shuffle);
my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
@@ -32,13 +33,16 @@ my $total_bibs = 0;
my $total_requests = 0;
my $total_available_items = 0;
my $num_items_mapped = 0;
+
+my @branches_to_use = _get_branches_to_pull_from();
+
foreach my $biblionumber (@$bibs_with_pending_requests) {
$total_bibs++;
my $hold_requests = GetPendingHoldRequestsForBib($biblionumber);
$total_requests += scalar(@$hold_requests);
- my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber);
+ my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, @branches_to_use);
$total_available_items += scalar(@$available_items);
- my $item_map = MapItemsToHoldRequests($hold_requests, $available_items);
+ my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, @branches_to_use);
if (defined($item_map)) {
$num_items_mapped += scalar(keys %$item_map);
CreatePicklistFromItemMap($item_map);
@@ -151,6 +155,7 @@ to fill a hold request if and only if:
sub GetItemsAvailableToFillHoldRequestsForBib {
my $biblionumber = shift;
+ my @branches_to_use = @_;
my $dbh = C4::Context->dbh;
my $items_query = "SELECT itemnumber, homebranch, holdingbranch
@@ -176,8 +181,13 @@ sub GetItemsAvailableToFillHoldRequestsForBib {
AND (found IS NOT NULL OR priority = 0)
)
AND biblionumber = ?";
+ my @params = ($biblionumber, $biblionumber);
+ if ($#branches_to_use > -1) {
+ $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @branches_to_use) . ")";
+ push @params, @branches_to_use;
+ }
my $sth = $dbh->prepare($items_query);
- $sth->execute($biblionumber, $biblionumber);
+ $sth->execute(@params);
my $items = $sth->fetchall_arrayref({});
return [ grep { my @transfers = GetTransfers($_->{itemnumber}); $#transfers == -1; } @$items ];
@@ -196,6 +206,7 @@ MapItemsToHoldRequests($hold_requests, $available_items);
sub MapItemsToHoldRequests {
my $hold_requests = shift;
my $available_items = shift;
+ my @branches_to_use = @_;
# handle trival cases
return unless scalar(@$hold_requests) > 0;
@@ -271,8 +282,14 @@ sub MapItemsToHoldRequests {
};
$num_items_remaining--;
} else {
- # FIXME implement static, random options
- foreach my $branch (sort keys %items_by_branch) {
+ my @pull_branches = ();
+ if ($#branches_to_use > -1) {
+ @pull_branches = @branches_to_use;
+ } else {
+ @pull_branches = sort keys %items_by_branch;
+ }
+ foreach my $branch (@pull_branches) {
+ next unless exists $items_by_branch{$branch};
my $item = pop @{ $items_by_branch{$branch} };
delete $items_by_branch{$branch} if scalar(@{ $items_by_branch{$branch} }) == 0;
$item_map{$item->{itemnumber}} = {
@@ -358,3 +375,23 @@ sub AddToHoldTargetMap {
$mapped_item->{holdingbranch}, $mapped_item->{item_level});
}
}
+
+=head2 _get_branches_to_pull_from
+
+Query system preferences to get ordered list of
+branches to use to fill hold requests.
+
+=cut
+
+sub _get_branches_to_pull_from {
+ my @branches_to_use = ();
+
+ my $static_branch_list = C4::Context->preference("StaticHoldsQueueWeight");
+ if ($static_branch_list) {
+ @branches_to_use = map { s/^\s+//; s/\s+$//; $_; } split /,/, $static_branch_list;
+ }
+
+ @branches_to_use = shuffle(@branches_to_use) if C4::Context->preference("RandomizeHoldsQueueWeight");
+
+ return @branches_to_use;
+}
--
1.5.5.GIT
More information about the Koha-patches
mailing list