@@ -, +, @@ background job detail view --- Koha/BackgroundJob.pm | 48 +++++++++++++++++++------ Koha/BackgroundJob/BatchUpdateBiblio.pm | 23 ++++++++++++ admin/background_jobs.pl | 10 ++---- t/db_dependent/Koha/BackgroundJobs.t | 8 ++++- 4 files changed, 70 insertions(+), 19 deletions(-) --- a/Koha/BackgroundJob.pm +++ a/Koha/BackgroundJob.pm @@ -152,16 +152,14 @@ Process the job! sub process { my ( $self, $args ) = @_; - my $job_type = $self->type; - return $job_type eq 'batch_biblio_record_modification' - ? Koha::BackgroundJob::BatchUpdateBiblio->process($args) - : $job_type eq 'batch_authority_record_modification' - ? 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'); + return {} if ref($self) ne 'Koha::BackgroundJob'; + + my $derived_class = $self->_derived_class; + + $args ||= {}; + + return $derived_class->process({job_id => $self->id, %$args}); + } =head3 job_type @@ -203,6 +201,22 @@ sub report { return $data_dump->{report}; } +=head3 additional_report + +Build additional variables for the job detail view. + +=cut + +sub additional_report { + my ( $self ) = @_; + + return {} if ref($self) ne 'Koha::BackgroundJob'; + + my $derived_class = $self->_derived_class; + + return $derived_class->additional_report({job_id => $self->id}); +} + =head3 cancel Cancel a job. @@ -214,6 +228,20 @@ sub cancel { $self->status('cancelled')->store; } +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') +} + sub _type { return 'BackgroundJob'; } --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ a/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -20,6 +20,9 @@ use JSON qw( decode_json encode_json ); use Koha::BackgroundJobs; use Koha::DateUtils qw( dt_from_string ); +use Koha::Virtualshelves; + +use C4::Context; use C4::Biblio; use C4::MarcModificationTemplates; @@ -140,4 +143,24 @@ sub enqueue { }); } +=head3 additional_report + +Pass the list of lists/virtual shelves the logged in user has write permissions. + +It will enable the "add modified records to list" feature. + +=cut + +sub additional_report { + my ($self) = @_; + + my $loggedinuser = C4::Context->userenv ? C4::Context->userenv->{'number'} : undef; + return { + lists => scalar Koha::Virtualshelves->search( + [ { category => 1, owner => $loggedinuser }, { category => 2 } ] + ), + }; + +} + 1; --- a/admin/background_jobs.pl +++ a/admin/background_jobs.pl @@ -51,14 +51,8 @@ if ( $op eq 'view' ) { } else { $template->param( job => $job, ); - $template->param( - lists => scalar Koha::Virtualshelves->search( - [ - { category => 1, owner => $loggedinuser }, - { category => 2 } - ] - ) - ) if $job->type eq 'batch_biblio_record_modification'; + my $report = $job->additional_report() || {}; + $template->param( %$report ); } } else { $op = 'list'; --- a/t/db_dependent/Koha/BackgroundJobs.t +++ a/t/db_dependent/Koha/BackgroundJobs.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 11; +use Test::More tests => 12; use Test::MockModule; use JSON qw( decode_json ); @@ -40,6 +40,10 @@ t::lib::Mocks::mock_userenv; my $net_stomp = Test::MockModule->new('Net::Stomp'); $net_stomp->mock( 'send_with_receipt', sub { return 1 } ); +my $background_job_module = Test::MockModule->new('Koha::BackgroundJob'); +$background_job_module->mock( '_derived_class', + sub { t::lib::Koha::BackgroundJob::BatchTest->new } ); + my $data = { a => 'aaa', b => 'bbb' }; my $job_size = 10; my $job_id = t::lib::Koha::BackgroundJob::BatchTest->new->enqueue( @@ -80,4 +84,6 @@ is_deeply( 'Correct number of records processed' ); +is_deeply( $new_job->additional_report(), {} ); + $schema->storage->txn_rollback; --