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

(-)a/Koha/BackgroundJob/BatchCancelHold.pm (-12 / +8 lines)
Lines 18-24 package Koha::BackgroundJob::BatchCancelHold; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use JSON qw( encode_json decode_json );
19
use JSON qw( encode_json decode_json );
20
20
21
use Koha::BackgroundJobs;
22
use Koha::DateUtils qw( dt_from_string );
21
use Koha::DateUtils qw( dt_from_string );
23
use Koha::Holds;
22
use Koha::Holds;
24
use Koha::Patrons;
23
use Koha::Patrons;
Lines 55-68 Process the modification. Link Here
55
sub process {
54
sub process {
56
    my ( $self, $args ) = @_;
55
    my ( $self, $args ) = @_;
57
56
58
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
57
    if ( $self->status eq 'cancelled' ) {
59
60
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
61
        return;
58
        return;
62
    }
59
    }
63
60
64
    my $job_progress = 0;
61
    my $job_progress = 0;
65
    $job->started_on(dt_from_string)->progress($job_progress)
62
    $self->started_on(dt_from_string)->progress($job_progress)
66
      ->status('started')->store;
63
      ->status('started')->store;
67
64
68
    my @hold_ids = @{ $args->{hold_ids} };
65
    my @hold_ids = @{ $args->{hold_ids} };
Lines 109-124 sub process { Link Here
109
              };
106
              };
110
            $report->{total_success}++;
107
            $report->{total_success}++;
111
        }
108
        }
112
        $job->progress( ++$job_progress )->store;
109
        $self->progress( ++$job_progress )->store;
113
    }
110
    }
114
111
115
    my $job_data = decode_json $job->data;
112
    my $job_data = decode_json $self->data;
116
    $job_data->{messages} = \@messages;
113
    $job_data->{messages} = \@messages;
117
    $job_data->{report}   = $report;
114
    $job_data->{report}   = $report;
118
115
119
    $job->ended_on(dt_from_string)->data( encode_json $job_data);
116
    $self->ended_on(dt_from_string)->data( encode_json $job_data);
120
    $job->status('finished') if $job->status ne 'cancelled';
117
    $self->status('finished') if $self->status ne 'cancelled';
121
    $job->store;
118
    $self->store;
