From d4faa97f8ee1e44beeed48ce7bac9466ab46780b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20=E2=80=9Etadzik=E2=80=9D=20So=C5=9Bnierz?= Date: Wed, 30 Apr 2025 12:09:46 +0200 Subject: [PATCH] Bug 39772: Extend background_tasks API to allow for human-readable job names --- Koha/BackgroundJob.pm | 7 ++-- admin/background_jobs.pl | 5 ++- .../prog/en/modules/admin/background_jobs.tt | 36 +++++++++---------- t/lib/plugins/Koha/Plugin/Test.pm | 5 ++- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 154c00e1e8..fb1594a95a 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -479,14 +479,17 @@ sub plugin_types_to_classes { my $namespace = $metadata->{namespace}; foreach my $type ( keys %{$tasks} ) { - my $class = $tasks->{$type}; + my $class = + ( ref $tasks->{$type} eq 'HASH' ) + ? $tasks->{$type}{class} + : $tasks->{$type}; # skip if conditions not met next unless $type and $class; my $key = "plugin_$namespace" . "_$type"; - $self->{_plugin_mapping}->{$key} = $tasks->{$type}; + $self->{_plugin_mapping}->{$key} = $class; } } } diff --git a/admin/background_jobs.pl b/admin/background_jobs.pl index d51877545b..275e8bcb89 100755 --- a/admin/background_jobs.pl +++ b/admin/background_jobs.pl @@ -88,9 +88,12 @@ my @plugin_job_types; for my $plugin (@plugins) { my $tasks = $plugin->background_tasks; for my $id ( keys %$tasks ) { + + # fallback to package name if no human-readable name is available + my $name = ( ref $tasks->{$id} eq 'HASH' ) ? $tasks->{$id}{name} : $tasks->{$id}; push @plugin_job_types, { id => 'plugin_' . $plugin->get_metadata->{namespace} . "_$id", - str => $tasks->{$id}, + str => $name, }; } } 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 c9ba94cd17..91d0e1487b 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 @@ -165,72 +165,72 @@ const job_types = [ { '_id': 'batch_biblio_record_modification', - '_str': _("Batch bibliographic record modification") + '_str': _("Batch bibliographic record modification").escapeHtml() }, { '_id': 'batch_biblio_record_deletion', - '_str': _("Batch bibliographic record deletion") + '_str': _("Batch bibliographic record deletion").escapeHtml() }, { '_id': 'batch_authority_record_modification', - '_str': _("Batch authority record modification") + '_str': _("Batch authority record modification").escapeHtml() }, { '_id': 'batch_authority_record_deletion', - '_str': _("Batch authority record deletion") + '_str': _("Batch authority record deletion").escapeHtml() }, { '_id': 'batch_item_record_modification', - '_str': _("Batch item record modification") + '_str': _("Batch item record modification").escapeHtml() }, { '_id': 'batch_item_record_deletion', - '_str': _("Batch item record deletion") + '_str': _("Batch item record deletion").escapeHtml() }, { '_id': 'erm_sushi_harvester', - '_str': _("ERM Usage Statistics SUSHI Harvester") + '_str': _("ERM Usage Statistics SUSHI Harvester").escapeHtml() }, { '_id': 'batch_hold_cancel', - '_str': _("Batch hold cancellation") + '_str': _("Batch hold cancellation").escapeHtml() }, { '_id': 'pseudonymize_statistic', - '_str': _("Pseudonymize statistic") + '_str': _("Pseudonymize statistic").escapeHtml() }, { '_id': 'create_eholdings_from_biblios', - '_str': _("Create eHolding titles") + '_str': _("Create eHolding titles").escapeHtml() }, { '_id': 'update_elastic_index', - '_str': _("Update Elasticsearch index") + '_str': _("Update Elasticsearch index").escapeHtml() }, { '_id': 'update_holds_queue_for_biblios', - '_str': _("Holds queue update") + '_str': _("Holds queue update").escapeHtml() }, { '_id': 'stage_marc_for_import', - '_str': _("Staged MARC records for import") + '_str': _("Staged MARC records for import").escapeHtml() }, { '_id': 'marc_import_commit_batch', - '_str': _("Import MARC records") + '_str': _("Import MARC records").escapeHtml() }, { '_id': 'marc_import_revert_batch', - '_str': _("Revert import MARC records") + '_str': _("Revert import MARC records").escapeHtml() }, { '_id': 'import_from_kbart_file', - '_str': _("Import titles from a KBART file") + '_str': _("Import titles from a KBART file").escapeHtml() }, [% FOR job_type IN plugin_job_types %] { '_id': '[% job_type.id %]', - '_str': '[% job_type.str %]' + '_str': '[% job_type.str | html_entity %]' }, [% END %] ]; @@ -290,7 +290,7 @@ "searchable": true, "orderable": true, "render": function(data, type, row, meta) { - return get_job_type(row.type).escapeHtml(); + return get_job_type(row.type); } }, { diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm index df7c34f21b..77600be3d5 100644 --- a/t/lib/plugins/Koha/Plugin/Test.pm +++ b/t/lib/plugins/Koha/Plugin/Test.pm @@ -366,7 +366,10 @@ sub intranet_catalog_biblio_tab { sub background_tasks { return { foo => 'MyPlugin::Class::Foo', - bar => 'MyPlugin::Class::Bar', + bar => { + class => 'MyPlugin::Class::Bar', + name => "Bar task", + }, }; } -- 2.47.2