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

(-)a/Koha/BackgroundJob.pm (-11 / +11 lines)
Lines 16-23 package Koha::BackgroundJob; 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 qw( decode_json encode_json );
19
use JSON;
20
use Encode qw( encode_utf8 );
21
use Carp qw( croak );
20
use Carp qw( croak );
22
use Net::Stomp;
21
use Net::Stomp;
23
use Try::Tiny qw( catch try );
22
use Try::Tiny qw( catch try );
Lines 101-111 sub enqueue { Link Here
101
    my $job_args    = $params->{job_args};
100
    my $job_args    = $params->{job_args};
102
    my $job_context = $params->{job_context} // C4::Context->userenv;
101
    my $job_context = $params->{job_context} // C4::Context->userenv;
103
    my $job_queue   = $params->{job_queue}  // 'default';
102
    my $job_queue   = $params->{job_queue}  // 'default';
103
    my $json = JSON->new;
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;
107
    my $json_context = encode_json $job_context;
107
    my $json_context = $json->encode($job_context);
108
    my $json_args = encode_json $job_args;
108
    my $json_args = $json->encode($job_args);
109
109
110
    $self->set(
110
    $self->set(
111
        {
111
        {
Lines 130-136 sub enqueue { Link Here
130
    };
130
    };
131
    return unless $conn;
131
    return unless $conn;
132
132
133
    $json_args = encode_json $job_args;
133
    $json_args = $json->encode($job_args);
134
    try {
134
    try {
135
        # This namespace is wrong, it must be a vhost instead.
135
        # This namespace is wrong, it must be a vhost instead.
136
        # But to do so it needs to be created on the server => much more work when a new Koha instance is created.
136
        # But to do so it needs to be created on the server => much more work when a new Koha instance is created.
Lines 167-173 sub process { Link Here
167
    $args ||= {};
167
    $args ||= {};
168
168
169
    if ( $self->context ) {
169
    if ( $self->context ) {
170
        my $context = decode_json($self->context);
170
        my $context = JSON->new->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-257 sub finish { Link Here
251
    return $self->set(
251
    return $self->set(
252
        {
252
        {
253
            ended_on => \'NOW()',
253
            ended_on => \'NOW()',
254
            data     => encode_json($data),
254
            data     => JSON->new->encode($data),
255
        }
255
        }
256
    )->store;
256
    )->store;
257
}
257
}
Lines 267-273 Returns the decoded JSON contents from $self->data. Link Here
267
sub decoded_data {
267
sub decoded_data {
268
    my ($self) = @_;
268
    my ($self) = @_;
269
269
270
    return $self->data ? decode_json( $self->data ) : undef;
270
    return $self->data ? JSON->new->decode( $self->data ) : undef;
271
}
271
}
272
272
273
=head3 set_encoded_data
273
=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 {
281
sub set_encoded_data {
282
    my ( $self, $data ) = @_;
282
    my ( $self, $data ) = @_;
283
283
284
    return $self->data( $data ? encode_json($data) : undef );
284
    return $self->data( $data ? JSON->new->encode($data) : undef );
285
}
285
}
286
286
287
=head3 job_type
287
=head3 job_type
Lines 302-308 sub messages { Link Here
302
    my ( $self ) = @_;
302
    my ( $self ) = @_;
303
303
304
    my @messages;
304
    my @messages;
305
    my $data_dump = decode_json encode_utf8 $self->data;
305
    my $data_dump = JSON->new->decode($self->data);
306
    if ( exists $data_dump->{messages} ) {
306
    if ( exists $data_dump->{messages} ) {
307
        @messages = @{ $data_dump->{messages} };
307
        @messages = @{ $data_dump->{messages} };
308
    }
308
    }
Lines 319-325 Report of the job. Link Here
319
sub report {
319
sub report {
320
    my ( $self ) = @_;
320
    my ( $self ) = @_;
321
321
322
    my $data_dump = decode_json encode_utf8 $self->data;
322
    my $data_dump = JSON->new->decode($self->data);
323
    return $data_dump->{report} || {};
323
    return $data_dump->{report} || {};
324
}
324
}
325
325
(-)a/Koha/BackgroundJob/BatchCancelHold.pm (-3 / +4 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 qw( encode_json decode_json );
19
use JSON;
20
20
21
use Koha::DateUtils qw( dt_from_string );
21
use Koha::DateUtils qw( dt_from_string );
22
use Koha::Holds;
22
use Koha::Holds;
Lines 109-119 sub process { Link Here
109
        $self->progress( ++$job_progress )->store;
109
        $self->progress( ++$job_progress )->store;
110
    }
110
    }
111
111
112
    my $job_data = decode_json $self->data;
112
    my $json = JSON->new;
113
    my $job_data = $json->decode($self->data);
113
    $job_data->{messages} = \@messages;
114
    $job_data->{messages} = \@messages;
114
    $job_data->{report}   = $report;
115
    $job_data->{report}   = $report;
115
116
116
    $self->ended_on(dt_from_string)->data( encode_json $job_data);
117
    $self->ended_on(dt_from_string)->data($json->encode($job_data));
117
    $self->status('finished') if $self->status ne 'cancelled';
118
    $self->status('finished') if $self->status ne 'cancelled';
118
    $self->store;
119
    $self->store;
119
120
(-)a/Koha/BackgroundJob/BatchDeleteAuthority.pm (-3 / +4 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 qw( encode_json decode_json );
4
use JSON;
5
5
6
use C4::AuthoritiesMarc;
6
use C4::AuthoritiesMarc;
7
7
Lines 84-95 sub process { Link Here
84
        $indexer->index_records( \@deleted_authids, "recordDelete", "authorityserver" );
84
        $indexer->index_records( \@deleted_authids, "recordDelete", "authorityserver" );
85
    }
85
    }
86
86
87
    my $job_data = decode_json $self->data;
87
    my $json = JSON->new;
88
    my $job_data = $json->decode($self->data);
88
    $job_data->{messages} = \@messages;
89
    $job_data->{messages} = \@messages;
89
    $job_data->{report} = $report;
90
    $job_data->{report} = $report;
90
91
91
    $self->ended_on(dt_from_string)
92
    $self->ended_on(dt_from_string)
92
        ->data(encode_json $job_data);
93
        ->data($json->encode($job_data));
93
    $self->status('finished') if $self->status ne 'cancelled';
94
    $self->status('finished') if $self->status ne 'cancelled';
94
    $self->store;
95
    $self->store;
95
}
96
}
(-)a/Koha/BackgroundJob/BatchDeleteBiblio.pm (-3 / +4 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 qw( encode_json decode_json );
4
use JSON;
5
5
6
use C4::Biblio;
6
use C4::Biblio;
7
7
Lines 167-178 sub process { Link Here
167
        ) if C4::Context->preference('RealTimeHoldsQueue');
167
        ) if C4::Context->preference('RealTimeHoldsQueue');
168
    }
168
    }
169
169
170
    my $job_data = decode_json $self->data;
170
    my $json = JSON->new;
171
    my $job_data = $json->decode($self->data);
171
    $job_data->{messages} = \@messages;
172
    $job_data->{messages} = \@messages;
172
    $job_data->{report} = $report;
173
    $job_data->{report} = $report;
173
174
174
    $self->ended_on(dt_from_string)
175
    $self->ended_on(dt_from_string)
175
        ->data(encode_json $job_data);
176
        ->data($json->encode($job_data));
176
    $self->status('finished') if $self->status ne 'cancelled';
177
    $self->status('finished') if $self->status ne 'cancelled';
177
    $self->store;
178
    $self->store;
178
}
179
}
(-)a/Koha/BackgroundJob/BatchDeleteItem.pm (-3 / +4 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 qw( encode_json decode_json );
25
use JSON;
26
use List::MoreUtils qw( uniq );
26
use List::MoreUtils qw( uniq );
27
use Try::Tiny;
27
use Try::Tiny;
28
28
Lines 199-209 sub process { Link Here
199
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
199
    $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers;
200
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
200
    $report->{deleted_biblionumbers}   = \@deleted_biblionumbers;
201
201
202
    my $job_data = decode_json $self->data;
202
    my $json = JSON->new;
203
    my $job_data = $json->decode($self->data);
203
    $job_data->{messages} = \@messages;
204
    $job_data->{messages} = \@messages;
204
    $job_data->{report}   = $report;
205
    $job_data->{report}   = $report;
205
206
206
    $self->ended_on(dt_from_string)->data( encode_json $job_data);
207
    $self->ended_on(dt_from_string)->data( $json->encode($job_data));
207
    $self->status('finished') if $self->status ne 'cancelled';
208
    $self->status('finished') if $self->status ne 'cancelled';
208
    $self->store;
209
    $self->store;
209
}
210
}
(-)a/Koha/BackgroundJob/BatchUpdateAuthority.pm (-3 / +4 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 qw( decode_json encode_json );
19
use JSON;
20
20
21
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
21
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
22
use C4::AuthoritiesMarc qw( ModAuthority );
22
use C4::AuthoritiesMarc qw( ModAuthority );
Lines 106-117 sub process { Link Here
106
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
106
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
107
    $indexer->index_records( \@record_ids, "specialUpdate", "authorityserver" );
107
    $indexer->index_records( \@record_ids, "specialUpdate", "authorityserver" );
108
108
109
    my $job_data = decode_json $self->data;
109
    my $json = JSON->new;
110
    my $job_data = $json->decode($self->data);
110
    $job_data->{messages} = \@messages;
111
    $job_data->{messages} = \@messages;
111
    $job_data->{report} = $report;
112
    $job_data->{report} = $report;
112
113
113
    $self->ended_on(dt_from_string)
114
    $self->ended_on(dt_from_string)
114
        ->data(encode_json $job_data);
115
        ->data($json->encode($job_data));
115
    $self->status('finished') if $self->status ne 'cancelled';
116
    $self->status('finished') if $self->status ne 'cancelled';
116
    $self->store;
117
    $self->store;
117
118
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-3 / +4 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 qw( decode_json encode_json );
19
use JSON;
20
20
21
use Koha::Biblios;
21
use Koha::Biblios;
22
use Koha::DateUtils qw( dt_from_string );
22
use Koha::DateUtils qw( dt_from_string );
Lines 118-129 sub process { Link Here
118
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
118
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
119
    $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver" );
119
    $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver" );
120
120
121
    my $job_data = decode_json $self->data;
121
    my $json = JSON->new;
122
    my $job_data = $json->decode($self->data);
122
    $job_data->{messages} = \@messages;
123
    $job_data->{messages} = \@messages;
123
    $job_data->{report} = $report;
124
    $job_data->{report} = $report;
124
125
125
    $self->ended_on(dt_from_string)
126
    $self->ended_on(dt_from_string)
126
        ->data(encode_json $job_data);
127
        ->data($json->encode($job_data));
127
    $self->status('finished') if $self->status ne 'cancelled';
128
    $self->status('finished') if $self->status ne 'cancelled';
128
    $self->store;
129
    $self->store;
129
}
130
}
(-)a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm (-3 / +4 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 qw( encode_json decode_json );
20
use JSON;
21
use Try::Tiny;
21
use Try::Tiny;
22
22
23
use Koha::Biblios;
23
use Koha::Biblios;
Lines 120-133 sub process { Link Here
120
        $self->progress( $self->progress + 1 )->store;
120
        $self->progress( $self->progress + 1 )->store;
121
    }
121
    }
122
122
123
    my $job_data = decode_json $self->data;
123
    my $json = JSON->new;
124
    my $job_data = $json->decode($self->data);
124
    $job_data->{messages} = \@messages;
125
    $job_data->{messages} = \@messages;
125
    $job_data->{report}   = $report;
126
    $job_data->{report}   = $report;
126
127
127
    $self->set(
128
    $self->set(
128
        {
129
        {
129
            ended_on => \'NOW()',
130
            ended_on => \'NOW()',
130
            data     => encode_json $job_data,
131
            data     => $json->encode($job_data),
131
            status   => 'finished',
132
            status   => 'finished',
132
        }
133
        }
133
    )->store;
134
    )->store;
(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-5 / +4 lines)
Lines 16-23 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 qw( encode_json decode_json );
19
use JSON;
20
use Encode qw( encode_utf8 );
21
use List::MoreUtils qw( uniq );
20
use List::MoreUtils qw( uniq );
22
use Try::Tiny;
21
use Try::Tiny;
23
22
Lines 130-140 sub process { Link Here
130
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
129
          if ( $_ =~ /Rollback failed/ );    # Rollback failed
131
    };
130
    };
132
131
132
    my $json = JSON->new;
133
    $self->discard_changes;
133
    $self->discard_changes;
134
    my $job_data = decode_json encode_utf8 $self->data;
134
    my $job_data = $json->decode($self->data);
135
    $job_data->{report} = $report;
135
    $job_data->{report} = $report;
136
136
137
    $self->ended_on(dt_from_string)->data( encode_json $job_data);
137
    $self->ended_on(dt_from_string)->data($json->encode($job_data));
138
    $self->status('finished') if $self->status ne 'cancelled';
138
    $self->status('finished') if $self->status ne 'cancelled';
139
    $self->store;
139
    $self->store;
140
}
140
}
141
- 

Return to bug 31351