122
119
123
}
120
}
124
121
Lines 153-160 Pass the biblio's title and patron's name Link Here
153
sub additional_report {
150
sub additional_report {
154
    my ( $self, $args ) = @_;
151
    my ( $self, $args ) = @_;
155
152
156
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
153
    my $messages = $self->messages;
157
    my $messages = $job->messages;
158
    for my $m ( @$messages ) {
154
    for my $m ( @$messages ) {
159
        $m->{patron} = Koha::Patrons->find($m->{patron_id});
155
        $m->{patron} = Koha::Patrons->find($m->{patron_id});
160
        $m->{biblio} = Koha::Biblios->find($m->{biblio_id});
156
        $m->{biblio} = Koha::Biblios->find($m->{biblio_id});
(-)a/Koha/BackgroundJob/BatchDeleteAuthority.pm (-13 / +8 lines)
Lines 3-9 package Koha::BackgroundJob::BatchDeleteAuthority; 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
5
6
use Koha::BackgroundJobs;
7
use Koha::DateUtils qw( dt_from_string );
6
use Koha::DateUtils qw( dt_from_string );
8
use C4::AuthoritiesMarc;
7
use C4::AuthoritiesMarc;
9
8
Lines 16-26 sub job_type { Link Here
16
sub process {
15
sub process {
17
    my ( $self, $args ) = @_;
16
    my ( $self, $args ) = @_;
18
17
19
    my $job_type = $args->{job_type};
18
    if ( $self->status eq 'cancelled' ) {
20
21
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
22
23
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
24
        return;
19
        return;
25
    }
20
    }
26
21
Lines 28-34 sub process { Link Here
28
    # Then we will start from scratch and so double delete the same records
23
    # Then we will start from scratch and so double delete the same records
29
24
30
    my $job_progress = 0;
25
    my $job_progress = 0;
31
    $job->started_on(dt_from_string)
26
    $self->started_on(dt_from_string)
32
        ->progress($job_progress)
27
        ->progress($job_progress)
33
        ->status('started')
28
        ->status('started')
34
        ->store;
29
        ->store;
Lines 44-50 sub process { Link Here
44
    my $schema = Koha::Database->new->schema;
39
    my $schema = Koha::Database->new->schema;
45
    RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) {
40
    RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) {
46
41
47
        last if $job->get_from_storage->status eq 'cancelled';
42
        last if $self->get_from_storage->status eq 'cancelled';
48
43
49
        next unless $record_id;
44
        next unless $record_id;
50
45
Lines 71-87 sub process { Link Here
71
            $schema->storage->txn_commit;
66
            $schema->storage->txn_commit;
72
        }
67
        }
73
68
74
        $job->progress( ++$job_progress )->store;
69
        $self->progress( ++$job_progress )->store;
75
    }
70
    }
76
71
77
    my $job_data = decode_json $job->data;
72
    my $job_data = decode_json $self->data;
78
    $job_data->{messages} = \@messages;
73
    $job_data->{messages} = \@messages;
79
    $job_data->{report} = $report;
74
    $job_data->{report} = $report;
80
75
81
    $job->ended_on(dt_from_string)
76
    $self->ended_on(dt_from_string)
82
        ->data(encode_json $job_data);
77
        ->data(encode_json $job_data);
83
    $job->status('finished') if $job->status ne 'cancelled';
78
    $self->status('finished') if $self->status ne 'cancelled';
84
    $job->store;
79
    $self->store;
85
}
80
}
86
81
87
sub enqueue {
82
sub enqueue {
(-)a/Koha/BackgroundJob/BatchDeleteBiblio.pm (-17 / +12 lines)
Lines 3-9 package Koha::BackgroundJob::BatchDeleteBiblio; 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
5
6
use Koha::BackgroundJobs;
7
use Koha::DateUtils qw( dt_from_string );
6
use Koha::DateUtils qw( dt_from_string );
8
use C4::Biblio;
7
use C4::Biblio;
9
8
Lines 38-48 Process the job. Link Here
38
sub process {
37
sub process {
39
    my ( $self, $args ) = @_;
38
    my ( $self, $args ) = @_;
40
39
41
    my $job_type = $args->{job_type};
40
    if ( $self->status eq 'cancelled' ) {
42
43
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
44
45
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
46
        return;
41
        return;
47
    }
42
    }
48
43
Lines 50-56 sub process { Link Here
50
    # Then we will start from scratch and so double delete the same records
45
    # Then we will start from scratch and so double delete the same records
51
46
52
    my $job_progress = 0;
47
    my $job_progress = 0;
53
    $job->started_on(dt_from_string)
48
    $self->started_on(dt_from_string)
54
        ->progress($job_progress)
49
        ->progress($job_progress)
55
        ->status('started')
50
        ->status('started')
56
        ->store;
51
        ->store;
Lines 66-72 sub process { Link Here
66
    my $schema = Koha::Database->new->schema;
61
    my $schema = Koha::Database->new->schema;
67
    RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) {
62
    RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) {
68
63
69
        last if $job->get_from_storage->status eq 'cancelled';
64
        last if $self->get_from_storage->status eq 'cancelled';
70
65
71
        next unless $record_id;
66
        next unless $record_id;
72
67
Lines 85-91 sub process { Link Here
85
                biblionumber => $biblionumber,
80
                biblionumber => $biblionumber,
86
            };
81
            };
87
            $schema->storage->txn_rollback;
82
            $schema->storage->txn_rollback;
88
            $job->progress( ++$job_progress )->store;
83
            $self->progress( ++$job_progress )->store;
89
            next;
84
            next;
90
        }
85
        }
91
86
Lines 104-110 sub process { Link Here
104
                    error => "$@",
99
                    error => "$@",
105
                };
100
                };
106
                $schema->storage->txn_rollback;
101
                $schema->storage->txn_rollback;
107
                $job->progress( ++$job_progress )->store;
102
                $self->progress( ++$job_progress )->store;
108
                next RECORD_IDS;
103
                next RECORD_IDS;
109
            }
104
            }
110
        }
105
        }
Lines 122-128 sub process { Link Here
122
                    error => @{$deleted->messages}[0]->message,
117
                    error => @{$deleted->messages}[0]->message,
123
                };
118
                };
124
                $schema->storage->txn_rollback;
119
                $schema->storage->txn_rollback;
