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

(-)a/Koha/BackgroundJob.pm (+6 lines)
Lines 3-8 package Koha::BackgroundJob; Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use JSON qw( encode_json decode_json );
4
use JSON qw( encode_json decode_json );
5
use Carp qw( croak );
5
use Carp qw( croak );
6
use Net::RabbitFoot;
7
6
use C4::Context;
8
use C4::Context;
7
use Koha::DateUtils qw( dt_from_string );
9
use Koha::DateUtils qw( dt_from_string );
8
use Koha::BackgroundJobs;
10
use Koha::BackgroundJobs;
Lines 81-86 sub report { Link Here
81
    return $data_dump->{report};
83
    return $data_dump->{report};
82
}
84
}
83
85
86
sub cancel {
87
    my ( $self ) = @_;
88
    $self->status('cancelled')->store;
89
}
84
90
85
sub _type {
91
sub _type {
86
    return 'BackgroundJob';
92
    return 'BackgroundJob';
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-7 / +12 lines)
Lines 14-23 sub process { Link Here
14
14
15
    my $job_type = $args->{job_type};
15
    my $job_type = $args->{job_type};
16
16
17
    return unless exists $args->{job_id};
18
19
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
17
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
20
18
19
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
20
        $channel->ack;
21
        return;
22
    }
23
21
    my $job_progress = 0;
24
    my $job_progress = 0;
22
    $job->started_on(dt_from_string)
25
    $job->started_on(dt_from_string)
23
        ->progress($job_progress)
26
        ->progress($job_progress)
Lines 29-42 sub process { Link Here
29
    my @record_ids = @{ $args->{record_ids} };
32
    my @record_ids = @{ $args->{record_ids} };
30
33
31
    my $report = {
34
    my $report = {
32
        total_records => 0,
35
        total_records => scalar @record_ids,
33
        total_success => 0,
36
        total_success => 0,
34
    };
37
    };
35
    my @messages;
38
    my @messages;
36
    my $dbh = C4::Context->dbh;
39
    my $dbh = C4::Context->dbh;
37
    $dbh->{RaiseError} = 1;
40
    $dbh->{RaiseError} = 1;
38
    RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) {
41
    RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) {
39
        $report->{total_records}++;
42
43
        last if $job->get_from_storage->status eq 'cancelled';
44
40
        next unless $biblionumber;
45
        next unless $biblionumber;
41
46
42
        # Modify the biblio
47
        # Modify the biblio
Lines 69-77 sub process { Link Here
69
    $job_data->{report} = $report;
74
    $job_data->{report} = $report;
70
75
71
    $job->ended_on(dt_from_string)
76
    $job->ended_on(dt_from_string)
72
        ->status('finished')
77
        ->data(encode_json $job_data);
73
        ->data(encode_json $job_data)
78
    $job->status('finished') if $job->status ne 'cancelled';
74
        ->store;
79
    $job->store;
75
    $channel->ack(); # FIXME Is that ok even on failure?
80
    $channel->ack(); # FIXME Is that ok even on failure?
76
}
81
}
77
82
(-)a/admin/background_jobs.pl (+8 lines)
Lines 51-59 if ( $op eq 'view' ) { Link Here
51
    } else {
51
    } else {
52
        $op = 'list';
52
        $op = 'list';
53
    }
53
    }
54
}
54
55
56
if ( $op eq 'cancel' ) {
57
    my $id = $input->param('id');
58
    if ( my $job = Koha::BackgroundJobs->find($id) ) { # FIXME Make sure logged in user can cancel this job
59
        $job->cancel;
60
    }
61
    $op = 'list';
55
}
62
}
56
63
64
57
if ( $op eq 'list' ) {
65
if ( $op eq 'list' ) {
58
    my $jobs = Koha::BackgroundJobs->search({}, { order_by => { -desc => 'enqueued_on' }});
66
    my $jobs = Koha::BackgroundJobs->search({}, { order_by => { -desc => 'enqueued_on' }});
59
    $template->param( jobs => $jobs, );
67
    $template->param( jobs => $jobs, );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt (-3 / +8 lines)
Lines 52-58 Link Here
52
                            </div>
52
                            </div>
53
                        [% ELSE %]
53
                        [% ELSE %]
54
                            <div class="dialog message">
54
                            <div class="dialog message">
55
                                [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred. <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
55
                                [% report.total_success | html %] / [% report.total_records | html %] records have successfully been modified. Some errors occurred.
56
                                [% IF job.status == 'cancelled' %]The job has been cancelled before it finished.[% END %]
57
                                <a href="/cgi-bin/koha/tools/batch_record_modification.pl" title="New batch record modification">New batch record modification</a>
56
                            </div>
58
                            </div>
57
                        [% END %]
59
                        [% END %]
58
                    [% END %]
60
                    [% END %]
Lines 137-144 Link Here
137
                    <td>[% job.started_on| html %]</td>
139
                    <td>[% job.started_on| html %]</td>
138
                    <td>[% job.ended_on| html %]</td>
140
                    <td>[% job.ended_on| html %]</td>
139
                    <td class="actions">
141
                    <td class="actions">
140
                        <a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=delete_confirm&amp;id=[% job.id | html %]"><i class="fa fa-pencil"></i> Delete</a>
142
                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&amp;id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a>
141
                        <a class="btn btn-default btn-xs  disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=replay&amp;id=[% job.id | html %]"><i class="fa fa-trash"></i> Replay</a>
143
                        [% IF job.status == 'new' || job.status == 'started' %]
144
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&amp;id=[% job.id | html %]"><i class="fa fa-pencil"></i> Cancel</a>
145
                        [% END %]
146
                        <a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=replay&amp;id=[% job.id | html %]"><i class="fa fa-trash"></i> Replay</a>
142
                    </td>
147
                    </td>
143
                </tr>
148
                </tr>
144
                [% END %]
149
                [% END %]
(-)a/new_koha_job.pl (-4 lines)
Lines 3-11 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Context;
4
use C4::Context;
5
use Koha::BackgroundJob::BatchUpdateBiblio;
5
use Koha::BackgroundJob::BatchUpdateBiblio;
6
use Koha::BackgroundJob;
7
8
use Net::RabbitFoot;
9
6
10
my $mmtid       = 1;
7
my $mmtid       = 1;
11
my $record_type = 'biblio';
8
my $record_type = 'biblio';
12
- 

Return to bug 22417