Lines 1-22
Link Here
|
1 |
package Koha::BackgroundJob::BatchUpdateAuthority; |
1 |
package Koha::BackgroundJob::BatchUpdateAuthority; |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
|
|
4 |
use JSON qw( encode_json decode_json ); |
5 |
|
6 |
use C4::MarcModificationTemplates; |
7 |
use C4::AuthoritiesMarc; |
4 |
use Koha::BackgroundJobs; |
8 |
use Koha::BackgroundJobs; |
5 |
use Koha::DateUtils qw( dt_from_string ); |
9 |
use Koha::DateUtils qw( dt_from_string ); |
6 |
use JSON qw( encode_json decode_json ); |
10 |
use Koha::MetadataRecord::Authority; |
7 |
|
11 |
|
8 |
use base 'Koha::BackgroundJob'; |
12 |
use base 'Koha::BackgroundJob'; |
9 |
|
13 |
|
10 |
our $channel; |
14 |
sub job_type { |
11 |
sub process { |
15 |
return 'batch_authority_record_modification'; |
12 |
my ( $self, $args, $channel ) = @_; |
16 |
} |
13 |
|
|
|
14 |
my $job_type = $args->{job_type}; |
15 |
|
17 |
|
16 |
return unless exists $args->{job_id}; |
18 |
sub process { |
|
|
19 |
my ( $self, $args ) = @_; |
17 |
|
20 |
|
18 |
my $job = Koha::BackgroundJobs->find( $args->{job_id} ); |
21 |
my $job = Koha::BackgroundJobs->find( $args->{job_id} ); |
19 |
|
22 |
|
|
|
23 |
if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) { |
24 |
return; |
25 |
} |
26 |
|
20 |
my $job_progress = 0; |
27 |
my $job_progress = 0; |
21 |
$job->started_on(dt_from_string) |
28 |
$job->started_on(dt_from_string) |
22 |
->progress($job_progress) |
29 |
->progress($job_progress) |
Lines 28-41
sub process {
Link Here
|
28 |
my @record_ids = @{ $args->{record_ids} }; |
35 |
my @record_ids = @{ $args->{record_ids} }; |
29 |
|
36 |
|
30 |
my $report = { |
37 |
my $report = { |
31 |
total_records => 0, |
38 |
total_records => scalar @record_ids, |
32 |
total_success => 0, |
39 |
total_success => 0, |
33 |
}; |
40 |
}; |
34 |
my @messages; |
41 |
my @messages; |
35 |
my $dbh = C4::Context->dbh; |
42 |
my $dbh = C4::Context->dbh; |
36 |
$dbh->{RaiseError} = 1; |
43 |
$dbh->{RaiseError} = 1; |
37 |
RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { |
44 |
RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { |
38 |
$report->{total_records}++; |
|
|
39 |
next unless $record_id; |
45 |
next unless $record_id; |
40 |
# Authorities |
46 |
# Authorities |
41 |
my $authid = $record_id; |
47 |
my $authid = $record_id; |
Lines 68-78
sub process {
Link Here
|
68 |
$job_data->{report} = $report; |
74 |
$job_data->{report} = $report; |
69 |
|
75 |
|
70 |
$job->ended_on(dt_from_string) |
76 |
$job->ended_on(dt_from_string) |
71 |
->status('finished') |
77 |
->data(encode_json $job_data); |
72 |
->data(encode_json $job_data) |
78 |
$job->status('finished') if $job->status ne 'cancelled'; |
73 |
->store; |
79 |
$job->store; |
74 |
|
80 |
|
75 |
$channel->ack(); # FIXME Is that ok even on failure? |
|
|
76 |
} |
81 |
} |
77 |
|
82 |
|
78 |
sub enqueue { |
83 |
sub enqueue { |
Lines 88-94
sub enqueue {
Link Here
|
88 |
my @record_ids = @{ $args->{record_ids} }; |
93 |
my @record_ids = @{ $args->{record_ids} }; |
89 |
|
94 |
|
90 |
$self->SUPER::enqueue({ |
95 |
$self->SUPER::enqueue({ |
91 |
job_type => 'batch_record_modification', |
|
|
92 |
job_size => scalar @record_ids, |
96 |
job_size => scalar @record_ids, |
93 |
job_args => {mmtid => $mmtid, record_type => $record_type, record_ids => \@record_ids,} |
97 |
job_args => {mmtid => $mmtid, record_type => $record_type, record_ids => \@record_ids,} |
94 |
}); |
98 |
}); |