125
                $job->progress( ++$job_progress )->store;
120
                $self->progress( ++$job_progress )->store;
126
                next RECORD_IDS;
121
                next RECORD_IDS;
127
            }
122
            }
128
        }
123
        }
Lines 139-145 sub process { Link Here
139
                error => ($@ ? $@ : $error),
134
                error => ($@ ? $@ : $error),
140
            };
135
            };
141
            $schema->storage->txn_rollback;
136
            $schema->storage->txn_rollback;
142
            $job->progress( ++$job_progress )->store;
137
            $self->progress( ++$job_progress )->store;
143
            next;
138
            next;
144
        }
139
        }
145
140
Lines 150-166 sub process { Link Here
150
        };
145
        };
151
        $report->{total_success}++;
146
        $report->{total_success}++;
152
        $schema->storage->txn_commit;
147
        $schema->storage->txn_commit;
153
        $job->progress( ++$job_progress )->store;
148
        $self->progress( ++$job_progress )->store;
154
    }
149
    }
155
150
156
    my $job_data = decode_json $job->data;
151
    my $job_data = decode_json $self->data;
157
    $job_data->{messages} = \@messages;
152
    $job_data->{messages} = \@messages;
158
    $job_data->{report} = $report;
153
    $job_data->{report} = $report;
159
154
160
    $job->ended_on(dt_from_string)
155
    $self->ended_on(dt_from_string)
161
        ->data(encode_json $job_data);
156
        ->data(encode_json $job_data);
162
    $job->status('finished') if $job->status ne 'cancelled';
157
    $self->status('finished') if $self->status ne 'cancelled';
163
    $job->store;
158
    $self->store;
164
}
159
}
165
160
166
=head3 enqueue
161
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchDeleteItem.pm (-13 / +8 lines)
Lines 26-32 use JSON qw( encode_json decode_json ); Link Here
26
use List::MoreUtils qw( uniq );
26
use List::MoreUtils qw( uniq );
27
use Try::Tiny;
27
use Try::Tiny;
28
28
29
use Koha::BackgroundJobs;
30
use Koha::DateUtils qw( dt_from_string );
29
use Koha::DateUtils qw( dt_from_string );
31
use Koha::Items;
30
use Koha::Items;
32
31
Lines 75-85 The generated report will be: Link Here
75
sub process {
74
sub process {
76
    my ( $self, $args ) = @_;
75
    my ( $self, $args ) = @_;
77
76
78
    my $job_type = $args->{job_type};
77
    if ( $self->status eq 'cancelled' ) {
79
80
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
81
82
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
83
        return;
78
        return;
84
    }
79
    }
85
80
Lines 87-93 sub process { Link Here
87
    # Then we will start from scratch and so double delete the same records
82
    # Then we will start from scratch and so double delete the same records
88
83
89
    my $job_progress = 0;
84
    my $job_progress = 0;
90
    $job->started_on(dt_from_string)->progress($job_progress)
85
    $self->started_on(dt_from_string)->progress($job_progress)
91
      ->status('started')->store;
86
      ->status('started')->store;
92
87
93
    my @record_ids     = @{ $args->{record_ids} };
88
    my @record_ids     = @{ $args->{record_ids} };
Lines 109-115 sub process { Link Here
109
                my (@biblionumbers);
104
                my (@biblionumbers);
110
                for my $record_id ( sort { $a <=> $b } @record_ids ) {
105
                for my $record_id ( sort { $a <=> $b } @record_ids ) {
111
106
112
                    last if $job->get_from_storage->status eq 'cancelled';
107
                    last if $self->get_from_storage->status eq 'cancelled';
113
108
114
                    my $item = Koha::Items->find($record_id) || next;
109
                    my $item = Koha::Items->find($record_id) || next;
115
110
Lines 136-142 sub process { Link Here
136
                    push @biblionumbers,       $item->biblionumber;
131
                    push @biblionumbers,       $item->biblionumber;
137
132
138
                    $report->{total_success}++;
133
                    $report->{total_success}++;
139
                    $job->progress( ++$job_progress )->store;
134
                    $self->progress( ++$job_progress )->store;
140
                }
135
                }
141
136
142
                # If there are no items left, delete the biblio
137
                # If there are no items left, delete the biblio
Lines 183-195 sub process { Link Here
183
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
178
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
184
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
179
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
185
180
186
    my $job_data = decode_json $job->data;
181
    my $job_data = decode_json $self->data;
187
    $job_data->{messages} = \@messages;
182
    $job_data->{messages} = \@messages;
188
    $job_data->{report}   = $report;
183
    $job_data->{report}   = $report;
189
184
190
    $job->ended_on(dt_from_string)->data( encode_json $job_data);
185
    $self->ended_on(dt_from_string)->data( encode_json $job_data);
191
    $job->status('finished') if $job->status ne 'cancelled';
186
    $self->status('finished') if $self->status ne 'cancelled';
192
    $job->store;
187
    $self->store;
193
}
188
}
194
189
195
=head3 enqueue
190
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchUpdateAuthority.pm (-9 / +7 lines)
Lines 55-68 Process the modification. Link Here
55
sub process {
55
sub process {
56
    my ( $self, $args ) = @_;
56
    my ( $self, $args ) = @_;
57
57
58
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
58
    if ( $self->status eq 'cancelled' ) {
59
60
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
61
        return;
59
        return;
62
    }
60
    }
63
61
64
    my $job_progress = 0;
62
    my $job_progress = 0;
65
    $job->started_on(dt_from_string)
63
    $self->started_on(dt_from_string)
66
        ->progress($job_progress)
64
        ->progress($job_progress)
67
        ->status('started')
65
        ->status('started')
68
        ->store;
66
        ->store;
Lines 100-116 sub process { Link Here
100
            };
98
            };
101
            $report->{total_success}++;
99
            $report->{total_success}++;
102
        }
100
        }
103
        $job->progress( ++$job_progress )->store;
101
        $self->progress( ++$job_progress )->store;
104
    }
