Bug 29149: Add the capability to provide more info to the background job detail view
(Patch extracted from bug 28445 to make it reusable for bug 23678) We already had the need for that, when bibliographic records are modified in batch we wanted to add a "Add to list" feature, and so pass a list of lists/virtual shelves to the template. Here (in 28445) we will want to pass the infos of the items that have been modified to display a table. Test plan: 0. Create at least one list (virtual shelf) 1. batch update biblios 2. Go to the job detail 3. Notice that dropdown list to add the record to a list => No regression found! Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
ccc4be5dc9
commit
987a494068
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue