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

(-)a/C4/HoldsQueue.pm (-10 / +27 lines)
Lines 166-175 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;
170
    my $unallocated = $params->{unallocated};
169
    my $dbh   = C4::Context->dbh;
171
    my $dbh   = C4::Context->dbh;
170
172
171
    $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
173
    unless( $unallocated ){
172
    $dbh->do("DELETE FROM hold_fill_targets");
174
        $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
175
        $dbh->do("DELETE FROM hold_fill_targets");
176
    }
173
177
174
    my $total_bibs            = 0;
178
    my $total_bibs            = 0;
175
    my $total_requests        = 0;
179
    my $total_requests        = 0;
Lines 199-204 sub CreateQueue { Link Here
199
            {   biblio_id             => $biblionumber,
203
            {   biblio_id             => $biblionumber,
200
                branches_to_use       => $branches_to_use,
204
                branches_to_use       => $branches_to_use,
201
                transport_cost_matrix => $transport_cost_matrix,
205
                transport_cost_matrix => $transport_cost_matrix,
206
                unallocated           => $unallocated
202
            }
207
            }
203
        );
208
        );
204
209
Lines 237-246 sub GetBibsWithPendingHoldRequests { Link Here
237
242
238
=head2 GetPendingHoldRequestsForBib
243
=head2 GetPendingHoldRequestsForBib
239
244
240
  my $requests = GetPendingHoldRequestsForBib($biblionumber);
245
  my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated });
241
246
242
Returns an arrayref of hashrefs to pending, unfilled hold requests
247
Returns an arrayref of hashrefs to pending, unfilled hold requests
243
on the bib identified by $biblionumber.  The following keys
248
on the bib identified by $biblionumber. Optionally returns only unallocated holds.  The following keys
244
are present in each hashref:
249
are present in each hashref:
245
250
246
    biblionumber
251
    biblionumber
Lines 257-263 The arrayref is sorted in order of increasing priority. Link Here
257
=cut
262
=cut
258
263
259
sub GetPendingHoldRequestsForBib {
264
sub GetPendingHoldRequestsForBib {
260
    my $biblionumber = shift;
265
    my $params = shift;
266
    my $biblionumber = $params->{biblionumber};
267
    my $unallocated = $params->{unallocated};
261
268
262
    my $dbh = C4::Context->dbh;
269
    my $dbh = C4::Context->dbh;
263
270
Lines 269-276 sub GetPendingHoldRequestsForBib { Link Here
269
                         AND found IS NULL
276
                         AND found IS NULL
270
                         AND priority > 0
277
                         AND priority > 0
271
                         AND reservedate <= CURRENT_DATE()
278
                         AND reservedate <= CURRENT_DATE()
272
                         AND suspend = 0
279
                         AND suspend = 0 ";
273
                         ORDER BY priority";
280
    $request_query .=   "AND reserve_id NOT IN (SELECT reserve_id FROM tmp_holdsqueue " if $unallocated;
281
    $request_query .=   "ORDER BY priority";
274
    my $sth = $dbh->prepare($request_query);
282
    my $sth = $dbh->prepare($request_query);
275
    $sth->execute($biblionumber);
283
    $sth->execute($biblionumber);
276
284
Lines 328-337 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
328
                           AND itemnumber IS NOT NULL
336
                           AND itemnumber IS NOT NULL
329
                           AND (found IS NOT NULL OR priority = 0)
337
                           AND (found IS NOT NULL OR priority = 0)
330
                        )
338
                        )
339
                        AND items.itemnumber NOT IN (
340
                           SELECT itemnumber
341
                           FROM tmp_holdsqueue
342
                           WHERE biblionumber = ?
343
                        )
331
                       AND items.biblionumber = ?
344
                       AND items.biblionumber = ?
332
                       AND branchtransfers.itemnumber IS NULL";
345
                       AND branchtransfers.itemnumber IS NULL";
333
346
334
    my @params = ($biblionumber, $biblionumber);
347
    my @params = ($biblionumber, $biblionumber, $biblionumber);
335
    if ($branches_to_use && @$branches_to_use) {
348
    if ($branches_to_use && @$branches_to_use) {
336
        $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")";
349
        $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")";
337
        push @params, @$branches_to_use;
350
        push @params, @$branches_to_use;
Lines 885-891 sub least_cost_branch { Link Here
885
            biblio_id             => $biblio_id,
898
            biblio_id             => $biblio_id,
886
          [ branches_to_use       => $branches_to_use,
899
          [ branches_to_use       => $branches_to_use,
887
            transport_cost_matrix => $transport_cost_matrix,
900
            transport_cost_matrix => $transport_cost_matrix,
888
            delete                => $delete, ]
901
            delete                => $delete,
902
            unallocated           => $unallocated, ]
889
        }
903
        }
890
    );
904
    );
