Bugzilla – Attachment 162381 Details for
Bug 33431
Make code use C4::Context->yaml_preference
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33431: Make C4::Circulation use C4::Context->yaml_preference
Bug-33431-Make-C4Circulation-use-C4Context-yamlpre.patch (text/plain), 6.20 KB, created by
Tomás Cohen Arazi (tcohen)
on 2024-02-23 15:02:40 UTC
(
hide
)
Description:
Bug 33431: Make C4::Circulation use C4::Context->yaml_preference
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2024-02-23 15:02:40 UTC
Size:
6.20 KB
patch
obsolete
>From d8b4442dd8493f691b2f30ea90656fe6d341d58a Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 6 Apr 2023 10:48:04 -0300 >Subject: [PATCH] Bug 33431: Make C4::Circulation use > C4::Context->yaml_preference > >This patch removes manual YAML handling for sysprefs in C4::Circulation. > >It also makes C4::Context->yaml_preference not warn when undef is >retrieved from the sysprefs. > >To test: >1. Run: > $ ktd --shell > k$ prove t/db_dependent/Circulation* >=> SUCCESS: Tests pass! >2. Apply this patch >3. Repeat 1 >=> SUCCESS: Tests pass! >4. Sign off :-D > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com> >--- > C4/Circulation.pm | 70 ++++++++++++++++++----------------------------- > C4/Context.pm | 2 +- > 2 files changed, 28 insertions(+), 44 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 109809d4b99..5f58245c7f2 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -21,7 +21,6 @@ package C4::Circulation; > use Modern::Perl; > use DateTime; > use POSIX qw( floor ); >-use YAML::XS; > use Encode; > > use C4::Context; >@@ -1798,21 +1797,12 @@ sub AddIssue { > } > } > >- my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckout'); >- if ($yaml) { >- $yaml = "$yaml\n\n"; >- >- my $rules; >- eval { $rules = YAML::XS::Load(Encode::encode_utf8($yaml)); }; >- if ($@) { >- warn "Unable to parse UpdateNotForLoanStatusOnCheckout syspref : $@"; >- } >- else { >- foreach my $key ( keys %$rules ) { >- if ( $item_object->notforloan eq $key ) { >- $item_object->notforloan($rules->{$key})->store({ log_action => 0, skip_record_index => 1 }); >- last; >- } >+ my $rules = C4::Context->yaml_preference('UpdateNotForLoanStatusOnCheckout'); >+ if ($rules) { >+ foreach my $key ( keys %$rules ) { >+ if ( $item_object->notforloan eq $key ) { >+ $item_object->notforloan($rules->{$key})->store({ log_action => 0, skip_record_index => 1 }); >+ last; > } > } > } >@@ -2215,34 +2205,28 @@ sub AddReturn { > $messages->{ $loc_msg_key } = $loc_messages->{ $loc_msg_key }; > } > >- my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin'); >- if ($yaml) { >- $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt >- my $rules; >- eval { $rules = YAML::XS::Load(Encode::encode_utf8($yaml)); }; >- if ($@) { >- warn "Unable to parse UpdateNotForLoanStatusOnCheckin syspref : $@"; >- } >- else { >- if ( defined $rules->{$item->itype} ) { >- foreach my $notloan_rule_key (keys %{ $rules->{$item->itype}} ) { >- if ( $item->notforloan eq $notloan_rule_key ) { >- $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$item->itype}->{$notloan_rule_key} }; >- $item->notforloan( $rules->{ $item->itype }->{$notloan_rule_key} ) >- ->store( { log_action => 0, skip_record_index => 1, skip_holds_queue => 1 } ) >- unless $rules->{ $item->itype }->{$notloan_rule_key} eq 'ONLYMESSAGE'; >- last; >- } >+ my $rules = C4::Context->yaml_preference('UpdateNotForLoanStatusOnCheckin'); >+ if ($rules) { >+ if ( defined $rules->{ $item->itype } ) { >+ foreach my $notloan_rule_key ( keys %{ $rules->{ $item->itype } } ) { >+ if ( $item->notforloan eq $notloan_rule_key ) { >+ $messages->{'NotForLoanStatusUpdated'} = >+ { from => $item->notforloan, to => $rules->{ $item->itype }->{$notloan_rule_key} }; >+ $item->notforloan( $rules->{ $item->itype }->{$notloan_rule_key} ) >+ ->store( { log_action => 0, skip_record_index => 1, skip_holds_queue => 1 } ) >+ unless $rules->{ $item->itype }->{$notloan_rule_key} eq 'ONLYMESSAGE'; >+ last; > } >- } elsif ( defined $rules->{'_ALL_'} ) { >- foreach my $notloan_rule_key (keys %{ $rules->{'_ALL_'}} ) { >- if ( $item->notforloan eq $notloan_rule_key ) { >- $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{'_ALL_'}->{$notloan_rule_key} }; >- $item->notforloan( $rules->{'_ALL_'}->{$notloan_rule_key} ) >- ->store( { log_action => 0, skip_record_index => 1, skip_holds_queue => 1 } ) >- unless $rules->{ '_ALL_' }->{$notloan_rule_key} eq 'ONLYMESSAGE'; >- last; >- } >+ } >+ } elsif ( defined $rules->{'_ALL_'} ) { >+ foreach my $notloan_rule_key ( keys %{ $rules->{'_ALL_'} } ) { >+ if ( $item->notforloan eq $notloan_rule_key ) { >+ $messages->{'NotForLoanStatusUpdated'} = >+ { from => $item->notforloan, to => $rules->{'_ALL_'}->{$notloan_rule_key} }; >+ $item->notforloan( $rules->{'_ALL_'}->{$notloan_rule_key} ) >+ ->store( { log_action => 0, skip_record_index => 1, skip_holds_queue => 1 } ) >+ unless $rules->{'_ALL_'}->{$notloan_rule_key} eq 'ONLYMESSAGE'; >+ last; > } > } > } >diff --git a/C4/Context.pm b/C4/Context.pm >index 091e4783a49..0169b10f85e 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -342,7 +342,7 @@ the value cannot be properly decoded as YAML. > sub yaml_preference { > my ( $self, $preference ) = @_; > >- my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) ) ); }; >+ my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) // '' ) ); }; > if ($@) { > warn "Unable to parse $preference syspref : $@"; > return; >-- >2.30.2
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 33431
:
149236
|
149237
|
149238
|
160245
|
160246
|
160247
|
160281
|
160282
|
160283
|
160392
|
160393
|
160394
| 162381 |
162382
|
162384