102
    }
105
103
106
    my $job_data = decode_json $job->data;
104
    my $job_data = decode_json $self->data;
107
    $job_data->{messages} = \@messages;
105
    $job_data->{messages} = \@messages;
108
    $job_data->{report} = $report;
106
    $job_data->{report} = $report;
109
107
110
    $job->ended_on(dt_from_string)
108
    $self->ended_on(dt_from_string)
111
        ->data(encode_json $job_data);
109
        ->data(encode_json $job_data);
112
    $job->status('finished') if $job->status ne 'cancelled';
110
    $self->status('finished') if $self->status ne 'cancelled';
113
    $job->store;
111
    $self->store;
114
112
115
}
113
}
116
114
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-11 / +8 lines)
Lines 18-24 package Koha::BackgroundJob::BatchUpdateBiblio; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use JSON qw( decode_json encode_json );
19
use JSON qw( decode_json encode_json );
20
20
21
use Koha::BackgroundJobs;
22
use Koha::DateUtils qw( dt_from_string );
21
use Koha::DateUtils qw( dt_from_string );
23
use Koha::Virtualshelves;
22
use Koha::Virtualshelves;
24
23
Lines 57-65 Process the modification. Link Here
57
sub process {
56
sub process {
58
    my ( $self, $args ) = @_;
57
    my ( $self, $args ) = @_;
59
58
60
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
59
    if ( $self->status eq 'cancelled' ) {
61
62
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
63
        return;
60
        return;
64
    }
61
    }
65
62
Lines 67-73 sub process { Link Here
67
    # Then we will start from scratch and so double process the same records
64
    # Then we will start from scratch and so double process the same records
68
65
69
    my $job_progress = 0;
66
    my $job_progress = 0;
70
    $job->started_on(dt_from_string)
67
    $self->started_on(dt_from_string)
71
        ->progress($job_progress)
68
        ->progress($job_progress)
72
        ->status('started')
69
        ->status('started')
73
        ->store;
70
        ->store;
Lines 82-88 sub process { Link Here
82
    my @messages;
79
    my @messages;
83
    RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) {
80
    RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) {
84
81
85
        last if $job->get_from_storage->status eq 'cancelled';
82
        last if $self->get_from_storage->status eq 'cancelled';
86
83
87
        next unless $biblionumber;
84
        next unless $biblionumber;
88
85
Lines 110-126 sub process { Link Here
110
            };
107
            };
111
            $report->{total_success}++;
108
            $report->{total_success}++;
112
        }
109
        }
113
        $job->progress( ++$job_progress )->store;
