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

(-)a/Koha/BackgroundJob/BatchCancelHold.pm (-14 / +6 lines)
Lines 17-26 package Koha::BackgroundJob::BatchCancelHold; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::DateUtils qw( dt_from_string );
21
use Koha::Holds;
20
use Koha::Holds;
22
use Koha::Patrons;
21
use Koha::Patrons;
23
use Koha::Holds;
24
22
25
use base 'Koha::BackgroundJob';
23
use base 'Koha::BackgroundJob';
26
24
Lines 57-65 sub process { Link Here
57
        return;
55
        return;
58
    }
56
    }
59
57
60
    my $job_progress = 0;
58
    $self->start;
61
    $self->started_on(dt_from_string)->progress($job_progress)
62
      ->status('started')->store;
63
59
64
    my @hold_ids = @{ $args->{hold_ids} };
60
    my @hold_ids = @{ $args->{hold_ids} };
65
61
Lines 105-122 sub process { Link Here
105
              };
101
              };
106
            $report->{total_success}++;
102
            $report->{total_success}++;
107
        }
103
        }
108
        $self->progress( ++$job_progress )->store;
104
        $self->step;
109
    }
105
    }
110
106
111
    my $json = $self->json;
107
    my $data = $self->decoded_data;
112
    my $job_data = $json->decode($self->data);
108
    $data->{messages} = \@messages;
113
    $job_data->{messages} = \@messages;
109
    $data->{report} = $report;
114
    $job_data->{report}   = $report;
115
116
    $self->ended_on(dt_from_string)->data($json->encode($job_data));
117
    $self->status('finished') if $self->status ne 'cancelled';
118
    $self->store;
119
110
111
    $self->finish( $data );
120
}
112
}
121
113
122
=head3 enqueue
114
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchDeleteAuthority.pm (-15 / +6 lines)
Lines 4-10 use Modern::Perl; Link Here
4
4
5
use C4::AuthoritiesMarc;
5
use C4::AuthoritiesMarc;
6
6
7
use Koha::DateUtils qw( dt_from_string );
8
use Koha::SearchEngine;
7
use Koha::SearchEngine;
9
use Koha::SearchEngine::Indexer;
8
use Koha::SearchEngine::Indexer;
10
9
Lines 24-34 sub process { Link Here
24
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
23
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
25
    # Then we will start from scratch and so double delete the same records
24
    # Then we will start from scratch and so double delete the same records
26
25
27
    my $job_progress = 0;
26
    $self->start;
28
    $self->started_on(dt_from_string)
29
        ->progress($job_progress)
30
        ->status('started')
31
        ->store;
32
27
33
    my $mmtid = $args->{mmtid};
28
    my $mmtid = $args->{mmtid};
34
    my @record_ids = @{ $args->{record_ids} };
29
    my @record_ids = @{ $args->{record_ids} };
Lines 71-77 sub process { Link Here
71
            $schema->storage->txn_commit;
66
            $schema->storage->txn_commit;
72
        }
67
        }
73
68
74
        $self->progress( ++$job_progress )->store;
69
        $self->step;
75
    }
70
    }
76
71
77
    my @deleted_authids =
72
    my @deleted_authids =
Lines 83-97 sub process { Link Here
83
        $indexer->index_records( \@deleted_authids, "recordDelete", "authorityserver" );
78
        $indexer->index_records( \@deleted_authids, "recordDelete", "authorityserver" );
84
    }
79
    }
85
80
86
    my $json = $self->json;
81
    my $data = $self->decoded_data;
87
    my $job_data = $json->decode($self->data);
82
    $data->{messages} = \@messages;
88
    $job_data->{messages} = \@messages;
83
    $data->{report} = $report;
89
    $job_data->{report} = $report;
90
84
91
    $self->ended_on(dt_from_string)
85
    $self->finish( $data );
92
        ->data($json->encode($job_data));
93
    $self->status('finished') if $self->status ne 'cancelled';
94
    $self->store;
