|
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; |