From 170020d453f3e6fdb57c9ea897da5e6efa75d574 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 1 Oct 2021 09:22:58 -0300 Subject: [PATCH] Bug 29149: (QA follow-up) Reorganize mapping This patch changes the mapping so it is more readable, and also allows adding things there more easily, like allowing to add code => class mappings from plugins, when time comes. To test: 1. Just verify things still work Signed-off-by: Jonathan Druart --- Koha/BackgroundJob.pm | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 553d7ce6e6..f67809d014 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -228,20 +228,41 @@ sub cancel { $self->status('cancelled')->store; } +=head2 Internal methods + +=head3 _derived_class + +=cut + sub _derived_class { my ( $self ) = @_; my $job_type = $self->type; - return $job_type eq 'batch_biblio_record_modification' - ? Koha::BackgroundJob::BatchUpdateBiblio->new - : $job_type eq 'batch_authority_record_modification' - ? Koha::BackgroundJob::BatchUpdateAuthority->new - : $job_type eq 'batch_biblio_record_deletion' - ? Koha::BackgroundJob::BatchDeleteBiblio->new - : $job_type eq 'batch_authority_record_deletion' - ? Koha::BackgroundJob::BatchDeleteAuthority->new - : Koha::Exceptions::Exception->throw($job_type . ' is not a valid job_type') + + my $class = $self->type_to_class_mapping->{$job_type}; + + Koha::Exceptions::Exception->throw($job_type . ' is not a valid job_type') + unless $class; + + return $class->new; +} + +=head3 type_to_class_mapping + +=cut + +sub type_to_class_mapping { + return { + batch_authority_record_deletion => 'Koha::BackgroundJob::BatchDeleteAuthority', + batch_authority_record_modification => 'Koha::BackgroundJob::BatchUpdateAuthority', + batch_biblio_record_deletion => 'Koha::BackgroundJob::BatchDeleteBiblio', + batch_biblio_record_modification => 'Koha::BackgroundJob::BatchUpdateBiblio', + }; } +=head3 _type + +=cut + sub _type { return 'BackgroundJob'; } -- 2.39.5