891
905
Lines 916-921 It return a hashref containing: Link Here
916
930
917
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
931
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
918
932
933
=item I<unallocated> tells the method to limit the holds to those not in the holds queue, should not
934
    be passed at the same time as delete.
935
919
=back
936
=back
920
937
921
Note: All the optional parameters will be calculated in the method if omitted. They
938
Note: All the optional parameters will be calculated in the method if omitted. They
Lines 936-942 sub update_queue_for_biblio { Link Here
936
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
953
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
937
    }
954
    }
938
955
939
    my $hold_requests   = GetPendingHoldRequestsForBib($biblio_id);
956
    my $hold_requests   = GetPendingHoldRequestsForBib({ biblionumber => $biblio_id, unallocated => $args->{unallocated} });
940
    $result->{requests} = scalar( @{$hold_requests} );
957
    $result->{requests} = scalar( @{$hold_requests} );
941
    # No need to check anything else if there are no holds to fill
958
    # No need to check anything else if there are no holds to fill
942
    return $result unless $result->{requests};
959
    return $result unless $result->{requests};
(-)a/misc/cronjobs/holds/build_holds_queue.pl (-3 / +10 lines)
Lines 41-49 Print a brief help message and exits. Link Here
41
41
42
Prints the manual page and exits.
42
Prints the manual page and exits.
43
43
44
=item B<--force>
44
=item b<--force>
45
45
46
Allows this script to rebuild the entire holds queue even if the RealTimeHoldsQueue system preference is enabled.
46
allows this script to rebuild the entire holds queue even if the realtimeholdsqueue system preference is enabled.
47
48
=item b<--unallocated>
49
50
prevents deletion of current queue and allows the script to only deal with holds not currently in the queue.
51
This is useful when using the realtimeholdsqueue and skipping closed libraries, or allowing holds in the future
52
This allows the script to catch holds that may have become active without triggering a real time update.
47
53
48
=back
54
=back
49
55
Lines 63-68 GetOptions( Link Here
63
    'h|help'  => \$help,
69
    'h|help'  => \$help,
64
    'm|man'   => \$man,
70
    'm|man'   => \$man,
65
    'f|force' => \$force,
71
    'f|force' => \$force,
72
    'u|unallocated' => \$unallocated
66
);
73
);
67
pod2usage(1)                              if $help;
74
pod2usage(1)                              if $help;
68
pod2usage( -exitval => 0, -verbose => 2 ) if $man;
75
pod2usage( -exitval => 0, -verbose => 2 ) if $man;
Lines 77-82 if ( $rthq && !$force ) { Link Here
77
84
78
cronlogaction( { info => $command_line_options } );
85
cronlogaction( { info => $command_line_options } );
79
86
80
CreateQueue();
87
CreateQueue({ unallocated => $unallocated });
81
88
82
cronlogaction( { action => 'End', info => "COMPLETED" } );
89
cronlogaction( { action => 'End', info => "COMPLETED" } );
(-)a/t/db_dependent/HoldsQueue.t (-2 / +1 lines)
Lines 1710-1716 subtest "Test _checkHoldPolicy" => sub { Link Here
1710
        }
1710
        }
1711
    );
1711
    );
1712
    ok( $reserve_id, "Hold was created");
1712
    ok( $reserve_id, "Hold was created");
1713
    my $requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblio->biblionumber);
1713
    my $requests = C4::HoldsQueue::GetPendingHoldRequestsForBib({ biblionumber => $biblio->biblionumber});
1714
    is( @$requests, 1, "Got correct number of holds");
1714
    is( @$requests, 1, "Got correct number of holds");
1715
1715
1716
    my $request = $requests->[0];
1716
    my $request = $requests->[0];
1717
- 

Return to bug 32565