95
}
86
}
96
87
97
sub enqueue {
88
sub enqueue {
(-)a/Koha/BackgroundJob/BatchDeleteBiblio.pm (-19 / +15 lines)
Lines 5-11 use Modern::Perl; Link Here
5
use C4::Biblio;
5
use C4::Biblio;
6
6
7
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
7
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
8
use Koha::DateUtils qw( dt_from_string );
9
use Koha::SearchEngine;
8
use Koha::SearchEngine;
10
use Koha::SearchEngine::Indexer;
9
use Koha::SearchEngine::Indexer;
11
10
Lines 47-57 sub process { Link Here
47
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
46
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
48
    # Then we will start from scratch and so double delete the same records
47
    # Then we will start from scratch and so double delete the same records
49
48
50
    my $job_progress = 0;
49
    $self->start;
51
    $self->started_on(dt_from_string)
52
        ->progress($job_progress)
53
        ->status('started')
54
        ->store;
55
50
56
    my $mmtid = $args->{mmtid};
51
    my $mmtid = $args->{mmtid};
57
    my @record_ids = @{ $args->{record_ids} };
52
    my @record_ids = @{ $args->{record_ids} };
Lines 83-89 sub process { Link Here
83
                biblionumber => $biblionumber,
78
                biblionumber => $biblionumber,
84
            };
79
            };
85
            $schema->storage->txn_rollback;
80
            $schema->storage->txn_rollback;
86
            $self->progress( ++$job_progress )->store;
81
82
            $self->step;
87
            next;
83
            next;
88
        }
84
        }
89
85
Lines 102-108 sub process { Link Here
102
                    error => "$@",
98
                    error => "$@",
103
                };
99
                };
104
                $schema->storage->txn_rollback;
100
                $schema->storage->txn_rollback;
105
                $self->progress( ++$job_progress )->store;
101
102
                $self->step;
106
                next RECORD_IDS;
103
                next RECORD_IDS;
107
            }
104
            }
108
        }
105
        }
Lines 120-126 sub process { Link Here
120
                    error => @{$deleted->messages}[0]->message,
117
                    error => @{$deleted->messages}[0]->message,
121
                };
118
                };
122
                $schema->storage->txn_rollback;
119
                $schema->storage->txn_rollback;
123
                $self->progress( ++$job_progress )->store;
120
121
                $self->step;
124
                next RECORD_IDS;
122
                next RECORD_IDS;
125
            }
123
            }
126
        }
124
        }
Lines 137-143 sub process { Link Here
137
                error => ($@ ? $@ : $error),
135
                error => ($@ ? $@ : $error),
138
            };
136
            };
139
            $schema->storage->txn_rollback;
137
            $schema->storage->txn_rollback;
140
            $self->progress( ++$job_progress )->store;
138
139
            $self->step;
141
            next;
140
            next;
142
        }
141
        }
143
142
Lines 148-154 sub process { Link Here
148
        };
147
        };
149
        $report->{total_success}++;
148
        $report->{total_success}++;
150
        $schema->storage->txn_commit;
149
        $schema->storage->txn_commit;
151
        $self->progress( ++$job_progress )->store;
150
151
        $self->step;
152
    }
152
    }
153
153
154
    my @deleted_biblionumbers =
154
    my @deleted_biblionumbers =
Lines 166-180 sub process { Link Here
166
        ) if C4::Context->preference('RealTimeHoldsQueue');
166
        ) if C4::Context->preference('RealTimeHoldsQueue');
167
    }
167
    }
168
168
169
    my $json = $self->json;
169
    my $data = $self->decoded_data;
170
    my $job_data = $json->decode($self->data);
170
    $data->{messages} = \@messages;
171
    $job_data->{messages} = \@messages;
171
    $data->{report} = $report;
172
    $job_data->{report} = $report;
173
172
174
    $self->ended_on(dt_from_string)
173
    $self->finish( $data );
175
        ->data($json->encode($job_data));
176
    $self->status('finished') if $self->status ne 'cancelled';
177
    $self->store;
178
}
174
}
179
175
180
=head3 enqueue
176
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchDeleteItem.pm (-12 / +6 lines)
Lines 25-31 use Modern::Perl; Link Here
25
use List::MoreUtils qw( uniq );
25
use List::MoreUtils qw( uniq );
26
use Try::Tiny;
26
use Try::Tiny;
27
27
28
use Koha::DateUtils qw( dt_from_string );
29
use Koha::Items;
28
use Koha::Items;
30
29
31
use base 'Koha::BackgroundJob';
30
use base 'Koha::BackgroundJob';
Lines 80-88 sub process { Link Here
80
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
79
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
81
    # Then we will start from scratch and so double delete the same records
80
    # Then we will start from scratch and so double delete the same records
82
81
83
    my $job_progress = 0;
82
    $self->start;
84
    $self->started_on(dt_from_string)->progress($job_progress)
85
      ->status('started')->store;
86
83
87
    my @record_ids     = @{ $args->{record_ids} };
84
    my @record_ids     = @{ $args->{record_ids} };
88
    my $delete_biblios = $args->{delete_biblios};
85
    my $delete_biblios = $args->{delete_biblios};
Lines 130-136 sub process { Link Here
130
                    push @biblionumbers,       $item->biblionumber;
127
                    push @biblionumbers,       $item->biblionumber;
131
128
132
                    $report->{total_success}++;
129
                    $report->{total_success}++;
133
                    $self->progress( ++$job_progress )->store;
130
                    $self->step;
134
                }
131
                }
