Bugzilla – Attachment 140311 Details for
Bug 31351
Worker dies on reindex job when operator last name/first name/branch name contains non-ASCII chars
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31351: (QA follow-up) Use $self->json in Background modules
Bug-31351-QA-follow-up-Use-self-json-in-Background.patch (text/plain), 10.48 KB, created by
Marcel de Rooy
on 2022-09-07 14:34:20 UTC
(
hide
)
Description:
Bug 31351: (QA follow-up) Use $self->json in Background modules
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2022-09-07 14:34:20 UTC
Size:
10.48 KB
patch
obsolete
>From d7c9782ff6d7bd94147785ea5e3c4121a56d0f8a Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 7 Sep 2022 12:05:17 +0000 >Subject: [PATCH] Bug 31351: (QA follow-up) Use $self->json in Background > modules >Content-Type: text/plain; charset=utf-8 > >Making the disabling utf8 flag explicit instead of depending on >the default of the CPAN module. > >Incorporating the change in background_jobs_worker too. > >Test plan: >See next patches when we look at unit tests. >Restart koha-worker. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/BackgroundJob.pm | 29 ++++++++++++++----- > Koha/BackgroundJob/BatchCancelHold.pm | 3 +- > Koha/BackgroundJob/BatchDeleteAuthority.pm | 3 +- > Koha/BackgroundJob/BatchDeleteBiblio.pm | 3 +- > Koha/BackgroundJob/BatchDeleteItem.pm | 3 +- > Koha/BackgroundJob/BatchUpdateAuthority.pm | 3 +- > Koha/BackgroundJob/BatchUpdateBiblio.pm | 3 +- > .../BatchUpdateBiblioHoldsQueue.pm | 3 +- > Koha/BackgroundJob/BatchUpdateItem.pm | 3 +- > misc/background_jobs_worker.pl | 4 +-- > 10 files changed, 32 insertions(+), 25 deletions(-) > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 69a39f9402..e4aede3fe3 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -100,7 +100,7 @@ sub enqueue { > my $job_args = $params->{job_args}; > my $job_context = $params->{job_context} // C4::Context->userenv; > my $job_queue = $params->{job_queue} // 'default'; >- my $json = JSON->new; >+ my $json = $self->json; > > my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef; > $job_context->{interface} = C4::Context->interface; >@@ -167,7 +167,7 @@ sub process { > $args ||= {}; > > if ( $self->context ) { >- my $context = JSON->new->decode($self->context); >+ my $context = $self->json->decode($self->context); > C4::Context->_new_userenv(-1); > C4::Context->interface( $context->{interface} ); > C4::Context->set_userenv( >@@ -251,11 +251,26 @@ sub finish { > return $self->set( > { > ended_on => \'NOW()', >- data => JSON->new->encode($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; >@@ -267,7 +282,7 @@ Returns the decoded JSON contents from $self->data. > sub decoded_data { > my ($self) = @_; > >- return $self->data ? JSON->new->decode( $self->data ) : undef; >+ return $self->data ? $self->json->decode( $self->data ) : undef; > } > > =head3 set_encoded_data >@@ -281,7 +296,7 @@ Serializes I<$data> as a JSON string and sets the I<data> attribute with it. > sub set_encoded_data { > my ( $self, $data ) = @_; > >- return $self->data( $data ? JSON->new->encode($data) : undef ); >+ return $self->data( $data ? $self->json->encode($data) : undef ); > } > > =head3 job_type >@@ -302,7 +317,7 @@ sub messages { > my ( $self ) = @_; > > my @messages; >- my $data_dump = JSON->new->decode($self->data); >+ my $data_dump = $self->json->decode($self->data); > if ( exists $data_dump->{messages} ) { > @messages = @{ $data_dump->{messages} }; > } >@@ -319,7 +334,7 @@ Report of the job. > sub report { > my ( $self ) = @_; > >- my $data_dump = JSON->new->decode($self->data); >+ my $data_dump = $self->json->decode($self->data); > return $data_dump->{report} || {}; > } > >diff --git a/Koha/BackgroundJob/BatchCancelHold.pm b/Koha/BackgroundJob/BatchCancelHold.pm >index 9fdcb5515a..cf730a6d3f 100644 >--- a/Koha/BackgroundJob/BatchCancelHold.pm >+++ b/Koha/BackgroundJob/BatchCancelHold.pm >@@ -16,7 +16,6 @@ package Koha::BackgroundJob::BatchCancelHold; > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use JSON; > > use Koha::DateUtils qw( dt_from_string ); > use Koha::Holds; >@@ -109,7 +108,7 @@ sub process { > $self->progress( ++$job_progress )->store; > } > >- my $json = JSON->new; >+ my $json = $self->json; > my $job_data = $json->decode($self->data); > $job_data->{messages} = \@messages; > $job_data->{report} = $report; >diff --git a/Koha/BackgroundJob/BatchDeleteAuthority.pm b/Koha/BackgroundJob/BatchDeleteAuthority.pm >index 5e407f80af..29c1f5b3ec 100644 >--- a/Koha/BackgroundJob/BatchDeleteAuthority.pm >+++ b/Koha/BackgroundJob/BatchDeleteAuthority.pm >@@ -1,7 +1,6 @@ > package Koha::BackgroundJob::BatchDeleteAuthority; > > use Modern::Perl; >-use JSON; > > use C4::AuthoritiesMarc; > >@@ -84,7 +83,7 @@ sub process { > $indexer->index_records( \@deleted_authids, "recordDelete", "authorityserver" ); > } > >- my $json = JSON->new; >+ my $json = $self->json; > my $job_data = $json->decode($self->data); > $job_data->{messages} = \@messages; > $job_data->{report} = $report; >diff --git a/Koha/BackgroundJob/BatchDeleteBiblio.pm b/Koha/BackgroundJob/BatchDeleteBiblio.pm >index 6186500da0..b87d255a08 100644 >--- a/Koha/BackgroundJob/BatchDeleteBiblio.pm >+++ b/Koha/BackgroundJob/BatchDeleteBiblio.pm >@@ -1,7 +1,6 @@ > package Koha::BackgroundJob::BatchDeleteBiblio; > > use Modern::Perl; >-use JSON; > > use C4::Biblio; > >@@ -167,7 +166,7 @@ sub process { > ) if C4::Context->preference('RealTimeHoldsQueue'); > } > >- my $json = JSON->new; >+ my $json = $self->json; > my $job_data = $json->decode($self->data); > $job_data->{messages} = \@messages; > $job_data->{report} = $report; >diff --git a/Koha/BackgroundJob/BatchDeleteItem.pm b/Koha/BackgroundJob/BatchDeleteItem.pm >index 1f717b3d80..d26504d8e2 100644 >--- a/Koha/BackgroundJob/BatchDeleteItem.pm >+++ b/Koha/BackgroundJob/BatchDeleteItem.pm >@@ -22,7 +22,6 @@ Koha::BackgroundJob::BatchDeleteItem - Background job derived class to process i > =cut > > use Modern::Perl; >-use JSON; > use List::MoreUtils qw( uniq ); > use Try::Tiny; > >@@ -199,7 +198,7 @@ sub process { > $report->{not_deleted_itemnumbers} = \@not_deleted_itemnumbers; > $report->{deleted_biblionumbers} = \@deleted_biblionumbers; > >- my $json = JSON->new; >+ my $json = $self->json; > my $job_data = $json->decode($self->data); > $job_data->{messages} = \@messages; > $job_data->{report} = $report; >diff --git a/Koha/BackgroundJob/BatchUpdateAuthority.pm b/Koha/BackgroundJob/BatchUpdateAuthority.pm >index 33afd61e12..23079672ff 100644 >--- a/Koha/BackgroundJob/BatchUpdateAuthority.pm >+++ b/Koha/BackgroundJob/BatchUpdateAuthority.pm >@@ -16,7 +16,6 @@ package Koha::BackgroundJob::BatchUpdateAuthority; > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use JSON; > > use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate ); > use C4::AuthoritiesMarc qw( ModAuthority ); >@@ -106,7 +105,7 @@ sub process { > my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); > $indexer->index_records( \@record_ids, "specialUpdate", "authorityserver" ); > >- my $json = JSON->new; >+ my $json = $self->json; > my $job_data = $json->decode($self->data); > $job_data->{messages} = \@messages; > $job_data->{report} = $report; >diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm >index 20cb296303..5b4d6b143b 100644 >--- a/Koha/BackgroundJob/BatchUpdateBiblio.pm >+++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm >@@ -16,7 +16,6 @@ package Koha::BackgroundJob::BatchUpdateBiblio; > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use JSON; > > use Koha::Biblios; > use Koha::DateUtils qw( dt_from_string ); >@@ -118,7 +117,7 @@ sub process { > my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); > $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver" ); > >- my $json = JSON->new; >+ my $json = $self->json; > my $job_data = $json->decode($self->data); > $job_data->{messages} = \@messages; > $job_data->{report} = $report; >diff --git a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm >index 607ae22174..cbe2494e75 100644 >--- a/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm >+++ b/Koha/BackgroundJob/BatchUpdateBiblioHoldsQueue.pm >@@ -17,7 +17,6 @@ package Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > > use Modern::Perl; > >-use JSON; > use Try::Tiny; > > use Koha::Biblios; >@@ -120,7 +119,7 @@ sub process { > $self->progress( $self->progress + 1 )->store; > } > >- my $json = JSON->new; >+ my $json = $self->json; > my $job_data = $json->decode($self->data); > $job_data->{messages} = \@messages; > $job_data->{report} = $report; >diff --git a/Koha/BackgroundJob/BatchUpdateItem.pm b/Koha/BackgroundJob/BatchUpdateItem.pm >index 8c1e8aefbd..d389ab97e2 100644 >--- a/Koha/BackgroundJob/BatchUpdateItem.pm >+++ b/Koha/BackgroundJob/BatchUpdateItem.pm >@@ -16,7 +16,6 @@ package Koha::BackgroundJob::BatchUpdateItem; > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use JSON; > use List::MoreUtils qw( uniq ); > use Try::Tiny; > >@@ -129,7 +128,7 @@ sub process { > if ( $_ =~ /Rollback failed/ ); # Rollback failed > }; > >- my $json = JSON->new; >+ my $json = $self->json; > $self->discard_changes; > my $job_data = $json->decode($self->data); > $job_data->{report} = $report; >diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl >index 0d9d7e2d1d..eb36f34f96 100755 >--- a/misc/background_jobs_worker.pl >+++ b/misc/background_jobs_worker.pl >@@ -90,7 +90,7 @@ while (1) { > } > > my $body = $frame->body; >- my $args = decode_json($body); >+ my $args = decode_json($body); # TODO Should this be from_json? Check utf8 flag. > > # FIXME This means we need to have create the DB entry before > # It could work in a first step, but then we will want to handle job that will be created from the message received >@@ -102,7 +102,7 @@ while (1) { > } else { > my $jobs = Koha::BackgroundJobs->search({ status => 'new', queue => \@queues }); > while ( my $job = $jobs->next ) { >- my $args = decode_json($job->data); >+ my $args = $job->json->decode($job->data); > process_job( $job, { job_id => $job->id, %$args } ); > } > sleep 10; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31351
:
139058
|
139438
|
140222
|
140236
|
140262
|
140310
| 140311 |
140312
|
140313
|
140314
|
140315