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

(-)a/C4/HoldsQueue.pm (-10 / +27 lines)
Lines 182-191 Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets Link Here
182
=cut
182
=cut
183
183
184
sub CreateQueue {
184
sub CreateQueue {
185
    my $params = shift;
186
    my $unallocated = $params->{unallocated};
185
    my $dbh   = C4::Context->dbh;
187
    my $dbh   = C4::Context->dbh;
186
188
187
    $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
189
    unless( $unallocated ){
188
    $dbh->do("DELETE FROM hold_fill_targets");
190
        $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
191
        $dbh->do("DELETE FROM hold_fill_targets");
192
    }
189
193
190
    my $total_bibs            = 0;
194
    my $total_bibs            = 0;
191
    my $total_requests        = 0;
195
    my $total_requests        = 0;
Lines 215-220 sub CreateQueue { Link Here
215
            {   biblio_id             => $biblionumber,
219
            {   biblio_id             => $biblionumber,
216
                branches_to_use       => $branches_to_use,
220
                branches_to_use       => $branches_to_use,
217
                transport_cost_matrix => $transport_cost_matrix,
221
                transport_cost_matrix => $transport_cost_matrix,
222
                unallocated           => $unallocated
218
            }
223
            }
219
        );
224
        );
220
225
Lines 253-262 sub GetBibsWithPendingHoldRequests { Link Here
253
258
254
=head2 GetPendingHoldRequestsForBib
259
=head2 GetPendingHoldRequestsForBib
255
260
256
  my $requests = GetPendingHoldRequestsForBib($biblionumber);
261
  my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated });
257
262
258
Returns an arrayref of hashrefs to pending, unfilled hold requests
263
Returns an arrayref of hashrefs to pending, unfilled hold requests
259
on the bib identified by $biblionumber.  The following keys
264
on the bib identified by $biblionumber. Optionally returns only unallocated holds.  The following keys
260
are present in each hashref:
265
are present in each hashref:
261
266
262
    biblionumber
267
    biblionumber
Lines 273-279 The arrayref is sorted in order of increasing priority. Link Here
273
=cut
278
=cut
274
279
275
sub GetPendingHoldRequestsForBib {
280
sub GetPendingHoldRequestsForBib {
276
    my $biblionumber = shift;
281
    my $params = shift;
282
    my $biblionumber = $params->{biblionumber};
283
    my $unallocated = $params->{unallocated};
277
284
278
    my $dbh = C4::Context->dbh;
285
    my $dbh = C4::Context->dbh;
279
286
Lines 285-292 sub GetPendingHoldRequestsForBib { Link Here
285
                         AND found IS NULL
292
                         AND found IS NULL
286
                         AND priority > 0
293
                         AND priority > 0
287
                         AND reservedate <= CURRENT_DATE()
294
                         AND reservedate <= CURRENT_DATE()
288
                         AND suspend = 0
295
                         AND suspend = 0 ";
289
                         ORDER BY priority";
296
    $request_query .=   "AND reserve_id NOT IN (SELECT reserve_id FROM tmp_holdsqueue " if $unallocated;
297
    $request_query .=   "ORDER BY priority";
290
    my $sth = $dbh->prepare($request_query);
298
    my $sth = $dbh->prepare($request_query);
291
    $sth->execute($biblionumber);
299
    $sth->execute($biblionumber);
292
300
Lines 343-351 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
343
                           AND itemnumber IS NOT NULL
351
                           AND itemnumber IS NOT NULL
344
                           AND (found IS NOT NULL OR priority = 0)
352
                           AND (found IS NOT NULL OR priority = 0)
345
                        )
353
                        )
354
                        AND items.itemnumber NOT IN (
355
                           SELECT itemnumber
356
                           FROM tmp_holdsqueue
357
                           WHERE biblionumber = ?
358
                        )
346
                       AND items.biblionumber = ?";
359
                       AND items.biblionumber = ?";
347
360
348
    my @params = ($biblionumber, $biblionumber);
361
    my @params = ($biblionumber, $biblionumber, $biblionumber);
349
    if ($branches_to_use && @$branches_to_use) {
362
    if ($branches_to_use && @$branches_to_use) {
350
        $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")";
363
        $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")";
351
        push @params, @$branches_to_use;
364
        push @params, @$branches_to_use;
Lines 891-897 sub least_cost_branch { Link Here
891
            biblio_id             => $biblio_id,
904
            biblio_id             => $biblio_id,
892
          [ branches_to_use       => $branches_to_use,
905
          [ branches_to_use       => $branches_to_use,
893
            transport_cost_matrix => $transport_cost_matrix,
906
            transport_cost_matrix => $transport_cost_matrix,
894
            delete                => $delete, ]
907
            delete                => $delete,
908
            unallocated           => $unallocated, ]
895
        }
909
        }
896
    );
910
    );
897
911
Lines 922-927 It return a hashref containing: Link Here
922
936
923
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
937
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
924
938
939
=item I<unallocated> tells the method to limit the holds to those not in the holds queue, should not
940
    be passed at the same time as delete.
941
925
=back
942
=back
926
943
927
Note: All the optional parameters will be calculated in the method if omitted. They
944
Note: All the optional parameters will be calculated in the method if omitted. They
Lines 942-948 sub update_queue_for_biblio { Link Here
942
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
959
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
943
    }
960
    }
944
961
945
    my $hold_requests   = GetPendingHoldRequestsForBib($biblio_id);
962
    my $hold_requests   = GetPendingHoldRequestsForBib({ biblionumber => $biblio_id, unallocated => $args->{unallocated} });
946
    $result->{requests} = scalar( @{$hold_requests} );
963
    $result->{requests} = scalar( @{$hold_requests} );
947
    # No need to check anything else if there are no holds to fill
964
    # No need to check anything else if there are no holds to fill
948
    return $result unless $result->{requests};
965
    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