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

(-)a/Koha/Authority/ControlledIndicators.pm (-18 / +4 lines)
Lines 20-27 package Koha::Authority::ControlledIndicators; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
use C4::Context;
21
use C4::Context;
22
22
23
our $cached_indicators;
24
25
=head1 NAME
23
=head1 NAME
26
24
27
Koha::Authority::ControlledIndicators - Obtain biblio indicators, controlled by authority record
25
Koha::Authority::ControlledIndicators - Obtain biblio indicators, controlled by authority record
Lines 39-45 Koha::Authority::ControlledIndicators - Obtain biblio indicators, controlled by Link Here
39
sub new {
37
sub new {
40
    my ( $class, $params ) = @_;
38
    my ( $class, $params ) = @_;
41
    $params = {} if ref($params) ne 'HASH';
39
    $params = {} if ref($params) ne 'HASH';
42
    $cached_indicators = undef;
43
    return bless $params, $class;
40
    return bless $params, $class;
44
}
41
}
45
42
Lines 66-76 sub get { Link Here
66
    $flavour = uc($flavour);
63
    $flavour = uc($flavour);
67
    $flavour = 'UNIMARC' if $flavour eq 'UNIMARCAUTH';
64
    $flavour = 'UNIMARC' if $flavour eq 'UNIMARCAUTH';
68
65
69
    $cached_indicators //= _load_pref();
66
    $self->{_parsed} //= _load_pref();
70
    my $result = {};
67
    my $result = {};
71
    return $result if !exists $cached_indicators->{$flavour};
68
    return $result if !exists $self->{_parsed}->{$flavour};
72
    my $rule = $cached_indicators->{$flavour}->{$tag} //
69
    my $rule = $self->{_parsed}->{$flavour}->{$tag} //
73
        $cached_indicators->{$flavour}->{'*'} //
70
        $self->{_parsed}->{$flavour}->{'*'} //
74
        {};
71
        {};
75
    my $report_fld = $record ? $record->field( $report_tag ) : undef;
72
    my $report_fld = $record ? $record->field( $report_tag ) : undef;
76
73
Lines 146-162 sub _thesaurus_info { Link Here
146
    return ( $ind, $sub2 );
143
    return ( $ind, $sub2 );
147
}
144
}
148
145
149
=head3 clear
150
151
    Clear internal cache.
152
153
=cut
154
155
sub clear {
156
    my ( $self, $params ) = @_;
157
    $cached_indicators = undef;
158
}
159
160
=head1 AUTHOR
146
=head1 AUTHOR
161
147
162
    Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands
148
    Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands
(-)a/t/Koha/Authority/ControlledIndicators.t (-20 / +1 lines)
Lines 10-16 use t::lib::Mocks; Link Here
10
use Koha::Authority::ControlledIndicators;
10
use Koha::Authority::ControlledIndicators;
11
11
12
subtest "Simple tests" => sub {
12
subtest "Simple tests" => sub {
13
    plan tests => 10;
13
    plan tests => 8;
14
14
15
    t::lib::Mocks::mock_preference('AuthorityControlledIndicators', q|
15
    t::lib::Mocks::mock_preference('AuthorityControlledIndicators', q|
16
marc21,600,ind1:auth1,ind2:x
16
marc21,600,ind1:auth1,ind2:x
Lines 52-75 marc21,800,ind1:, Link Here
52
    });
52
    });
53
    is( $res->{ind1}, '', 'ind1: clears 1st indicator' );
53
    is( $res->{ind1}, '', 'ind1: clears 1st indicator' );
54
    is( exists $res->{ind2}, '', 'Check if 2nd indicator key does not exist' );
54
    is( exists $res->{ind2}, '', 'Check if 2nd indicator key does not exist' );
55
56
    # Test caching
57
    t::lib::Mocks::mock_preference('AuthorityControlledIndicators', q{} );
58
    $res = $oInd->get({
59
        flavour => "MARC21",
60
        report_tag  => '100',
61
        auth_record => $record,
62
        biblio_tag  => '700',
63
    });
64
    is( $res->{ind1}, '4', 'Cache not cleared yet' );
65
    $oInd->clear;
66
    $res = $oInd->get({
67
        flavour => "MARC21",
68
        report_tag  => '100',
69
        auth_record => $record,
70
        biblio_tag  => '700',
71
    });
72
    is_deeply( $res, {}, 'Cache cleared' );
73
};
55
};
74
56
75
subtest "Tests for sub _thesaurus_info" => sub {
57
subtest "Tests for sub _thesaurus_info" => sub {
76
- 

Return to bug 14769