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

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 2137-2143 sub AddReturn { Link Here
2137
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2137
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2138
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2138
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2139
2139
2140
    my $update_loc_rules = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckin')->get_yaml_pref_hash();
2140
    my $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
2141
    map { $update_loc_rules->{$_} = $update_loc_rules->{$_}[0] } keys %$update_loc_rules; #We can only move to one location so we flatten the arrays
2141
    map { $update_loc_rules->{$_} = $update_loc_rules->{$_}[0] } keys %$update_loc_rules; #We can only move to one location so we flatten the arrays
2142
    if ($update_loc_rules) {
2142
    if ($update_loc_rules) {
2143
        if (defined $update_loc_rules->{_ALL_}) {
2143
        if (defined $update_loc_rules->{_ALL_}) {
(-)a/Koha/Config/SysPref.pm (-28 lines)
Lines 36-69 Koha::Config::SysPref - Koha System Preference Object class Link Here
36
36
37
=cut
37
=cut
38
38
39
=head3 get_yaml_pref_hash
40
41
Turn a pref defined via YAML as a hash
42
43
=cut
44
45
sub get_yaml_pref_hash {
46
    my ( $self ) = @_;
47
    return if !defined( $self );
48
49
    # We want to use C4::Context->preference in any cases
50
    # It's cached, and mock_preference still works from tests
51
    my @lines = split /\n/, C4::Context->preference($self->variable) // '';
52
    my $pref_as_hash;
53
    foreach my $line (@lines){
54
        my ($field,$array) = split /:/, $line;
55
        next if !$array;
56
        $field =~ s/^\s*|\s*$//g;
57
        $array =~ s/[ [\]\r]//g;
58
        my @array = split /,/, $array;
59
        @array = map { $_ eq '""' || $_ eq "''" ? '' : $_ } @array;
60
        @array = map { $_ eq 'NULL' ? undef : $_ } @array;
61
        $pref_as_hash->{$field} = \@array;
62
    }
63
64
    return $pref_as_hash;
65
}
66
67
39
68
=head3 store
40
=head3 store
69
41
(-)a/Koha/Item.pm (-2 / +1 lines)
Lines 2065-2072 rules set in the ItemsDeniedRenewal system preference. Link Here
2065
2065
2066
sub is_denied_renewal {
2066
sub is_denied_renewal {
2067
    my ( $self ) = @_;
2067
    my ( $self ) = @_;
2068
2068
    my $denyingrules = C4::Context->yaml_preference('ItemsDeniedRenewal');
2069
    my $denyingrules = Koha::Config::SysPrefs->find('ItemsDeniedRenewal')->get_yaml_pref_hash();
2070
    return 0 unless $denyingrules;
2069
    return 0 unless $denyingrules;
2071
    foreach my $field (keys %$denyingrules) {
2070
    foreach my $field (keys %$denyingrules) {
2072
        my $val = $self->$field;
2071
        my $val = $self->$field;
(-)a/t/db_dependent/Koha/Config/SysPrefs.t (-23 / +1 lines)
Lines 16-22 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Test::More tests => 4;
19
use Test::More tests => 3;
20
20
21
use t::lib::Mocks;
21
use t::lib::Mocks;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
Lines 43-67 is( $retrieved_pref->value, $new_pref->value, 'Find a pref by variable should re Link Here
43
$retrieved_pref->delete;
43
$retrieved_pref->delete;
44
is( Koha::Config::SysPrefs->search->count, $nb_of_prefs, 'Delete should have deleted the pref' );
44
is( Koha::Config::SysPrefs->search->count, $nb_of_prefs, 'Delete should have deleted the pref' );
45
45
46
subtest 'get_yaml_pref_hash' => sub {
47
48
    plan tests => 1;
49
50
    my $the_pref = Koha::Config::SysPrefs->find({variable=>'ItemsDeniedRenewal'});
51
    t::lib::Mocks::mock_preference('ItemsDeniedRenewal', q{
52
        nulled: [NULL,'']
53
        this: [just_that]
54
        multi_this: [that,another]
55
    });
56
57
    my $expected_hash = {
58
        nulled => [undef,""],
59
        this     => ['just_that'],
60
        multi_this => ['that','another'],
61
    };
62
    my $got_hash = $the_pref->get_yaml_pref_hash();
63
    is_deeply($got_hash,$expected_hash,"Pref fetched and converted correctly");
64
65
};
66
67
$schema->storage->txn_rollback;
46
$schema->storage->txn_rollback;
68
- 

Return to bug 32478