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

(-)a/C4/HoldsQueue.pm (-4 / +5 lines)
Lines 166-171 Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets Link Here
166
sub CreateQueue {
166
sub CreateQueue {
167
    my $params      = shift;
167
    my $params      = shift;
168
    my $unallocated = $params->{unallocated};
168
    my $unallocated = $params->{unallocated};
169
    my $record_ids  = $params->{record_ids};
169
    my $loops       = $params->{loops} || 1;
170
    my $loops       = $params->{loops} || 1;
170
    my $dbh         = C4::Context->dbh;
171
    my $dbh         = C4::Context->dbh;
171
172
Lines 192-205 sub CreateQueue { Link Here
192
193
193
    $branches_to_use = load_branches_to_pull_from($use_transport_cost_matrix);
194
    $branches_to_use = load_branches_to_pull_from($use_transport_cost_matrix);
194
195
195
    my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
196
    my $bibs_to_update = $record_ids ? $record_ids : GetBibsWithPendingHoldRequests();
196
197
197
    # Split the list of bibs into chunks to run in parallel
198
    # Split the list of bibs into chunks to run in parallel
198
    my @chunks;
199
    my @chunks;
199
    if ( $loops > 1 ) {
200
    if ( $loops > 1 ) {
200
        my $i = 0;
201
        my $i = 0;
201
        while (@$bibs_with_pending_requests) {
202
        while (@$bibs_to_update) {
202
            push( @{ $chunks[$i] }, pop(@$bibs_with_pending_requests) );
203
            push( @{ $chunks[$i] }, pop(@$bibs_to_update) );
203
204
204
            $i++;
205
            $i++;
205
            $i = 0 if $i >= $loops;
206
            $i = 0 if $i >= $loops;
Lines 225-231 sub CreateQueue { Link Here
225
226
226
        $pm->wait_all_children;
227
        $pm->wait_all_children;
227
    } else {
228
    } else {
228
        foreach my $biblionumber (@$bibs_with_pending_requests) {
229
        foreach my $biblionumber (@$bibs_to_update) {
229
            update_queue_for_biblio(
230
            update_queue_for_biblio(
230
                {
231
                {
231
                    biblio_id             => $biblionumber,
232
                    biblio_id             => $biblionumber,
(-)a/Koha/BackgroundJob/RebuildHoldsQueue.pm (+109 lines)
Line 0 Link Here
1
package Koha::BackgroundJob::RebuildHoldsQueue;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Biblios;
21
use Koha::SearchEngine;
22
use Koha::SearchEngine::Indexer;
23
24
use C4::Context;
25
use C4::Biblio;
26
use C4::Items;
27
use C4::MarcModificationTemplates;
28
29
use base 'Koha::BackgroundJob';
30
31
=head1 NAME
32
33
Koha::BackgroundJob::RebuildHoldsQueue - Rebuild the holds queue
34
35
This is a subclass of Koha::BackgroundJob.
36
37
=head1 API
38
39
=head2 Class methods
40
41
=head3 job_type
42
43
Define the job type of this job: rebuild_holds_queue
44
45
=cut
46
47
sub job_type {
48
    return 'rebuild_holds_queue';
49
}
50
51
=head3 process
52
53
Process the rebuild.
54
55
=cut
56
57
sub process {
58
    my ( $self, $args ) = @_;
59
60
    my $data;
61
62
    if ( $self->status eq 'cancelled' ) {
63
        return;
64
    }
65
66
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
67
    # Then we will start from scratch and so double process the same records
68
69
    $self->start;
70
71
    my @record_ids = @{ $args->{record_ids} };
72
    my $scope      = @record_ids ? scalar @record_ids : 'full';
73
74
    my $report = {
75
        records_passed => $scope,
76
    };
77
    my @messages;
78
79
    C4::HoldsQueue::CreateQueue(
80
        {
81
            record_ids  => @record_ids,
82
            unallocated => undef,
83
        }
84
    );
85
    $data->{messages} = \@messages;
86
    $data->{report}   = $report;
87
88
    $self->finish($data);
89
}
90
91
=head3 enqueue
92
93
Enqueue the new job
94
95
=cut
96
97
sub enqueue {
98
    my ( $self, $args ) = @_;
99
100
    $self->SUPER::enqueue(
101
        {
102
            job_size  => $args->{record_ids} ? scalar @{ $args->{record_ids} } : 'full',
103
            job_args  => $args,
104
            job_queue => 'long_tasks',
105
        }
106
    );
107
}
108
109
1;
(-)a/installer/data/mysql/atomicupdate/bug_39859.pl (-1 / +20 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "BUG_NUMBER",
6
    description => "A single line description",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        $dbh->do(
12
            q{
13
            INSERT IGNORE INTO permissions (module_bit, code, description) VALUES
14
            ( 6, 'rebuild_holds_queue', 'Rebuild the holds queue')
15
        }
16
        );
17
18
        say $out "Added new permission 'rebuild_holds_queue'";
19
    },
20
};

Return to bug 39859