135
132
136
                # If there are no items left, delete the biblio
133
                # If there are no items left, delete the biblio
Lines 198-211 sub process { Link Here
198
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
195
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
199
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
196
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
200
197
201
    my $json = $self->json;
198
    my $data = $self->decoded_data;
202
    my $job_data = $json->decode($self->data);
199
    $data->{messages} = \@messages;
203
    $job_data->{messages} = \@messages;
200
    $data->{report} = $report;
204
    $job_data->{report}   = $report;
205
201
206
    $self->ended_on(dt_from_string)->data( $json->encode($job_data));
202
    $self->finish( $data );
207
    $self->status('finished') if $self->status ne 'cancelled';
208
    $self->store;
209
}
203
}
210
204
211
=head3 enqueue
205
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchUpdateAuthority.pm (-15 / +6 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
20
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
21
use C4::AuthoritiesMarc qw( ModAuthority );
21
use C4::AuthoritiesMarc qw( ModAuthority );
22
use Koha::BackgroundJobs;
22
use Koha::BackgroundJobs;
23
use Koha::DateUtils qw( dt_from_string );
24
use Koha::MetadataRecord::Authority;
23
use Koha::MetadataRecord::Authority;
25
use Koha::SearchEngine;
24
use Koha::SearchEngine;
26
use Koha::SearchEngine::Indexer;
25
use Koha::SearchEngine::Indexer;
Lines 60-70 sub process { Link Here
60
        return;
59
        return;
61
    }
60
    }
62
61
63
    my $job_progress = 0;
62
    $self->start;
64
    $self->started_on(dt_from_string)
65
        ->progress($job_progress)
66
        ->status('started')
67
        ->store;
68
63
69
    my $mmtid = $args->{mmtid};
64
    my $mmtid = $args->{mmtid};
70
    my @record_ids = @{ $args->{record_ids} };
65
    my @record_ids = @{ $args->{record_ids} };
Lines 99-119 sub process { Link Here
99
            };
94
            };
100
            $report->{total_success}++;
95
            $report->{total_success}++;
101
        }
96
        }
102
        $self->progress( ++$job_progress )->store;
97
        $self->step;
103
    }
98
    }
104
99
105
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
100
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
106
    $indexer->index_records( \@record_ids, "specialUpdate", "authorityserver" );
101
    $indexer->index_records( \@record_ids, "specialUpdate", "authorityserver" );
107
102
108
    my $json = $self->json;
103
    my $data = $self->decoded_data;
109
    my $job_data = $json->decode($self->data);
104
    $data->{messages} = \@messages;
110
    $job_data->{messages} = \@messages;
105
    $data->{report}   = $report;
111
    $job_data->{report} = $report;
112
106
113
    $self->ended_on(dt_from_string)
107
    $self->finish( $data );
114
        ->data($json->encode($job_data));
115
    $self->status('finished') if $self->status ne 'cancelled';
116
    $self->store;
117
108
118
}
109
}
119
110
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-15 / +7 lines)
Lines 18-24 package Koha::BackgroundJob::BatchUpdateBiblio; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Biblios;
20
use Koha::Biblios;
21
use Koha::DateUtils qw( dt_from_string );
22
use Koha::Virtualshelves;
21
use Koha::Virtualshelves;
23
use Koha::SearchEngine;
22
use Koha::SearchEngine;
24
use Koha::SearchEngine::Indexer;
23
use Koha::SearchEngine::Indexer;
Lines 65-75 sub process { Link Here
65
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
64
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
66
    # Then we will start from scratch and so double process the same records
65
    # Then we will start from scratch and so double process the same records
67
66
68
    my $job_progress = 0;
67
    $self->start;
69
    $self->started_on(dt_from_string)
70
        ->progress($job_progress)
71
        ->status('started')
72
        ->store;
73
68
74
    my $mmtid = $args->{mmtid};
69
    my $mmtid = $args->{mmtid};
75
    my @record_ids = @{ $args->{record_ids} };
70
    my @record_ids = @{ $args->{record_ids} };
Lines 111-131 sub process { Link Here
111
            };
106
            };
112
            $report->{total_success}++;
107
            $report->{total_success}++;
113
        }
108
        }
114
        $self->progress( ++$job_progress )->store;
109
110
        $self->step;
115
    }
111
    }
116
112
117
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
113
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
118
    $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver" );