110
        $self->progress( ++$job_progress )->store;
114
    }
111
    }
115
112
116
    my $job_data = decode_json $job->data;
113
    my $job_data = decode_json $self->data;
117
    $job_data->{messages} = \@messages;
114
    $job_data->{messages} = \@messages;
118
    $job_data->{report} = $report;
115
    $job_data->{report} = $report;
119
116
120
    $job->ended_on(dt_from_string)
117
    $self->ended_on(dt_from_string)
121
        ->data(encode_json $job_data);
118
        ->data(encode_json $job_data);
122
    $job->status('finished') if $job->status ne 'cancelled';
119
    $self->status('finished') if $self->status ne 'cancelled';
123
    $job->store;
120
    $self->store;
124
}
121
}
125
122
126
=head3 enqueue
123
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-15 / +9 lines)
Lines 27-33 use MARC::Field; Link Here
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::Items;
28
use C4::Items;
29
29
30
use Koha::BackgroundJobs;
31
use Koha::DateUtils qw( dt_from_string );
30
use Koha::DateUtils qw( dt_from_string );
32
use Koha::SearchEngine::Indexer;
31
use Koha::SearchEngine::Indexer;
33
use Koha::Items;
32
use Koha::Items;
Lines 85-93 regex_mod allows to modify existing subfield's values using a regular expression Link Here
85
sub process {
84
sub process {
86
    my ( $self, $args ) = @_;
85
    my ( $self, $args ) = @_;
87
86
88
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
87
    if ( $self->status eq 'cancelled' ) {
89
90
    if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) {
91
        return;
88
        return;
92
    }
89
    }
93
90
Lines 95-101 sub process { Link Here
95
    # Then we will start from scratch and so double process the same records
92
    # Then we will start from scratch and so double process the same records
96
93
97
    my $job_progress = 0;
94
    my $job_progress = 0;
98
    $job->started_on(dt_from_string)->progress($job_progress)
95
    $self->started_on(dt_from_string)->progress($job_progress)
99
      ->status('started')->store;
96
      ->status('started')->store;
100
97
101
    my @record_ids = @{ $args->{record_ids} };
98
    my @record_ids = @{ $args->{record_ids} };
Lines 120-126 sub process { Link Here
120
                  $exclude_from_local_holds_priority,
117
                  $exclude_from_local_holds_priority,
121
                callback => sub {
118
                callback => sub {
122
                    my ($progress) = @_;
119
                    my ($progress) = @_;
123
                    $job->progress($progress)->store;
120
                    $self->progress($progress)->store;
124
                },
121
                },
125
            }
122
            }
126
          );
123
          );
Lines 133-145 sub process { Link Here
133
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
130
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
134
    };
131
    };
135
132
136
    $job->discard_changes;
133
    $self->discard_changes;
137
    my $job_data = decode_json encode_utf8 $job->data;
134
    my $job_data = decode_json encode_utf8 $self->data;
138
    $job_data->{report} = $report;
135
    $job_data->{report} = $report;
139
136
140
    $job->ended_on(dt_from_string)->data( encode_json $job_data);
137
    $self->ended_on(dt_from_string)->data( encode_json $job_data);
141
    $job->status('finished') if $job->status ne 'cancelled';
138
    $self->status('finished') if $self->status ne 'cancelled';
142
    $job->store;
139
    $self->store;
143
}
140
}
144
141
145
=head3 enqueue
142
=head3 enqueue
Lines 173-181 Sent the infos to generate the table containing the details of the modified item Link Here
173
sub additional_report {
170
sub additional_report {
174
    my ( $self, $args ) = @_;
171
    my ( $self, $args ) = @_;
175
172
176
    my $job = Koha::BackgroundJobs->find( $args->{job_id} );
173
    my $itemnumbers = $self->report->{modified_itemnumbers};
177
178
    my $itemnumbers = $job->report->{modified_itemnumbers};
179
    if ( scalar(@$itemnumbers) > C4::Context->preference('MaxItemsToDisplayForBatchMod') ) {
174
    if ( scalar(@$itemnumbers) > C4::Context->preference('MaxItemsToDisplayForBatchMod') ) {
180
        return { too_many_items_display => 1 };
175
        return { too_many_items_display => 1 };
181
    } else {
176
    } else {
182
- 

Return to bug 30181