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

(-)a/C4/HoldsQueue.pm (-10 / +28 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 226-231 sub GetBibsWithPendingHoldRequests { Link Here
226
                     AND priority > 0
231
                     AND priority > 0
227
                     AND reservedate <= CURRENT_DATE()
232
                     AND reservedate <= CURRENT_DATE()
228
                     AND suspend = 0
233
                     AND suspend = 0
234
                     AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets)
229
                     ";
235
                     ";
230
    my $sth = $dbh->prepare($bib_query);
236
    my $sth = $dbh->prepare($bib_query);
231
237
Lines 237-246 sub GetBibsWithPendingHoldRequests { Link Here
237
243
238
=head2 GetPendingHoldRequestsForBib
244
=head2 GetPendingHoldRequestsForBib
239
245
240
  my $requests = GetPendingHoldRequestsForBib($biblionumber);
246
  my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated });
241
247
242
Returns an arrayref of hashrefs to pending, unfilled hold requests
248
Returns an arrayref of hashrefs to pending, unfilled hold requests
243
on the bib identified by $biblionumber.  The following keys
249
on the bib identified by $biblionumber. Optionally returns only unallocated holds.  The following keys
244
are present in each hashref:
250
are present in each hashref:
245
251
246
    biblionumber
252
    biblionumber
Lines 257-263 The arrayref is sorted in order of increasing priority. Link Here
257
=cut
263
=cut
258
264
259
sub GetPendingHoldRequestsForBib {
265
sub GetPendingHoldRequestsForBib {
260
    my $biblionumber = shift;
266
    my $params = shift;
267
    my $biblionumber = $params->{biblionumber};
268
    my $unallocated = $params->{unallocated};
261
269
262
    my $dbh = C4::Context->dbh;
270
    my $dbh = C4::Context->dbh;
263
271
Lines 269-276 sub GetPendingHoldRequestsForBib { Link Here
269
                         AND found IS NULL
277
                         AND found IS NULL
270
                         AND priority > 0
278
                         AND priority > 0
271
                         AND reservedate <= CURRENT_DATE()
279
                         AND reservedate <= CURRENT_DATE()
272
                         AND suspend = 0
280
                         AND suspend = 0 ";
273
                         ORDER BY priority";
281
    $request_query .=   "AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) " if $unallocated;
282
    $request_query .=   "ORDER BY priority";
274
    my $sth = $dbh->prepare($request_query);
283
    my $sth = $dbh->prepare($request_query);
275
    $sth->execute($biblionumber);
284
    $sth->execute($biblionumber);
276
285
Lines 328-337 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
328
                           AND itemnumber IS NOT NULL
337
                           AND itemnumber IS NOT NULL
329
                           AND (found IS NOT NULL OR priority = 0)
338
                           AND (found IS NOT NULL OR priority = 0)
330
                        )
339
                        )
340
                        AND items.itemnumber NOT IN (
341
                           SELECT itemnumber
342
                           FROM tmp_holdsqueue
343
                           WHERE biblionumber = ?
344
                        )
331
                       AND items.biblionumber = ?
345
                       AND items.biblionumber = ?
332
                       AND branchtransfers.itemnumber IS NULL";
346
                       AND branchtransfers.itemnumber IS NULL";
333
347
334
    my @params = ($biblionumber, $biblionumber);
348
    my @params = ($biblionumber, $biblionumber, $biblionumber);
335
    if ($branches_to_use && @$branches_to_use) {
349
    if ($branches_to_use && @$branches_to_use) {
336
        $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")";
350
        $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")";
337
        push @params, @$branches_to_use;
351
        push @params, @$branches_to_use;
Lines 870-876 sub least_cost_branch { Link Here
870
            biblio_id             => $biblio_id,
884
            biblio_id             => $biblio_id,
871
          [ branches_to_use       => $branches_to_use,
885
          [ branches_to_use       => $branches_to_use,
872
            transport_cost_matrix => $transport_cost_matrix,
886
            transport_cost_matrix => $transport_cost_matrix,
873
            delete                => $delete, ]
887
            delete                => $delete,
888
            unallocated           => $unallocated, ]
874
        }
889
        }
875
    );
890
    );
876
891
Lines 901-906 It return a hashref containing: Link Here
901
916
902
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
917
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
903
918
919
=item I<unallocated> tells the method to limit the holds to those not in the holds queue, should not
920
    be passed at the same time as delete.
921
904
=back
922
=back
905
923
906
Note: All the optional parameters will be calculated in the method if omitted. They
924
Note: All the optional parameters will be calculated in the method if omitted. They
Lines 921-927 sub update_queue_for_biblio { Link Here
921
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
939
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
922
    }
940
    }
923
941
924
    my $hold_requests   = GetPendingHoldRequestsForBib($biblio_id);
942
    my $hold_requests   = GetPendingHoldRequestsForBib({ biblionumber => $biblio_id, unallocated => $args->{unallocated} });
925
    $result->{requests} = scalar( @{$hold_requests} );
943
    $result->{requests} = scalar( @{$hold_requests} );
926
    # No need to check anything else if there are no holds to fill
944
    # No need to check anything else if there are no holds to fill
927
    return $result unless $result->{requests};
945
    return $result unless $result->{requests};
(-)a/misc/cronjobs/holds/build_holds_queue.pl (-3 / +11 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 56-61 This script builds or rebuilds the entire holds queue. Link Here
56
my $help  = 0;
62
my $help  = 0;
57
my $man   = 0;
63
my $man   = 0;
58
my $force = 0;
64
my $force = 0;
65
my $unallocated = 0;
59
66
60
my $command_line_options = join( " ", @ARGV );
67
my $command_line_options = join( " ", @ARGV );
61
68
Lines 63-68 GetOptions( Link Here
63
    'h|help'  => \$help,
70
    'h|help'  => \$help,
64
    'm|man'   => \$man,
71
    'm|man'   => \$man,
65
    'f|force' => \$force,
72
    'f|force' => \$force,
73
    'u|unallocated' => \$unallocated
66
);
74
);
67
pod2usage(1)                              if $help;
75
pod2usage(1)                              if $help;
68
pod2usage( -exitval => 0, -verbose => 2 ) if $man;
76
pod2usage( -exitval => 0, -verbose => 2 ) if $man;
Lines 77-82 if ( $rthq && !$force ) { Link Here
77
85
78
cronlogaction( { info => $command_line_options } );
86
cronlogaction( { info => $command_line_options } );
79
87
80
CreateQueue();
88
CreateQueue({ unallocated => $unallocated });
81
89
82
cronlogaction( { action => 'End', info => "COMPLETED" } );
90
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