Bugzilla – Attachment 79254 Details for
Bug 15494
Block renewals by arbitrary item values
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15494: Move yaml syspref code to its own sub
Bug-15494-Move-yaml-syspref-code-to-its-own-sub.patch (text/plain), 5.33 KB, created by
Nick Clemens (kidclamp)
on 2018-09-21 20:18:11 UTC
(
hide
)
Description:
Bug 15494: Move yaml syspref code to its own sub
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2018-09-21 20:18:11 UTC
Size:
5.33 KB
patch
obsolete
>From cf28911099d34e294ca867a8af322796fd341fa0 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 21 Sep 2018 20:16:24 +0000 >Subject: [PATCH] Bug 15494: Move yaml syspref code to its own sub > >To test: >1 - prove -v t/db_dependent/Koha/Util/SystemPreferences.t >--- > C4/Circulation.pm | 14 +----- > Koha/Util/SystemPreferences.pm | 69 ++++++++++++++++++++++++++++ > t/db_dependent/Koha/Util/SystemPreferences.t | 42 +++++++++++++++++ > 3 files changed, 113 insertions(+), 12 deletions(-) > create mode 100644 Koha/Util/SystemPreferences.pm > create mode 100644 t/db_dependent/Koha/Util/SystemPreferences.t > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index e782ce5..a04112d 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -57,6 +57,7 @@ use Koha::RefundLostItemFeeRule; > use Koha::RefundLostItemFeeRules; > use Koha::Account::Lines; > use Koha::Account::Offsets; >+use Koha::Util::SystemPreferences; > use Carp; > use List::MoreUtils qw( uniq any ); > use Scalar::Util qw( looks_like_number ); >@@ -4108,18 +4109,7 @@ sub _item_denied_renewal { > my $item = $params->{item}; > return unless $item; > >- my @lines = split /\n/, C4::Context->preference('ItemsDeniedRenewal')//''; >- my $denyingrules; >- foreach my $line (@lines){ >- my ($field,$array) = split /:/, $line; >- next if !$array; >- $field =~ s/^\s*|\s*$//g; >- $array =~ s/[ [\]\r]//g; >- my @array = split /,/, $array; >- @array = map { $_ eq '""' || $_ eq "''" ? '' : $_ } @array; >- @array = map { $_ eq 'NULL' ? undef : $_ } @array; >- $denyingrules->{$field} = \@array; >- } >+ my $denyingrules = get_yaml_pref_hash('ItemsDeniedRenewal'); > return unless $denyingrules; > foreach my $field (keys %$denyingrules) { > my $val = $item->{$field}; >diff --git a/Koha/Util/SystemPreferences.pm b/Koha/Util/SystemPreferences.pm >new file mode 100644 >index 0000000..a57c98b >--- /dev/null >+++ b/Koha/Util/SystemPreferences.pm >@@ -0,0 +1,69 @@ >+package Koha::Util::SystemPreferences; >+ >+# Copyright 2018 Koha Development Team >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use parent qw( Exporter ); >+ >+our @EXPORT = qw( >+ get_yaml_pref_hash >+); >+ >+=head1 NAME >+ >+Koha::Util::SystemPreferences - utility class with System Preference routines >+ >+=head1 METHODS >+ >+=head2 get_yaml_pref_hash >+ >+Turn a pref defined via YAML as a hash >+ >+=cut >+ >+sub get_yaml_pref_hash { >+ my ( $pref ) = @_; >+ return if !defined( $pref ); >+ >+ my @lines = split /\n/, C4::Context->preference($pref)//''; >+ my $pref_as_hash; >+ foreach my $line (@lines){ >+ my ($field,$array) = split /:/, $line; >+ next if !$array; >+ $field =~ s/^\s*|\s*$//g; >+ $array =~ s/[ [\]\r]//g; >+ my @array = split /,/, $array; >+ @array = map { $_ eq '""' || $_ eq "''" ? '' : $_ } @array; >+ @array = map { $_ eq 'NULL' ? undef : $_ } @array; >+ $pref_as_hash->{$field} = \@array; >+ } >+ >+ return $pref_as_hash; >+} >+ >+1; >+__END__ >+ >+=head1 AUTHOR >+ >+Koha Development Team <http://koha-community.org/> >+ >+Nick Clemens <nick@bywatersolutions.com> >+ >+=cut >diff --git a/t/db_dependent/Koha/Util/SystemPreferences.t b/t/db_dependent/Koha/Util/SystemPreferences.t >new file mode 100644 >index 0000000..4ca7612 >--- /dev/null >+++ b/t/db_dependent/Koha/Util/SystemPreferences.t >@@ -0,0 +1,42 @@ >+# This file is part of Koha. >+# >+# Copyright 2018 Koha Development Team >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Test::More tests => 1; >+ >+use t::lib::Mocks; >+use Koha::Util::SystemPreferences; >+ >+subtest 'get_yaml_pref_hash' => sub { >+ >+ plan tests => 1; >+ >+ t::lib::Mocks::mock_preference('ItemDeniedRenewal',q{ >+ nulled: [NULL,''] >+ this: [just_that] >+ multi_this: [that,another] >+ }); >+ my $expected_hash = { >+ nulled => [undef,""], >+ this => ['just_that'], >+ multi_this => ['that','another'], >+ }; >+ my $got_hash = get_yaml_pref_hash('ItemDeniedRenewal'); >+ is_deeply($got_hash,$expected_hash,"Pref fetched and converted correctly"); >+ >+}; >+ >-- >2.1.4
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 15494
:
63700
|
63701
|
63702
|
63703
|
67886
|
67887
|
67888
|
67889
|
68146
|
68147
|
68148
|
68149
|
70295
|
70629
|
70630
|
70631
|
70632
|
71129
|
71130
|
71131
|
71132
|
71133
|
71134
|
71135
|
71136
|
71137
|
71138
|
79249
|
79250
|
79251
|
79252
|
79253
|
79254
|
79293
|
80327
|
80328
|
80329
|
80330
|
80331
|
80332
|
80333
|
81411
|
81412
|
81413
|
81414
|
81415
|
81416
|
81417