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

(-)a/Koha/BackgroundJob.pm (-7 / +22 lines)
Lines 100-106 sub enqueue { Link Here
100
    my $job_args    = $params->{job_args};
100
    my $job_args    = $params->{job_args};
101
    my $job_context = $params->{job_context} // C4::Context->userenv;
101
    my $job_context = $params->{job_context} // C4::Context->userenv;
102
    my $job_queue   = $params->{job_queue}  // 'default';
102
    my $job_queue   = $params->{job_queue}  // 'default';
103
    my $json = JSON->new;
103
    my $json = $self->json;
104
104
105
    my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef;
105
    my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef;
106
    $job_context->{interface} = C4::Context->interface;
106
    $job_context->{interface} = C4::Context->interface;
Lines 167-173 sub process { Link Here
167
    $args ||= {};
167
    $args ||= {};
168
168
169
    if ( $self->context ) {
169
    if ( $self->context ) {
170
        my $context = JSON->new->decode($self->context);
170
        my $context = $self->json->decode($self->context);
171
        C4::Context->_new_userenv(-1);
171
        C4::Context->_new_userenv(-1);
172
        C4::Context->interface( $context->{interface} );
172
        C4::Context->interface( $context->{interface} );
173
        C4::Context->set_userenv(
173
        C4::Context->set_userenv(
Lines 251-261 sub finish { Link Here
251
    return $self->set(
251
    return $self->set(
252
        {
252
        {
253
            ended_on => \'NOW()',
253
            ended_on => \'NOW()',
254
            data     => JSON->new->encode($data),
254
            data     => $self->json->encode($data),
255
        }
255
        }
256
    )->store;
256
    )->store;
257
}
257
}
258
258
259
=head3 json
260
261
   my $JSON_object = $self->json;
262
263
Returns a JSON object with utf8 disabled. Encoding to UTF-8 should be
264
done later.
265
266
=cut
267
268
sub json {
269
    my ( $self ) = @_;
270
    $self->{_json} //= JSON->new->utf8(0); # TODO Should we allow_nonref ?
271
    return $self->{_json};
272
}
273
259
=head3 decoded_data
274
=head3 decoded_data
260
275
261
    my $job_data = $self->decoded_data;
276
    my $job_data = $self->decoded_data;
Lines 267-273 Returns the decoded JSON contents from $self->data. Link Here
267
sub decoded_data {
282
sub decoded_data {
268
    my ($self) = @_;
283
    my ($self) = @_;
269
284
270
    return $self->data ? JSON->new->decode( $self->data ) : undef;
285
    return $self->data ? $self->json->decode( $self->data ) : undef;
271
}
286
}
272
287
273
=head3 set_encoded_data
288
=head3 set_encoded_data
Lines 281-287 Serializes I<$data> as a JSON string and sets the I<data> attribute with it. Link Here
281
sub set_encoded_data {
296
sub set_encoded_data {
282
    my ( $self, $data ) = @_;
297
    my ( $self, $data ) = @_;
283
298
284
    return $self->data( $data ? JSON->new->encode($data) : undef );
299
    return $self->data( $data ? $self->json->encode($data) : undef );
285
}
300
}
286
301
287
=head3 job_type
302
=head3 job_type
Lines 302-308 sub messages { Link Here
302
    my ( $self ) = @_;
317
    my ( $self ) = @_;
303
318
304
    my @messages;
319
    my @messages;
305
    my $data_dump = JSON->new->decode($self->data);
320
    my $data_dump = $self->json->decode($self->data);
306
    if ( exists $data_dump->{messages} ) {
321
    if ( exists $data_dump->{messages} ) {
307
        @messages = @{ $data_dump->{messages} };
322
        @messages = @{ $data_dump->{messages} };
308
    }
323
    }
Lines 319-325 Report of the job. Link Here
319
sub report {
334
sub report {
320
    my ( $self ) = @_;
335
    my ( $self ) = @_;
321
336
322
    my $data_dump = JSON->new->decode($self->data);
337
    my $data_dump = $self->json->decode($self->data);
323
    return $data_dump->{report} || {};
338
    return $data_dump->{report} || {};
324
}
339
}
325
340
(-)a/Koha/BackgroundJob/BatchCancelHold.pm (-2 / +1 lines)
Lines 16-22 package Koha::BackgroundJob::BatchCancelHold; Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use JSON;
20
19
21
use Koha::DateUtils qw( dt_from_string );
20
use Koha::DateUtils qw( dt_from_string );
22
use Koha::Holds;
21
use Koha::Holds;
Lines 109-115 sub process { Link Here
109
        $self->progress( ++$job_progress )->store;
108
        $self->progress( ++$job_progress )->store;
110
    }
109
    }
111
110
112
    my $json = JSON->new;
111
    my $json = $self->json;
113
    my $job_data = $json->decode($self->data);
112
    my $job_data = $json->decode($self->data);
114
    $job_data->{messages} = \@messages;
113
    $job_data->{messages} = \@messages;
115
    $job_data->{report}   = $report;
114
    $job_data->{report}   = $report;
(-)a/Koha/BackgroundJob/BatchDeleteAuthority.pm (-2 / +1 lines)
Lines 1-7 Link Here
1
package Koha::BackgroundJob::BatchDeleteAuthority;
1
package Koha::BackgroundJob::BatchDeleteAuthority;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use JSON;
5
4
6
use C4::AuthoritiesMarc;
5
use C4::AuthoritiesMarc;
7
6
Lines 84-90 sub process { Link Here
84
        $indexer->index_records( \@deleted_authids, "recordDelete", "authorityserver" );
83
        $indexer->index_records( \@deleted_authids, "recordDelete", "authorityserver" );
85
    }
84
    }
86
85
87
    my $json = JSON->new;
86
    my $json = $self->json;
88
    my $job_data = $json->decode($self->data);
87
    my $job_data = $json->decode($self->data);
89
    $job_data->{messages} = \@messages;
88
    $job_data->{messages} = \@messages;
90
    $job_data->{report} = $report;
89
    $job_data->{report} = $report;
(-)a/Koha/BackgroundJob/BatchDeleteBiblio.pm (-2 / +1 lines)
Lines 1-7 Link Here
1
package Koha::BackgroundJob::BatchDeleteBiblio;
1
package Koha::BackgroundJob::BatchDeleteBiblio;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use JSON;
5
4
6
use C4::Biblio;
5
use C4::Biblio;
7
6
Lines 167-173 sub process { Link Here
167
        ) if C4::Context->preference('RealTimeHoldsQueue');
166
        ) if C4::Context->preference('RealTimeHoldsQueue');
168
    }
167
    }
169
168
170
    my $json = JSON->new;
169
    my $json = $self->json;
171
    my $job_data = $json->decode($self->data);
170
    my $job_data = $json->decode($self->data);
172
    $job_data->{messages} = \@messages;
171
    $job_data->{messages} = \@messages;
173
    $job_data->{report} = $report;
172
    $job_data->{report} = $report;
(-)a/Koha/BackgroundJob/BatchDeleteItem.pm (-2 / +1 lines)
Lines 22-28 Koha::BackgroundJob::BatchDeleteItem - Background job derived class to process i Link Here
22
=cut
22
=cut
23
23
24
use Modern::Perl;
24
use Modern::Perl;
25
use JSON;
26
use List::MoreUtils qw( uniq );
25
use List::MoreUtils qw( uniq );
27
use Try::Tiny;
26
use Try::Tiny;
28
27
Lines 199-205 sub process { Link Here
199
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
198
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
200
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
199
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
201
200
202
    my $json = JSON->new;
201
    my $json = $self->json;
203
    my $job_data = $json->decode($self->data);
202
    my $job_data = $json->decode($self->data);
204
    $job_data->{messages} = \@messages;
203
    $job_data->{messages} = \@messages;
205
    $job_data->{report}   = $report;
204
    $job_data->{report}   = $report;
(-)a/Koha/BackgroundJob/BatchUpdateAuthority.pm (-2 / +1 lines)
Lines 16-22 package Koha::BackgroundJob::BatchUpdateAuthority; Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use JSON;
20
19
21
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
20
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
22
use C4::AuthoritiesMarc qw( ModAuthority );
21
use C4::AuthoritiesMarc qw( ModAuthority );
Lines 106-112 sub process { Link Here
106
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
105
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
107
    $indexer->index_records( \@record_ids, "specialUpdate", "authorityserver" );
106
    $indexer->index_records( \@record_ids, "specialUpdate", "authorityserver" );
108
107
109
    my $json = JSON->new;
108
    my $json = $self->json;
110
    my $job_data = $json->decode($self->data);
109
    my $job_data = $json->decode($self->data);
111
    $job_data->{messages} = \@messages;
110
    $job_data->{messages} = \@messages;
112
    $job_data->{report} = $report;
111
    $job_data->{report} = $report;
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-2 / +1 lines)
Lines 16-22 package Koha::BackgroundJob::BatchUpdateBiblio; Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use JSON;
20
19
21
use Koha::Biblios;
20
use Koha::Biblios;
22
use Koha::DateUtils qw( dt_from_string );
21
use Koha::DateUtils qw( dt_from_string );
Lines 118-124 sub process { Link Here
118
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
117
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
119
    $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver" );
118
    $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver" );
120
119
121
    my $json = JSON->new;
120
    my $json = $self->json;
122
    my $job_data = $json->decode($self->data);
121
    my $job_data = $json->decode($self->data);
123
    $job_data->{messages} = \@messages;
122
    $job_data->{messages} = \@messages;
124
    $job_data->{report} = $report;
123
    $job_data->{report} = $report;
(-)a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm (-2 / +1 lines)
Lines 17-23 package Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use JSON;
21
use Try::Tiny;
20
use Try::Tiny;
22
21
23
use Koha::Biblios;
22
use Koha::Biblios;
Lines 120-126 sub process { Link Here
120
        $self->progress( $self->progress + 1 )->store;
119
        $self->progress( $self->progress + 1 )->store;
121
    }
120
    }
122
121
123
    my $json = JSON->new;
122
    my $json = $self->json;
124
    my $job_data = $json->decode($self->data);
123
    my $job_data = $json->decode($self->data);
125
    $job_data->{messages} = \@messages;
124
    $job_data->{messages} = \@messages;
126
    $job_data->{report}   = $report;
125
    $job_data->{report}   = $report;
(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-2 / +1 lines)
Lines 16-22 package Koha::BackgroundJob::BatchUpdateItem; Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use JSON;
20
use List::MoreUtils qw( uniq );
19
use List::MoreUtils qw( uniq );
21
use Try::Tiny;
20
use Try::Tiny;
22
21
Lines 129-135 sub process { Link Here
129
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
128
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
130
    };
129
    };
131
130
132
    my $json = JSON->new;
131
    my $json = $self->json;
133
    $self->discard_changes;
132
    $self->discard_changes;
134
    my $job_data = $json->decode($self->data);
133
    my $job_data = $json->decode($self->data);
135
    $job_data->{report} = $report;
134
    $job_data->{report} = $report;
(-)a/misc/background_jobs_worker.pl (-3 / +2 lines)
Lines 90-96 while (1) { Link Here
90
        }
90
        }
91
91
92
        my $body = $frame->body;
92
        my $body = $frame->body;
93
        my $args = decode_json($body);
93
        my $args = decode_json($body); # TODO Should this be from_json? Check utf8 flag.
94
94
95
        # FIXME This means we need to have create the DB entry before
95
        # FIXME This means we need to have create the DB entry before
96
        # It could work in a first step, but then we will want to handle job that will be created from the message received
96
        # It could work in a first step, but then we will want to handle job that will be created from the message received
Lines 102-108 while (1) { Link Here
102
    } else {
102
    } else {
103
        my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues });
103
        my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues });
104
        while ( my $job = $jobs->next ) {
104
        while ( my $job = $jobs->next ) {
105
            my $args = decode_json($job->data);
105
            my $args = $job->json->decode($job->data);
106
            process_job( $job, { job_id => $job->id, %$args } );
106
            process_job( $job, { job_id => $job->id, %$args } );
107
        }
107
        }
108
        sleep 10;
108
        sleep 10;
109
- 

Return to bug 31351