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

(-)a/C4/HoldsQueue.pm (-15 / +16 lines)
Lines 166-177 Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets Link Here
166
=cut
166
=cut
167
167
168
sub CreateQueue {
168
sub CreateQueue {
169
    my $params = shift;
169
    my $params      = shift;
170
    my $unallocated = $params->{unallocated};
170
    my $unallocated = $params->{unallocated};
171
    my $dbh   = C4::Context->dbh;
171
    my $dbh         = C4::Context->dbh;
172
172
173
    unless( $unallocated ){
173
    unless ($unallocated) {
174
        $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
174
        $dbh->do("DELETE FROM tmp_holdsqueue");    # clear the old table for new info
175
        $dbh->do("DELETE FROM hold_fill_targets");
175
        $dbh->do("DELETE FROM hold_fill_targets");
176
    }
176
    }
177
177
Lines 200-206 sub CreateQueue { Link Here
200
        $total_bibs++;
200
        $total_bibs++;
201
201
202
        my $result = update_queue_for_biblio(
202
        my $result = update_queue_for_biblio(
203
            {   biblio_id             => $biblionumber,
203
            {
204
                biblio_id             => $biblionumber,
204
                branches_to_use       => $branches_to_use,
205
                branches_to_use       => $branches_to_use,
205
                transport_cost_matrix => $transport_cost_matrix,
206
                transport_cost_matrix => $transport_cost_matrix,
206
                unallocated           => $unallocated
207
                unallocated           => $unallocated
Lines 243-249 sub GetBibsWithPendingHoldRequests { Link Here
243
244
244
=head2 GetPendingHoldRequestsForBib
245
=head2 GetPendingHoldRequestsForBib
245
246
246
  my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated });
247
    my $requests = GetPendingHoldRequestsForBib( { biblionumber => $biblionumber, unallocated => $unallocated } );
247
248
248
Returns an arrayref of hashrefs to pending, unfilled hold requests
249
Returns an arrayref of hashrefs to pending, unfilled hold requests
249
on the bib identified by $biblionumber. Optionally returns only unallocated holds.  The following keys
250
on the bib identified by $biblionumber. Optionally returns only unallocated holds.  The following keys
Lines 263-271 The arrayref is sorted in order of increasing priority. Link Here
263
=cut
264
=cut
264
265
265
sub GetPendingHoldRequestsForBib {
266
sub GetPendingHoldRequestsForBib {
266
    my $params = shift;
267
    my $params       = shift;
267
    my $biblionumber = $params->{biblionumber};
268
    my $biblionumber = $params->{biblionumber};
268
    my $unallocated = $params->{unallocated};
269
    my $unallocated  = $params->{unallocated};
269
270
270
    my $dbh = C4::Context->dbh;
271
    my $dbh = C4::Context->dbh;
271
272
Lines 278-285 sub GetPendingHoldRequestsForBib { Link Here
278
                         AND priority > 0
279
                         AND priority > 0
279
                         AND reservedate <= CURRENT_DATE()
280
                         AND reservedate <= CURRENT_DATE()
280
                         AND suspend = 0 ";
281
                         AND suspend = 0 ";
281
    $request_query .=   "AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) " if $unallocated;
282
    $request_query .= "AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) " if $unallocated;
282
    $request_query .=   "ORDER BY priority";
283
    $request_query .= "ORDER BY priority";
283
    my $sth = $dbh->prepare($request_query);
284
    my $sth = $dbh->prepare($request_query);
284
    $sth->execute($biblionumber);
285
    $sth->execute($biblionumber);
285
286
Lines 313-329 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
313
    my $items_query = "SELECT items.itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype
314
    my $items_query = "SELECT items.itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype
314
                       FROM items ";
315
                       FROM items ";
315
316
316
    if (C4::Context->preference('item-level_itypes')) {
317
    if ( C4::Context->preference('item-level_itypes') ) {
317
        $items_query .=   "LEFT JOIN itemtypes ON (itemtypes.itemtype = items.itype) ";
318
        $items_query .= "LEFT JOIN itemtypes ON (itemtypes.itemtype = items.itype) ";
318
    } else {
319
    } else {
319
        $items_query .=   "JOIN biblioitems USING (biblioitemnumber)
320
        $items_query .= "JOIN biblioitems USING (biblioitemnumber)
320
                           LEFT JOIN itemtypes USING (itemtype) ";
321
                           LEFT JOIN itemtypes USING (itemtype) ";
321
    }
322
    }
322
    $items_query .=  " LEFT JOIN branchtransfers ON (
323
    $items_query .= " LEFT JOIN branchtransfers ON (
323
                           items.itemnumber = branchtransfers.itemnumber
324
                           items.itemnumber = branchtransfers.itemnumber
324
                           AND branchtransfers.datearrived IS NULL AND branchtransfers.datecancelled IS NULL
325
                           AND branchtransfers.datearrived IS NULL AND branchtransfers.datecancelled IS NULL
325
                     )";
326
                     )";
326
    $items_query .=  " WHERE items.notforloan = 0
327
    $items_query .= " WHERE items.notforloan = 0
327
                       AND holdingbranch IS NOT NULL
328
                       AND holdingbranch IS NOT NULL
328
                       AND itemlost = 0
329
                       AND itemlost = 0
329
                       AND withdrawn = 0";
330
                       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