Bugzilla – Attachment 107485 Details for
Bug 26080
Use the task queue for the batch delete records tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26080: Use the task queue for batch delete authorities
Bug-26080-Use-the-task-queue-for-batch-delete-auth.patch (text/plain), 9.70 KB, created by
Jonathan Druart
on 2020-07-29 10:40:07 UTC
(
hide
)
Description:
Bug 26080: Use the task queue for batch delete authorities
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-07-29 10:40:07 UTC
Size:
9.70 KB
patch
obsolete
>From d9a8b697b9ff87faf6a5e8b7133c7bf00f355124 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 29 Jul 2020 12:13:39 +0200 >Subject: [PATCH] Bug 26080: Use the task queue for batch delete authorities > >Same as the first patch, for authorities > >Test plan: >Delete authority records using the batch record deletion tool >Confirm that the job is now delegated to the task queue and that >everything else is working as before >--- > Koha/BackgroundJob.pm | 3 + > Koha/BackgroundJob/BatchDeleteAuthority.pm | 101 ++++++++++++++++++ > .../batch_authority_record_deletion.inc | 42 ++++++++ > .../en/modules/tools/batch_delete_records.tt | 18 +--- > misc/background_jobs_worker.pl | 1 + > tools/batch_delete_records.pl | 1 + > 6 files changed, 153 insertions(+), 13 deletions(-) > create mode 100644 Koha/BackgroundJob/BatchDeleteAuthority.pm > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_authority_record_deletion.inc > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 07a71ff71f..38326421db 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -11,6 +11,7 @@ use Koha::Exceptions; > use Koha::BackgroundJob::BatchUpdateBiblio; > use Koha::BackgroundJob::BatchUpdateAuthority; > use Koha::BackgroundJob::BatchDeleteBiblio; >+use Koha::BackgroundJob::BatchDeleteAuthority; > > use Scalar::Util qw( weaken ); > >@@ -74,6 +75,8 @@ sub process { > ? Koha::BackgroundJob::BatchUpdateAuthority->process($args) > : $job_type eq 'batch_biblio_record_deletion' > ? Koha::BackgroundJob::BatchDeleteBiblio->process($args) >+ : $job_type eq 'batch_authority_record_deletion' >+ ? Koha::BackgroundJob::BatchDeleteAuthority->process($args) > : Koha::Exceptions::Exception->throw('->process called without valid job_type'); > } > >diff --git a/Koha/BackgroundJob/BatchDeleteAuthority.pm b/Koha/BackgroundJob/BatchDeleteAuthority.pm >new file mode 100644 >index 0000000000..18a3202a6e >--- /dev/null >+++ b/Koha/BackgroundJob/BatchDeleteAuthority.pm >@@ -0,0 +1,101 @@ >+package Koha::BackgroundJob::BatchDeleteAuthority; >+ >+use Modern::Perl; >+use JSON qw( encode_json decode_json ); >+ >+use Koha::BackgroundJobs; >+use Koha::DateUtils qw( dt_from_string ); >+use C4::AuthoritiesMarc; >+ >+use base 'Koha::BackgroundJob'; >+ >+sub job_type { >+ return 'batch_authority_record_deletion'; >+} >+ >+sub process { >+ my ( $self, $args ) = @_; >+ >+ my $job_type = $args->{job_type}; >+ >+ my $job = Koha::BackgroundJobs->find( $args->{job_id} ); >+ >+ if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) { >+ return; >+ } >+ >+ # FIXME If the job has already been started, but started again (worker has been restart for instance) >+ # Then we will start from scratch and so double delete the same records >+ >+ my $job_progress = 0; >+ $job->started_on(dt_from_string) >+ ->progress($job_progress) >+ ->status('started') >+ ->store; >+ >+ my $mmtid = $args->{mmtid}; >+ my @record_ids = @{ $args->{record_ids} }; >+ >+ my $report = { >+ total_records => scalar @record_ids, >+ total_success => 0, >+ }; >+ my @messages; >+ my $schema = Koha::Database->new->schema; >+ RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { >+ >+ last if $job->get_from_storage->status eq 'cancelled'; >+ >+ next unless $record_id; >+ >+ $schema->storage->txn_begin; >+ >+ my $authid = $record_id; >+ eval { C4::AuthoritiesMarc::DelAuthority({ authid => $authid }) }; >+ if ( $@ ) { >+ push @messages, { >+ type => 'error', >+ code => 'authority_not_deleted', >+ authid => $authid, >+ error => ($@ ? $@ : 0), >+ }; >+ $schema->storage->txn_rollback; >+ next; >+ } else { >+ push @messages, { >+ type => 'success', >+ code => 'authority_deleted', >+ authid => $authid, >+ }; >+ $report->{total_success}++; >+ $schema->storage->txn_commit; >+ } >+ >+ $job->progress( ++$job_progress )->store; >+ } >+ >+ my $job_data = decode_json $job->data; >+ $job_data->{messages} = \@messages; >+ $job_data->{report} = $report; >+ >+ $job->ended_on(dt_from_string) >+ ->data(encode_json $job_data); >+ $job->status('finished') if $job->status ne 'cancelled'; >+ $job->store; >+} >+ >+sub enqueue { >+ my ( $self, $args) = @_; >+ >+ # TODO Raise exception instead >+ return unless exists $args->{record_ids}; >+ >+ my @record_ids = @{ $args->{record_ids} }; >+ >+ $self->SUPER::enqueue({ >+ job_size => scalar @record_ids, >+ job_args => {record_ids => \@record_ids,} >+ }); >+} >+ >+1; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_authority_record_deletion.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_authority_record_deletion.inc >new file mode 100644 >index 0000000000..f9e24aff39 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_authority_record_deletion.inc >@@ -0,0 +1,42 @@ >+[% BLOCK report %] >+ [% SET report = job.report %] >+ [% IF report %] >+ [% IF report.total_records == report.total_success %] >+ <div class="dialog message"> >+ All records have been deleted successfully! >+ </div> >+ [% ELSIF report.total_success == 0 %] >+ <div class="dialog message"> >+ No record has been deleted. An error occurred. >+ </div> >+ [% ELSE %] >+ <div class="dialog message"> >+ [% report.total_success | html %] / [% report.total_records | html %] records have been deleted successfully but some errors occurred. >+ </div> >+ [% END %] >+ [% END %] >+[% END %] >+ >+[% BLOCK detail %] >+ [% FOR m IN job.messages %] >+ <div class="dialog message"> >+ [% IF m.type == 'success' %] >+ <i class="fa fa-check success"></i> >+ [% ELSIF m.type == 'warning' %] >+ <i class="fa fa-warning warn"></i> >+ [% ELSIF m.type == 'error' %] >+ <i class="fa fa-exclamation error"></i> >+ [% END %] >+ [% IF m.code == 'authority_not_exists' %] >+ The authority id [% m.authid | html %] does not exist in the database. >+ [% ELSIF m.code == 'authority_not_deleted' %] >+ Authority record [% m.authid | html %] was not deleted. An error occurred. >+ [% ELSIF m.code == 'authority_deleted' %] >+ Authority [% m.authid | html %] has been deleted successfully. >+ [% END %] >+ </div> >+ [% END %] >+[% END %] >+ >+[% BLOCK js %] >+[% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt >index 82d57acec4..533e982127 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt >@@ -35,13 +35,14 @@ > The biblionumber [% message.biblionumber | html %] does not exist in the database. > [% ELSIF message.code == 'authority_not_exists' %] > The authority id [% message.authid | html %] does not exist in the database. >- [% ELSIF message.code == 'authority_not_deleted' %] >- Authority record [% message.authid | html %] was not deleted. An error occurred. >- [% ELSIF message.code == 'authority_deleted' %] >- Authority [% message.authid | html %] has been deleted successfully. > [% ELSIF message.code == 'cannot_enqueue_job' %] > Cannot enqueue this job. >+ [% ELSIF message.code == 'biblio_not_exists' %] >+ Bibliographic record [% message.biblionumber | html %] does not exist in the database. >+ [% ELSIF message.code == 'authority_not_exists' %] >+ Authority record [% message.authid | html %] does not exist in the database. > [% END %] >+ > [% IF message.error %] > (The error was: [% message.error | html %], see the Koha log file for more information). > [% END %] >@@ -190,15 +191,6 @@ > [% ELSE %] > There are no record ids defined. > [% END %] >- [% ELSIF op == 'report' %] >- [% IF report.total_records == report.total_success %] >- All records have been deleted successfully! >- [% ELSIF report.total_success == 0 %] >- No record has been deleted. An error occurred. >- [% ELSE %] >- [% report.total_success | html %] / [% report.total_records | html %] records have been deleted successfully but some errors occurred. >- [% END %] >- <p><a href="/cgi-bin/koha/tools/batch_delete_records.pl" title="New batch record deletion">New batch record deletion</a></p> > [% ELSIF op == 'enqueued' %] > <div class="dialog message"> > <p>The job has been enqueued! It will be processed as soon as possible.</p> >diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl >index 9b9dab7455..8078e1ca7b 100755 >--- a/misc/background_jobs_worker.pl >+++ b/misc/background_jobs_worker.pl >@@ -26,6 +26,7 @@ my @job_types = qw( > batch_biblio_record_modification > batch_authority_record_modification > batch_biblio_record_deletion >+ batch_authority_record_deletion > ); > > # FIXME cf note in Koha::BackgroundJob about $namespace >diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl >index 4b7fea5592..715b681f2a 100755 >--- a/tools/batch_delete_records.pl >+++ b/tools/batch_delete_records.pl >@@ -34,6 +34,7 @@ use Koha::Authorities; > use Koha::Biblios; > use Koha::Items; > use Koha::BackgroundJob::BatchDeleteBiblio; >+use Koha::BackgroundJob::BatchDeleteAuthority; > > my $input = new CGI; > my $op = $input->param('op') // q|form|; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26080
:
107483
|
107484
|
107485
|
122347
|
122348
|
122349
|
123214
|
123215
|
123216
|
123989
|
123990
|
123991
|
124408
|
124409
|
124410
|
124411
|
124412