114
    $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver" );
119
115
120
    my $json = $self->json;
116
    my $data = $self->decoded_data;
121
    my $job_data = $json->decode($self->data);
117
    $data->{messages} = \@messages;
122
    $job_data->{messages} = \@messages;
118
    $data->{report} = $report;
123
    $job_data->{report} = $report;
124
119
125
    $self->ended_on(dt_from_string)
120
    $self->finish( $data );
126
        ->data($json->encode($job_data));
127
    $self->status('finished') if $self->status ne 'cancelled';
128
    $self->store;
129
}
121
}
130
122
131
=head3 enqueue
123
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm (-19 / +6 lines)
Lines 59-71 sub process { Link Here
59
59
60
    my $schema = Koha::Database->new->schema;
60
    my $schema = Koha::Database->new->schema;
61
61
62
    $self->set(
62
    $self->start;
63
        {
64
            started_on => \'NOW()',
65
            progress   => 0,
66
            status     => 'started',
67
        }
68
    )->store;
69
63
70
    my @biblio_ids = @{ $args->{biblio_ids} };
64
    my @biblio_ids = @{ $args->{biblio_ids} };
71
65
Lines 116-136 sub process { Link Here
116
            $schema->storage->txn_rollback;
110
            $schema->storage->txn_rollback;
117
        };
111
        };
118
112
119
        $self->progress( $self->progress + 1 )->store;
113
        $self->step;
120
    }
114
    }
121
115
122
    my $json = $self->json;
116
    my $data = $self->decoded_data;
123
    my $job_data = $json->decode($self->data);
117
    $data->{messages} = \@messages;
124
    $job_data->{messages} = \@messages;
118
    $data->{report} = $report;
125
    $job_data->{report}   = $report;
126
119
127
    $self->set(
120
    $self->finish( $data );
128
        {
129
            ended_on => \'NOW()',
130
            data     => $json->encode($job_data),
131
            status   => 'finished',
132
        }
133
    )->store;
134
}
121
}
135
122
136
=head3 enqueue
123
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-24 / +10 lines)
Lines 89-97 sub process { Link Here
89
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
89
    # FIXME If the job has already been started, but started again (worker has been restart for instance)
90
    # Then we will start from scratch and so double process the same records
90
    # Then we will start from scratch and so double process the same records
91
91
92
    my $job_progress = 0;
92
    $self->start;
93
    $self->started_on(dt_from_string)->progress($job_progress)
94
      ->status('started')->store;
95
93
96
    my @record_ids = @{ $args->{record_ids} };
94
    my @record_ids = @{ $args->{record_ids} };
97
    my $regex_mod  = $args->{regex_mod};
95
    my $regex_mod  = $args->{regex_mod};
Lines 105-124 sub process { Link Here
105
    };
103
    };
106
104
107
    try {
105
    try {
108
        my ($results) =
106
        my ($results) = Koha::Items->search( { itemnumber => \@record_ids } )->batch_update(
109
          Koha::Items->search( { itemnumber => \@record_ids } )
107
            {   regex_mod                         => $regex_mod,
110
          ->batch_update(
108
                new_values                        => $new_values,
111
            {
109
                exclude_from_local_holds_priority => $exclude_from_local_holds_priority,
112
                regex_mod  => $regex_mod,
110
                callback                          => sub { $self->step; },
113
                new_values => $new_values,
114
                exclude_from_local_holds_priority =>
115
                  $exclude_from_local_holds_priority,
116
                callback => sub {
117
                    my ($progress) = @_;
118
                    $self->progress($progress)->store;
119
                },
120
            }
111
            }
121
          );
112
        );
122
        $report->{modified_itemnumbers} = $results->{modified_itemnumbers};
113
        $report->{modified_itemnumbers} = $results->{modified_itemnumbers};
123
        $report->{modified_fields}      = $results->{modified_fields};
114
        $report->{modified_fields}      = $results->{modified_fields};
124
    }
115
    }
Lines 128-141 sub process { Link Here
128
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
119
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
129
    };
120
    };
130
121
131
    my $json = $self->json;
122
    my $data = $self->decoded_data;
132
    $self->discard_changes;
123
    $data->{report} = $report;
133
    my $job_data = $json->decode($self->data);
134
    $job_data->{report} = $report;
135
124
136
    $self->ended_on(dt_from_string)->data($json->encode($job_data));
125
    $self->finish( $data );
137
    $self->status('finished') if $self->status ne 'cancelled';
138
    $self->store;
139
}
126
}
140
127
141
=head3 enqueue
128
=head3 enqueue
142
- 

Return to bug 30943