From 4708933800fde69a853b59cf57f4f171ac2eef4a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 28 Apr 2022 10:57:04 -0300 Subject: [PATCH] Bug 29346: Add better reporting Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens Signed-off-by: Fridolin Somers --- .../BatchUpdateBiblioHoldsQueue.pm | 23 ++++------- .../update_holds_queue_for_biblios.inc | 41 +++++++++++++++++++ .../prog/en/modules/admin/background_jobs.tt | 2 + 3 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/update_holds_queue_for_biblios.inc diff --git a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm index 852ff065ac..c85de205ff 100644 --- a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm +++ b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm @@ -20,6 +20,7 @@ use Modern::Perl; use JSON qw( encode_json decode_json ); use Try::Tiny; +use Koha::Biblios; use Koha::Exceptions; use C4::HoldsQueue @@ -59,12 +60,10 @@ sub process { my $schema = Koha::Database->new->schema; - my $job_progress = 0; - $self->set( { started_on => \'NOW()', - progress => $job_progress, + progress => 0, status => 'started', } )->store; @@ -100,26 +99,25 @@ sub process { type => 'success', code => 'holds_queue_updated', biblio_id => $biblio_id, - available_items => $result->{available_items}, - mapped_items => $result->{mapped_items}, - requests => $result->{requests}, }; $report->{total_success}++; $schema->storage->txn_commit; } catch { - push @messages, { + + push @messages, + { type => 'error', code => 'holds_queue_update_error', biblio_id => $biblio_id, error => "$_", - }; + }; $schema->storage->txn_rollback; }; - $self->progress( $job_progress++ )->store; + $self->progress( $self->progress + 1 )->store; } my $job_data = decode_json $self->data; @@ -130,12 +128,9 @@ sub process { { ended_on => \'NOW()', data => encode_json $job_data, + status => 'finished', } - ); - $self->status('finished') - unless $self->status ne 'cancelled'; - - $self->store; + )->store; } =head3 enqueue diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/update_holds_queue_for_biblios.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/update_holds_queue_for_biblios.inc new file mode 100644 index 0000000000..2928785ffb --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/update_holds_queue_for_biblios.inc @@ -0,0 +1,41 @@ +[% USE KohaSpan %] +[% BLOCK report %] + [% SET report = job.report %] + [% IF report %] + [% IF report.total_biblios == report.total_success %] +
+ Holds queue successfully updated. +
+ [% ELSE %] +
+ Holds queue for [% report.total_success | html %] / [% report.total_biblios | html %] has been successfully updated. Some errors occurred. + [% IF job.status == 'cancelled' %]The job has been cancelled before it finished.[% END %] +
+ [% END %] + [% END %] + +[% END %] + +[% BLOCK detail %] + [% FOR m IN report_messages %] +
+ [% IF m.type == 'success' %] + + [% ELSIF m.type == 'warning' %] + + [% ELSIF m.type == 'error' %] + + [% END %] + [% SWITCH m.code %] + [% CASE 'holds_queue_update_error' %] + [% IF m.biblio_id %] + Holds queue for biblio [% m.biblio.title | html %]. + [% END %] + An error occurred ([% m.error | html %]) + [% END %] +
+ [% END %] +[% END %] + +[% BLOCK js %] +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt index 05703abaf1..4da24feed3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt @@ -39,6 +39,8 @@ Batch hold cancellation [% CASE 'update_elastic_index' %] Update Elasticsearch index + [% CASE 'update_holds_queue_for_biblios' %] + Holds queue update [% CASE %]Unknown job type '[% job_type | html %]' [% END %] -- 2.39.5