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

(-)a/C4/HoldsQueue.pm (-15 / +16 lines)
Lines 168-179 Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets Link Here
168
=cut
168
=cut
169
169
170
sub CreateQueue {
170
sub CreateQueue {
171
    my $params = shift;
171
    my $params      = shift;
172
    my $unallocated = $params->{unallocated};
172
    my $unallocated = $params->{unallocated};
173
    my $dbh   = C4::Context->dbh;
173
    my $dbh         = C4::Context->dbh;
174
174
175
    unless( $unallocated ){
175
    unless ($unallocated) {
176
        $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
176
        $dbh->do("DELETE FROM tmp_holdsqueue");    # clear the old table for new info
177
        $dbh->do("DELETE FROM hold_fill_targets");
177
        $dbh->do("DELETE FROM hold_fill_targets");
178
    }
178
    }
179
179
Lines 202-208 sub CreateQueue { Link Here
202
        $total_bibs++;
202
        $total_bibs++;
203
203
204
        my $result = update_queue_for_biblio(
204
        my $result = update_queue_for_biblio(
205
            {   biblio_id             => $biblionumber,
205
            {
206
                biblio_id             => $biblionumber,
206
                branches_to_use       => $branches_to_use,
207
                branches_to_use       => $branches_to_use,
207
                transport_cost_matrix => $transport_cost_matrix,
208
                transport_cost_matrix => $transport_cost_matrix,
208
                unallocated           => $unallocated
209
                unallocated           => $unallocated
Lines 245-251 sub GetBibsWithPendingHoldRequests { Link Here
245
246
246
=head2 GetPendingHoldRequestsForBib
247
=head2 GetPendingHoldRequestsForBib
247
248
248
  my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated });
249
    my $requests = GetPendingHoldRequestsForBib( { biblionumber => $biblionumber, unallocated => $unallocated } );
249
250
250
Returns an arrayref of hashrefs to pending, unfilled hold requests
251
Returns an arrayref of hashrefs to pending, unfilled hold requests
251
on the bib identified by $biblionumber. Optionally returns only unallocated holds.  The following keys
252
on the bib identified by $biblionumber. Optionally returns only unallocated holds.  The following keys
Lines 265-273 The arrayref is sorted in order of increasing priority. Link Here
265
=cut
266
=cut
266
267
267
sub GetPendingHoldRequestsForBib {
268
sub GetPendingHoldRequestsForBib {
268
    my $params = shift;
269
    my $params       = shift;
269
    my $biblionumber = $params->{biblionumber};
270
    my $biblionumber = $params->{biblionumber};
270
    my $unallocated = $params->{unallocated};
271
    my $unallocated  = $params->{unallocated};
271
272
272
    my $dbh = C4::Context->dbh;
273
    my $dbh = C4::Context->dbh;
273
274
Lines 280-287 sub GetPendingHoldRequestsForBib { Link Here
280
                         AND priority > 0
281
                         AND priority > 0
281
                         AND reservedate <= CURRENT_DATE()
282
                         AND reservedate <= CURRENT_DATE()
282
                         AND suspend = 0 ";
283
                         AND suspend = 0 ";
283
    $request_query .=   "AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) " if $unallocated;
284
    $request_query .= "AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) " if $unallocated;
284
    $request_query .=   "ORDER BY priority";
285
    $request_query .= "ORDER BY priority";
285
    my $sth = $dbh->prepare($request_query);
286
    my $sth = $dbh->prepare($request_query);
286
    $sth->execute($biblionumber);
287
    $sth->execute($biblionumber);
287
288
Lines 315-331 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
315
    my $items_query = "SELECT items.itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype
316
    my $items_query = "SELECT items.itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype
316
                       FROM items ";
317
                       FROM items ";
317
318
318
    if (C4::Context->preference('item-level_itypes')) {
319
    if ( C4::Context->preference('item-level_itypes') ) {
319
        $items_query .=   "LEFT JOIN itemtypes ON (itemtypes.itemtype = items.itype) ";
320
        $items_query .= "LEFT JOIN itemtypes ON (itemtypes.itemtype = items.itype) ";
320
    } else {
321
    } else {
321
        $items_query .=   "JOIN biblioitems USING (biblioitemnumber)
322
        $items_query .= "JOIN biblioitems USING (biblioitemnumber)
322
                           LEFT JOIN itemtypes USING (itemtype) ";
323
                           LEFT JOIN itemtypes USING (itemtype) ";
323
    }
324
    }
324
    $items_query .=  " LEFT JOIN branchtransfers ON (
325
    $items_query .= " LEFT JOIN branchtransfers ON (
325
                           items.itemnumber = branchtransfers.itemnumber
326
                           items.itemnumber = branchtransfers.itemnumber
326
                           AND branchtransfers.datearrived IS NULL AND branchtransfers.datecancelled IS NULL
327
                           AND branchtransfers.datearrived IS NULL AND branchtransfers.datecancelled IS NULL
327
                     )";
328
                     )";
328
    $items_query .=  " WHERE items.notforloan = 0
329
    $items_query .= " WHERE items.notforloan = 0
329
                       AND holdingbranch IS NOT NULL
330
                       AND holdingbranch IS NOT NULL
330
                       AND itemlost = 0
331
                       AND itemlost = 0
331
                       AND withdrawn = 0";
332
                       AND withdrawn = 0";
(-)a/misc/cronjobs/holds/build_holds_queue.pl (-7 / +7 lines)
Lines 59-75 This script builds or rebuilds the entire holds queue. Link Here
59
59
60
=cut
60
=cut
61
61
62
my $help  = 0;
62
my $help        = 0;
63
my $man   = 0;
63
my $man         = 0;
64
my $force = 0;
64
my $force       = 0;
65
my $unallocated = 0;
65
my $unallocated = 0;
66
66
67
my $command_line_options = join( " ", @ARGV );
67
my $command_line_options = join( " ", @ARGV );
68
68
69
GetOptions(
69
GetOptions(
70
    'h|help'  => \$help,
70
    'h|help'        => \$help,
71
    'm|man'   => \$man,
71
    'm|man'         => \$man,
72
    'f|force' => \$force,
72
    'f|force'       => \$force,
73
    'u|unallocated' => \$unallocated
73
    'u|unallocated' => \$unallocated
74
);
74
);
75
pod2usage(1)                              if $help;
75
pod2usage(1)                              if $help;
Lines 85-90 if ( $rthq && !$force ) { Link Here
85
85
86
cronlogaction( { info => $command_line_options } );
86
cronlogaction( { info => $command_line_options } );
87
87
88
CreateQueue({ unallocated => $unallocated });
88
CreateQueue( { unallocated => $unallocated } );
89
89
90
cronlogaction( { action => 'End', info => "COMPLETED" } );
90
cronlogaction( { action => 'End', info => "COMPLETED" } );
(-)a/t/db_dependent/HoldsQueue.t (-3 / +2 lines)
Lines 2254-2267 subtest "Test unallocated option" => sub { Link Here
2254
2254
2255
    my $original_timestamp = $hold->timestamp;
2255
    my $original_timestamp = $hold->timestamp;
2256
2256
2257
    sleep 2; # Allow time to pass after first hold was placed
2257
    sleep 2;    # Allow time to pass after first hold was placed
2258
    C4::HoldsQueue::CreateQueue();
2258
    C4::HoldsQueue::CreateQueue();
2259
    $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item1->biblionumber } );
2259
    $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item1->biblionumber } );
2260
    $hold     = $queue_rs->next;
2260
    $hold     = $queue_rs->next;
2261
    isnt( $hold->timestamp, $original_timestamp, "Hold was reallocated when queue fully rebuilt" );
2261
    isnt( $hold->timestamp, $original_timestamp, "Hold was reallocated when queue fully rebuilt" );
2262
    my $after_rebuild_timestamp = $hold->timestamp;
2262
    my $after_rebuild_timestamp = $hold->timestamp;
2263
2263
2264
    sleep 2; # Allow time to pass after first full rebuild
2264
    sleep 2;    # Allow time to pass after first full rebuild
2265
    C4::HoldsQueue::CreateQueue( { unallocated => 1 } );
2265
    C4::HoldsQueue::CreateQueue( { unallocated => 1 } );
2266
    $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item1->biblionumber } );
2266
    $queue_rs = $schema->resultset('TmpHoldsqueue')->search( { biblionumber => $item1->biblionumber } );
2267
    $hold     = $queue_rs->next;
2267
    $hold     = $queue_rs->next;
2268
- 

Return to bug 32565