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

(-)a/C4/HoldsQueue.pm (-10 / +28 lines)
Lines 168-177 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;
172
    my $unallocated = $params->{unallocated};
171
    my $dbh   = C4::Context->dbh;
173
    my $dbh   = C4::Context->dbh;
172
174
173
    $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
175
    unless( $unallocated ){
174
    $dbh->do("DELETE FROM hold_fill_targets");
176
        $dbh->do("DELETE FROM tmp_holdsqueue");  # clear the old table for new info
177
        $dbh->do("DELETE FROM hold_fill_targets");
178
    }
175
179
176
    my $total_bibs            = 0;
180
    my $total_bibs            = 0;
177
    my $total_requests        = 0;
181
    my $total_requests        = 0;
Lines 201-206 sub CreateQueue { Link Here
201
            {   biblio_id             => $biblionumber,
205
            {   biblio_id             => $biblionumber,
202
                branches_to_use       => $branches_to_use,
206
                branches_to_use       => $branches_to_use,
203
                transport_cost_matrix => $transport_cost_matrix,
207
                transport_cost_matrix => $transport_cost_matrix,
208
                unallocated           => $unallocated
204
            }
209
            }
205
        );
210
        );
206
211
Lines 228-233 sub GetBibsWithPendingHoldRequests { Link Here
228
                     AND priority > 0
233
                     AND priority > 0
229
                     AND reservedate <= CURRENT_DATE()
234
                     AND reservedate <= CURRENT_DATE()
230
                     AND suspend = 0
235
                     AND suspend = 0
236
                     AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets)
231
                     ";
237
                     ";
232
    my $sth = $dbh->prepare($bib_query);
238
    my $sth = $dbh->prepare($bib_query);
233
239
Lines 239-248 sub GetBibsWithPendingHoldRequests { Link Here
239
245
240
=head2 GetPendingHoldRequestsForBib
246
=head2 GetPendingHoldRequestsForBib
241
247
242
  my $requests = GetPendingHoldRequestsForBib($biblionumber);
248
  my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated });
243
249
244
Returns an arrayref of hashrefs to pending, unfilled hold requests
250
Returns an arrayref of hashrefs to pending, unfilled hold requests
245
on the bib identified by $biblionumber.  The following keys
251
on the bib identified by $biblionumber. Optionally returns only unallocated holds.  The following keys
246
are present in each hashref:
252
are present in each hashref:
247
253
248
    biblionumber
254
    biblionumber
Lines 259-265 The arrayref is sorted in order of increasing priority. Link Here
259
=cut
265
=cut
260
266
261
sub GetPendingHoldRequestsForBib {
267
sub GetPendingHoldRequestsForBib {
262
    my $biblionumber = shift;
268
    my $params = shift;
269
    my $biblionumber = $params->{biblionumber};
270
    my $unallocated = $params->{unallocated};
263
271
264
    my $dbh = C4::Context->dbh;
272
    my $dbh = C4::Context->dbh;
265
273
Lines 271-278 sub GetPendingHoldRequestsForBib { Link Here
271
                         AND found IS NULL
279
                         AND found IS NULL
272
                         AND priority > 0
280
                         AND priority > 0
273
                         AND reservedate <= CURRENT_DATE()
281
                         AND reservedate <= CURRENT_DATE()
274
                         AND suspend = 0
282
                         AND suspend = 0 ";
275
                         ORDER BY priority";
283
    $request_query .=   "AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) " if $unallocated;
284
    $request_query .=   "ORDER BY priority";
276
    my $sth = $dbh->prepare($request_query);
285
    my $sth = $dbh->prepare($request_query);
277
    $sth->execute($biblionumber);
286
    $sth->execute($biblionumber);
278
287
Lines 330-339 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
330
                           AND itemnumber IS NOT NULL
339
                           AND itemnumber IS NOT NULL
331
                           AND (found IS NOT NULL OR priority = 0)
340
                           AND (found IS NOT NULL OR priority = 0)
332
                        )
341
                        )
342
                        AND items.itemnumber NOT IN (
343
                           SELECT itemnumber
344
                           FROM tmp_holdsqueue
345
                           WHERE biblionumber = ?
346
                        )
333
                       AND items.biblionumber = ?
347
                       AND items.biblionumber = ?
334
                       AND branchtransfers.itemnumber IS NULL";
348
                       AND branchtransfers.itemnumber IS NULL";
335
349
336
    my @params = ($biblionumber, $biblionumber);
350
    my @params = ($biblionumber, $biblionumber, $biblionumber);
337
    if ($branches_to_use && @$branches_to_use) {
351
    if ($branches_to_use && @$branches_to_use) {
338
        $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")";
352
        $items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")";
339
        push @params, @$branches_to_use;
353
        push @params, @$branches_to_use;
Lines 1120-1126 sub least_cost_branch { Link Here
1120
            biblio_id             => $biblio_id,
1134
            biblio_id             => $biblio_id,
1121
          [ branches_to_use       => $branches_to_use,
1135
          [ branches_to_use       => $branches_to_use,
1122
            transport_cost_matrix => $transport_cost_matrix,
1136
            transport_cost_matrix => $transport_cost_matrix,
1123
            delete                => $delete, ]
1137
            delete                => $delete,
1138
            unallocated           => $unallocated, ]
1124
        }
1139
        }
1125
    );
1140
    );
1126
1141
Lines 1151-1156 It return a hashref containing: Link Here
1151
1166
1152
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
1167
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
1153
1168
1169
=item I<unallocated> tells the method to limit the holds to those not in the holds queue, should not
1170
    be passed at the same time as delete.
1171
1154
=back
1172
=back
1155
1173
1156
Note: All the optional parameters will be calculated in the method if omitted. They
1174
Note: All the optional parameters will be calculated in the method if omitted. They
Lines 1171-1177 sub update_queue_for_biblio { Link Here
1171
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
1189
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
1172
    }
1190
    }
1173
1191
1174
    my $hold_requests   = GetPendingHoldRequestsForBib($biblio_id);
1192
    my $hold_requests   = GetPendingHoldRequestsForBib({ biblionumber => $biblio_id, unallocated => $args->{unallocated} });
1175
    $result->{requests} = scalar( @{$hold_requests} );
1193
    $result->{requests} = scalar( @{$hold_requests} );
1176
    # No need to check anything else if there are no holds to fill
1194
    # No need to check anything else if there are no holds to fill
1177
    return $result unless $result->{requests};
1195
    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