# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
-use JSON qw( decode_json encode_json );
-use Encode qw( encode_utf8 );
+use JSON;
use Carp qw( croak );
use Net::Stomp;
use Try::Tiny qw( catch try );
my $job_args = $params->{job_args};
my $job_context = $params->{job_context} // C4::Context->userenv;
my $job_queue = $params->{job_queue} // 'default';
+ my $json = $self->json;
my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef;
$job_context->{interface} = C4::Context->interface;
- my $json_context = encode_json $job_context;
- my $json_args = encode_json $job_args;
+ my $json_context = $json->encode($job_context);
+ my $json_args = $json->encode($job_args);
$self->set(
{
};
return unless $conn;
- $json_args = encode_json $job_args;
+ $json_args = $json->encode($job_args);
try {
# This namespace is wrong, it must be a vhost instead.
# But to do so it needs to be created on the server => much more work when a new Koha instance is created.
$args ||= {};
if ( $self->context ) {
- my $context = decode_json($self->context);
+ my $context = $self->json->decode($self->context);
C4::Context->_new_userenv(-1);
C4::Context->interface( $context->{interface} );
C4::Context->set_userenv(
return $self->set(
{
ended_on => \'NOW()',
- data => encode_json($data),
+ data => $self->json->encode($data),
}
)->store;
}
+=head3 json
+
+ my $JSON_object = $self->json;
+
+Returns a JSON object with utf8 disabled. Encoding to UTF-8 should be
+done later.
+
+=cut
+
+sub json {
+ my ( $self ) = @_;
+ $self->{_json} //= JSON->new->utf8(0); # TODO Should we allow_nonref ?
+ return $self->{_json};
+}
+
=head3 decoded_data
my $job_data = $self->decoded_data;
sub decoded_data {
my ($self) = @_;
- return $self->data ? decode_json( $self->data ) : undef;
+ return $self->data ? $self->json->decode( $self->data ) : undef;
}
=head3 set_encoded_data
sub set_encoded_data {
my ( $self, $data ) = @_;
- return $self->data( $data ? encode_json($data) : undef );
+ return $self->data( $data ? $self->json->encode($data) : undef );
}
=head3 job_type
my ( $self ) = @_;
my @messages;
- my $data_dump = decode_json encode_utf8 $self->data;
+ my $data_dump = $self->json->decode($self->data);
if ( exists $data_dump->{messages} ) {
@messages = @{ $data_dump->{messages} };
}
sub report {
my ( $self ) = @_;
- my $data_dump = decode_json encode_utf8 $self->data;
+ my $data_dump = $self->json->decode($self->data);
return $data_dump->{report} || {};
}
sub type_to_class_mapping {
my ($self) = @_;
- my $plugins_mapping = $self->plugin_types_to_classes;
+ my $plugins_mapping = ( C4::Context->config("enable_plugins") ) ? $self->plugin_types_to_classes : {};
return ($plugins_mapping)
? { %{ $self->core_types_to_classes }, %$plugins_mapping }