View | Details | Raw Unified | Return to bug 29149
Collapse All | Expand All

(-)a/Koha/BackgroundJob.pm (-10 / +38 lines)
Lines 152-167 Process the job! Link Here
152
sub process {
152
sub process {
153
    my ( $self, $args ) = @_;
153
    my ( $self, $args ) = @_;
154
154
155
    my $job_type = $self->type;
155
    return {} if ref($self) ne 'Koha::BackgroundJob';
156
    return $job_type eq 'batch_biblio_record_modification'
156
157
      ? Koha::BackgroundJob::BatchUpdateBiblio->process($args)
157
    my $derived_class = $self->_derived_class;
158
      : $job_type eq 'batch_authority_record_modification'
158
159
      ? Koha::BackgroundJob::BatchUpdateAuthority->process($args)
159
    $args ||= {};
160
      : $job_type eq 'batch_biblio_record_deletion'
160
161
      ? Koha::BackgroundJob::BatchDeleteBiblio->process($args)
161
    return $derived_class->process({job_id => $self->id, %$args});
162
      : $job_type eq 'batch_authority_record_deletion'
162
163
      ? Koha::BackgroundJob::BatchDeleteAuthority->process($args)
164
      : Koha::Exceptions::Exception->throw('->process called without valid job_type');
165
}
163
}
166
164
167
=head3 job_type
165
=head3 job_type
Lines 203-208 sub report { Link Here
203
    return $data_dump->{report};
201
    return $data_dump->{report};
204
}
202
}
205
203
204
=head3 additional_report
205
206
Build additional variables for the job detail view.
207
208
=cut
209
210
sub additional_report {
211
    my ( $self ) = @_;
212
213
    return {} if ref($self) ne 'Koha::BackgroundJob';
214
215
    my $derived_class = $self->_derived_class;
216
217
    return $derived_class->additional_report({job_id => $self->id});
218
}
219
206
=head3 cancel
220
=head3 cancel
207
221
208
Cancel a job.
222
Cancel a job.
Lines 214-219 sub cancel { Link Here
214
    $self->status('cancelled')->store;
228
    $self->status('cancelled')->store;
215
}
229
}
216
230
231
sub _derived_class {
232
    my ( $self ) = @_;
233
    my $job_type = $self->type;
234
    return $job_type eq 'batch_biblio_record_modification'
235
      ? Koha::BackgroundJob::BatchUpdateBiblio->new
236
      : $job_type eq 'batch_authority_record_modification'
237
      ? Koha::BackgroundJob::BatchUpdateAuthority->new
238
      : $job_type eq 'batch_biblio_record_deletion'
239
      ? Koha::BackgroundJob::BatchDeleteBiblio->new
240
      : $job_type eq 'batch_authority_record_deletion'
241
      ? Koha::BackgroundJob::BatchDeleteAuthority->new
242
      : Koha::Exceptions::Exception->throw($job_type . ' is not a valid job_type')
243
}
244
217
sub _type {
245
sub _type {
218
    return 'BackgroundJob';
246
    return 'BackgroundJob';
219
}
247
}
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (+23 lines)
Lines 20-25 use JSON qw( decode_json encode_json ); Link Here
20
20
21
use Koha::BackgroundJobs;
21
use Koha::BackgroundJobs;
22
use Koha::DateUtils qw( dt_from_string );
22
use Koha::DateUtils qw( dt_from_string );
23
use Koha::Virtualshelves;
24
25
use C4::Context;
23
use C4::Biblio;
26
use C4::Biblio;
24
use C4::MarcModificationTemplates;
27
use C4::MarcModificationTemplates;
25
28
Lines 140-143 sub enqueue { Link Here
140
    });
143
    });
141
}
144
}
142
145
146
=head3 additional_report
147
148
Pass the list of lists/virtual shelves the logged in user has write permissions.
149
150
It will enable the "add modified records to list" feature.
151
152
=cut
153
154
sub additional_report {
155
    my ($self) = @_;
156
157
    my $loggedinuser = C4::Context->userenv ? C4::Context->userenv->{'number'} : undef;
158
    return {
159
        lists => scalar Koha::Virtualshelves->search(
160
            [ { category => 1, owner => $loggedinuser }, { category => 2 } ]
161
        ),
162
    };
163
164
}
165
143
1;
166
1;
(-)a/admin/background_jobs.pl (-8 / +2 lines)
Lines 51-64 if ( $op eq 'view' ) { Link Here
51
        }
51
        }
52
        else {
52
        else {
53
            $template->param( job => $job, );
53
            $template->param( job => $job, );
54
            $template->param(
54
            my $report = $job->additional_report() || {};
55
                lists => scalar Koha::Virtualshelves->search(
55
            $template->param( %$report );
56
                    [
57
                        { category => 1, owner => $loggedinuser },
58
                        { category => 2 }
59
                    ]
60
                )
61
            ) if $job->type eq 'batch_biblio_record_modification';
62
        }
56
        }
63
    } else {
57
    } else {
64
        $op = 'list';
58
        $op = 'list';
(-)a/t/db_dependent/Koha/BackgroundJobs.t (-2 / +7 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 11;
22
use Test::More tests => 12;
23
use Test::MockModule;
23
use Test::MockModule;
24
use JSON qw( decode_json );
24
use JSON qw( decode_json );
25
25
Lines 40-45 t::lib::Mocks::mock_userenv; Link Here
40
my $net_stomp = Test::MockModule->new('Net::Stomp');
40
my $net_stomp = Test::MockModule->new('Net::Stomp');
41
$net_stomp->mock( 'send_with_receipt', sub { return 1 } );
41
$net_stomp->mock( 'send_with_receipt', sub { return 1 } );
42
42
43
my $background_job_module = Test::MockModule->new('Koha::BackgroundJob');
44
$background_job_module->mock( '_derived_class',
45
    sub { t::lib::Koha::BackgroundJob::BatchTest->new } );
46
43
my $data     = { a => 'aaa', b => 'bbb' };
47
my $data     = { a => 'aaa', b => 'bbb' };
44
my $job_size = 10;
48
my $job_size = 10;
45
my $job_id   = t::lib::Koha::BackgroundJob::BatchTest->new->enqueue(
49
my $job_id   = t::lib::Koha::BackgroundJob::BatchTest->new->enqueue(
Lines 80-83 is_deeply( Link Here
80
    'Correct number of records processed'
84
    'Correct number of records processed'
81
);
85
);
82
86
87
is_deeply( $new_job->additional_report(), {} );
88
83
$schema->storage->txn_rollback;
89
$schema->storage->txn_rollback;
84
- 

Return to bug 29149