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

(-)a/C4/Circulation.pm (-12 / +2 lines)
Lines 57-62 use Koha::RefundLostItemFeeRule; Link Here
57
use Koha::RefundLostItemFeeRules;
57
use Koha::RefundLostItemFeeRules;
58
use Koha::Account::Lines;
58
use Koha::Account::Lines;
59
use Koha::Account::Offsets;
59
use Koha::Account::Offsets;
60
use Koha::Util::SystemPreferences;
60
use Carp;
61
use Carp;
61
use List::MoreUtils qw( uniq any );
62
use List::MoreUtils qw( uniq any );
62
use Scalar::Util qw( looks_like_number );
63
use Scalar::Util qw( looks_like_number );
Lines 4108-4125 sub _item_denied_renewal { Link Here
4108
    my $item = $params->{item};
4109
    my $item = $params->{item};
4109
    return unless $item;
4110
    return unless $item;
4110
4111
4111
    my @lines = split /\n/, C4::Context->preference('ItemsDeniedRenewal')//'';
4112
    my $denyingrules = get_yaml_pref_hash('ItemsDeniedRenewal');
4112
    my $denyingrules;
4113
    foreach my $line (@lines){
4114
        my ($field,$array) = split /:/, $line;
4115
        next if !$array;
4116
        $field =~ s/^\s*|\s*$//g;
4117
        $array =~ s/[ [\]\r]//g;
4118
        my @array = split /,/, $array;
4119
        @array = map { $_ eq '""' || $_ eq "''" ? '' : $_ } @array;
4120
        @array = map { $_ eq 'NULL' ? undef : $_ } @array;
4121
        $denyingrules->{$field} = \@array;
4122
    }
4123
    return unless $denyingrules;
4113
    return unless $denyingrules;
4124
    foreach my $field (keys %$denyingrules) {
4114
    foreach my $field (keys %$denyingrules) {
4125
        my $val = $item->{$field};
4115
        my $val = $item->{$field};
(-)a/Koha/Util/SystemPreferences.pm (+69 lines)
Line 0 Link Here
1
package Koha::Util::SystemPreferences;
2
3
# Copyright 2018 Koha Development Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use parent qw( Exporter );
23
24
our @EXPORT = qw(
25
  get_yaml_pref_hash
26
);
27
28
=head1 NAME
29
30
Koha::Util::SystemPreferences - utility class with System Preference routines
31
32
=head1 METHODS
33
34
=head2 get_yaml_pref_hash
35
36
Turn a pref defined via YAML as a hash
37
38
=cut
39
40
sub get_yaml_pref_hash {
41
    my ( $pref ) = @_;
42
    return if !defined( $pref );
43
44
    my @lines = split /\n/, C4::Context->preference($pref)//'';
45
    my $pref_as_hash;
46
    foreach my $line (@lines){
47
        my ($field,$array) = split /:/, $line;
48
        next if !$array;
49
        $field =~ s/^\s*|\s*$//g;
50
        $array =~ s/[ [\]\r]//g;
51
        my @array = split /,/, $array;
52
        @array = map { $_ eq '""' || $_ eq "''" ? '' : $_ } @array;
53
        @array = map { $_ eq 'NULL' ? undef : $_ } @array;
54
        $pref_as_hash->{$field} = \@array;
55
    }
56
57
    return $pref_as_hash;
58
}
59
60
1;
61
__END__
62
63
=head1 AUTHOR
64
65
Koha Development Team <http://koha-community.org/>
66
67
Nick Clemens <nick@bywatersolutions.com>
68
69
=cut
(-)a/t/db_dependent/Koha/Util/SystemPreferences.t (-1 / +42 lines)
Line 0 Link Here
0
- 
1
# This file is part of Koha.
2
#
3
# Copyright 2018 Koha Development Team
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but 
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
use Test::More tests => 1;
20
21
use t::lib::Mocks;
22
use Koha::Util::SystemPreferences;
23
24
subtest 'get_yaml_pref_hash' => sub {
25
26
    plan tests => 1;
27
28
    t::lib::Mocks::mock_preference('ItemDeniedRenewal',q{
29
        nulled: [NULL,'']
30
        this: [just_that]
31
        multi_this: [that,another]
32
    });
33
    my $expected_hash = {
34
        nulled => [undef,""],
35
        this     => ['just_that'],
36
        multi_this => ['that','another'],
37
    };
38
    my $got_hash = get_yaml_pref_hash('ItemDeniedRenewal');
39
    is_deeply($got_hash,$expected_hash,"Pref fetched and converted correctly");
40
41
};
42

Return to bug 15494