Lines 3-9
package Koha::BackgroundJob::BatchDeleteBiblio;
Link Here
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use JSON qw( encode_json decode_json ); |
4 |
use JSON qw( encode_json decode_json ); |
5 |
|
5 |
|
6 |
use Koha::BackgroundJobs; |
|
|
7 |
use Koha::DateUtils qw( dt_from_string ); |
6 |
use Koha::DateUtils qw( dt_from_string ); |
8 |
use C4::Biblio; |
7 |
use C4::Biblio; |
9 |
|
8 |
|
Lines 38-48
Process the job.
Link Here
|
38 |
sub process { |
37 |
sub process { |
39 |
my ( $self, $args ) = @_; |
38 |
my ( $self, $args ) = @_; |
40 |
|
39 |
|
41 |
my $job_type = $args->{job_type}; |
40 |
if ( $self->status eq 'cancelled' ) { |
42 |
|
|
|
43 |
my $job = Koha::BackgroundJobs->find( $args->{job_id} ); |
44 |
|
45 |
if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) { |
46 |
return; |
41 |
return; |
47 |
} |
42 |
} |
48 |
|
43 |
|
Lines 50-56
sub process {
Link Here
|
50 |
# Then we will start from scratch and so double delete the same records |
45 |
# Then we will start from scratch and so double delete the same records |
51 |
|
46 |
|
52 |
my $job_progress = 0; |
47 |
my $job_progress = 0; |
53 |
$job->started_on(dt_from_string) |
48 |
$self->started_on(dt_from_string) |
54 |
->progress($job_progress) |
49 |
->progress($job_progress) |
55 |
->status('started') |
50 |
->status('started') |
56 |
->store; |
51 |
->store; |
Lines 66-72
sub process {
Link Here
|
66 |
my $schema = Koha::Database->new->schema; |
61 |
my $schema = Koha::Database->new->schema; |
67 |
RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { |
62 |
RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { |
68 |
|
63 |
|
69 |
last if $job->get_from_storage->status eq 'cancelled'; |
64 |
last if $self->get_from_storage->status eq 'cancelled'; |
70 |
|
65 |
|
71 |
next unless $record_id; |
66 |
next unless $record_id; |
72 |
|
67 |
|
Lines 85-91
sub process {
Link Here
|
85 |
biblionumber => $biblionumber, |
80 |
biblionumber => $biblionumber, |
86 |
}; |
81 |
}; |
87 |
$schema->storage->txn_rollback; |
82 |
$schema->storage->txn_rollback; |
88 |
$job->progress( ++$job_progress )->store; |
83 |
$self->progress( ++$job_progress )->store; |
89 |
next; |
84 |
next; |
90 |
} |
85 |
} |
91 |
|
86 |
|
Lines 104-110
sub process {
Link Here
|
104 |
error => "$@", |
99 |
error => "$@", |
105 |
}; |
100 |
}; |
106 |
$schema->storage->txn_rollback; |
101 |
$schema->storage->txn_rollback; |
107 |
$job->progress( ++$job_progress )->store; |
102 |
$self->progress( ++$job_progress )->store; |
108 |
next RECORD_IDS; |
103 |
next RECORD_IDS; |
109 |
} |
104 |
} |
110 |
} |
105 |
} |
Lines 122-128
sub process {
Link Here
|
122 |
error => @{$deleted->messages}[0]->message, |
117 |
error => @{$deleted->messages}[0]->message, |
123 |
}; |
118 |
}; |
124 |
$schema->storage->txn_rollback; |
119 |
$schema->storage->txn_rollback; |
125 |
$job->progress( ++$job_progress )->store; |
120 |
$self->progress( ++$job_progress )->store; |
126 |
next RECORD_IDS; |
121 |
next RECORD_IDS; |
127 |
} |
122 |
} |
128 |
} |
123 |
} |
Lines 139-145
sub process {
Link Here
|
139 |
error => ($@ ? $@ : $error), |
134 |
error => ($@ ? $@ : $error), |
140 |
}; |
135 |
}; |
141 |
$schema->storage->txn_rollback; |
136 |
$schema->storage->txn_rollback; |
142 |
$job->progress( ++$job_progress )->store; |
137 |
$self->progress( ++$job_progress )->store; |
143 |
next; |
138 |
next; |
144 |
} |
139 |
} |
145 |
|
140 |
|
Lines 150-166
sub process {
Link Here
|
150 |
}; |
145 |
}; |
151 |
$report->{total_success}++; |
146 |
$report->{total_success}++; |
152 |
$schema->storage->txn_commit; |
147 |
$schema->storage->txn_commit; |
153 |
$job->progress( ++$job_progress )->store; |
148 |
$self->progress( ++$job_progress )->store; |
154 |
} |
149 |
} |
155 |
|
150 |
|
156 |
my $job_data = decode_json $job->data; |
151 |
my $job_data = decode_json $self->data; |
157 |
$job_data->{messages} = \@messages; |
152 |
$job_data->{messages} = \@messages; |
158 |
$job_data->{report} = $report; |
153 |
$job_data->{report} = $report; |
159 |
|
154 |
|
160 |
$job->ended_on(dt_from_string) |
155 |
$self->ended_on(dt_from_string) |
161 |
->data(encode_json $job_data); |
156 |
->data(encode_json $job_data); |
162 |
$job->status('finished') if $job->status ne 'cancelled'; |
157 |
$self->status('finished') if $self->status ne 'cancelled'; |
163 |
$job->store; |
158 |
$self->store; |
164 |
} |
159 |
} |
165 |
|
160 |
|
166 |
=head3 enqueue |
161 |
=head3 enqueue |