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

(-)a/C4/Biblio.pm (-49 / +25 lines)
Lines 111-116 use Koha::SearchEngine::Indexer; Link Here
111
use Koha::SimpleMARC;
111
use Koha::SimpleMARC;
112
use Koha::Libraries;
112
use Koha::Libraries;
113
use Koha::Util::MARC;
113
use Koha::Util::MARC;
114
use Koha::AuthorisedValues;
114
115
115
=head1 NAME
116
=head1 NAME
116
117
Lines 1498-1550 sub GetAuthorisedValueDesc { Link Here
1498
1499
1499
    return q{} unless defined($value);
1500
    return q{} unless defined($value);
1500
1501
1501
    my $cache = Koha::Caches->get_instance();
1502
    my $cache_key;
1503
    if ( !$category ) {
1502
    if ( !$category ) {
1504
1503
1505
        return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1504
        return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1506
1505
1507
        #---- branch
1506
        #---- branch
1508
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1507
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1509
            $cache_key = "libraries:name";
1508
            my $libraries = {
1510
            my $libraries = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1509
                map { $_->branchcode => $_->branchname } Koha::Libraries->search(
1511
            if ( !$libraries ) {
1510
                    {},
1512
                $libraries = {
1511
                    { columns => [ 'branchcode', 'branchname' ] }
1513
                    map { $_->branchcode => $_->branchname } Koha::Libraries->search(
1512
                )->as_list
1514
                        {},
1513
            };
1515
                        { columns => [ 'branchcode', 'branchname' ] }
1516
                    )->as_list
1517
                };
1518
                $cache->set_in_cache( $cache_key, $libraries );
1519
            }
1520
            return $libraries->{$value};
1514
            return $libraries->{$value};
1521
        }
1515
        }
1522
1516
1523
        #---- itemtypes
1517
        #---- itemtypes
1524
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1518
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1525
            my $lang = C4::Languages::getlanguage;
1519
            foreach my $item_type ( Koha::ItemTypes->search()->as_list ) {
1526
            $lang //= 'en';
1520
                if ( $item_type->itemtype eq $value ) {
1527
            $cache_key = 'itemtype:description:' . $lang;
1521
                    return $item_type->translated_description;
1528
            my $itypes = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1522
                }
1529
            if ( !$itypes ) {
1530
                $itypes = { map { $_->itemtype => $_->translated_description } Koha::ItemTypes->search()->as_list };
1531
                $cache->set_in_cache( $cache_key, $itypes );
1532
            }
1523
            }
1533
            return $itypes->{$value};
1534
        }
1524
        }
1535
1525
1536
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) {
1526
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) {
1537
            $cache_key = "cn_sources:description";
1527
            my $cn_sources = {
1538
            my $cn_sources = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1528
                map { $_->cn_source => $_->description } Koha::ClassSources->search(
1539
            if ( !$cn_sources ) {
1529
                    {},
1540
                $cn_sources = {
1530
                    { columns => [ 'cn_source', 'description' ] }
1541
                    map { $_->cn_source => $_->description } Koha::ClassSources->search(
1531
                )->as_list
1542
                        {},
1532
            };
1543
                        { columns => [ 'cn_source', 'description' ] }
1544
                    )->as_list
1545
                };
1546
                $cache->set_in_cache( $cache_key, $cn_sources );
1547
            }
1548
            return $cn_sources->{$value};
1533
            return $cn_sources->{$value};
1549
        }
1534
        }
1550
1535
Lines 1552-1574 sub GetAuthorisedValueDesc { Link Here
1552
        $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1537
        $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1553
    }
1538
    }
1554
1539
1555
    my $dbh = C4::Context->dbh;
1540
    if ( $category ) {
1556
    if ( $category ne "" ) {
1541
        my $description = Koha::AuthorisedValues->get_description_by_category_and_authorised_value(
1557
        $cache_key = "AV_descriptions:" . $category;
1542
            {
1558
        my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1543
                category         => $category,
1559
        if ( !$av_descriptions ) {
1544
                authorised_value => $value
1560
            $av_descriptions = {
1545
            }
1561
                map { $_->authorised_value => { lib => $_->lib, lib_opac => $_->lib_opac } }
1546
        );
1562
                    Koha::AuthorisedValues->search(
1547
        return $opac ? $description->{'opac_description'} : $description->{'lib'};
1563
                    { category => $category },
1564
                    { columns  => [ 'authorised_value', 'lib_opac', 'lib' ] }
1565
                    )->as_list
1566
            };
1567
            $cache->set_in_cache( $cache_key, $av_descriptions );
1568
        }
1569
        return ( $opac && $av_descriptions->{$value}->{'lib_opac'} )
1570
            ? $av_descriptions->{$value}->{'lib_opac'}
1571
            : $av_descriptions->{$value}->{'lib'};
1572
    } else {
1548
    } else {
1573
        return $value;    # if nothing is found return the original value
1549
        return $value;    # if nothing is found return the original value
1574
    }
1550
    }
(-)a/C4/Serials.pm (-6 / +22 lines)
Lines 75-80 use C4::Context; Link Here
75
use C4::Log                qw( logaction );                  # logaction
75
use C4::Log                qw( logaction );                  # logaction
76
use C4::Serials::Frequency qw( GetSubscriptionFrequency );
76
use C4::Serials::Frequency qw( GetSubscriptionFrequency );
77
use C4::Serials::Numberpattern;
77
use C4::Serials::Numberpattern;
78
use Koha::AdditionalFields;
78
use Koha::AdditionalFieldValues;
79
use Koha::AdditionalFieldValues;
79
use Koha::Biblios;
80
use Koha::Biblios;
80
use Koha::DateUtils qw( dt_from_string );
81
use Koha::DateUtils qw( dt_from_string );
Lines 639-651 sub SearchSubscriptions { Link Here
639
    if ( $params->{results_limit} && $total_results > $params->{results_limit} ) {
640
    if ( $params->{results_limit} && $total_results > $params->{results_limit} ) {
640
        $results = [ splice( @{$results}, 0, $params->{results_limit} ) ];
641
        $results = [ splice( @{$results}, 0, $params->{results_limit} ) ];
641
    }
642
    }
643
    my @additional_field_ids = map { $_->id  } Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list;
644
    if (@additional_field_ids) {
645
        my %subscriptions_by_id = map { $_->{subscriptionid } => $_ } @{$results};
646
        my $field_values_rs = Koha::AdditionalFieldValues->search(
647
            {
648
                field_id => { -in => \@additional_field_ids },
649
                record_id => { -in => [ keys %subscriptions_by_id ] }
650
            }
651
        );
652
        while (my $field_value = $field_values_rs->next) {
653
            $subscriptions_by_id{$field_value->record_id}->{additional_field_values}->{$field_value->field_id} = $field_value->value;
654
        }
655
    }
656
    else {
657
        for my $subscription ( @{$results} ) {
658
            $subscription->{additional_field_values} = {};
659
        }
660
    }
642
661
643
    for my $subscription (@$results) {
662
    for my $subscription ( @{$results} ) {
644
        $subscription->{cannotedit}    = not can_edit_subscription($subscription);
663
        $subscription->{cannotedit} = not can_edit_subscription( $subscription );
645
        $subscription->{cannotdisplay} = not can_show_subscription($subscription);
664
        $subscription->{cannotdisplay} = not can_show_subscription( $subscription );
646
647
        my $subscription_object = Koha::Subscriptions->find( $subscription->{subscriptionid} );
648
        $subscription->{additional_field_values} = $subscription_object->get_additional_field_values_for_template;
649
    }
665
    }
650
666
651
    return wantarray ? @{$results} : { results => $results, total => $total_results };
667
    return wantarray ? @{$results} : { results => $results, total => $total_results };
(-)a/Koha/AuthorisedValue.pm (-40 / +2 lines)
Lines 25-37 use Koha::Exceptions; Link Here
25
use Koha::Object;
25
use Koha::Object;
26
use Koha::Object::Limit::Library;
26
use Koha::Object::Limit::Library;
27
27
28
use base qw(Koha::Object Koha::Object::Limit::Library);
28
use base qw(Koha::Object::CachedExpiration Koha::Object::Limit::Library);
29
29
30
use constant NUM_PATTERN    => q{^(-[1-9][0-9]*|0|[1-9][0-9]*)$};
30
use constant NUM_PATTERN    => q{^(-[1-9][0-9]*|0|[1-9][0-9]*)$};
31
use constant NUM_PATTERN_JS => q{(-[1-9][0-9]*|0|[1-9][0-9]*)};     # ^ and $ removed
31
use constant NUM_PATTERN_JS => q{(-[1-9][0-9]*|0|[1-9][0-9]*)};     # ^ and $ removed
32
32
33
my $cache = Koha::Caches->get_instance();
34
35
=head1 NAME
33
=head1 NAME
36
34
37
Koha::AuthorisedValue - Koha Authorised value Object class
35
Koha::AuthorisedValue - Koha Authorised value Object class
Lines 50-93 AuthorisedValue specific store to ensure relevant caches are flushed on change Link Here
50
48
51
sub store {
49
sub store {
52
    my ($self) = @_;
50
    my ($self) = @_;
53
54
    my $flush = 0;
55
56
    if ( !$self->in_storage ) {
57
        $flush = 1;
58
    } else {
59
        my %updated_columns = $self->_result->get_dirty_columns;
60
61
        if (   exists $updated_columns{lib}
62
            or exists $updated_columns{lib_opac} )
63
        {
64
            $flush = 1;
65
        }
66
    }
67
68
    $self->_check_is_integer_only;
51
    $self->_check_is_integer_only;
69
52
    return $self->SUPER::store;
70
    $self = $self->SUPER::store;
71
72
    if ($flush) {
73
        my $key = "AV_descriptions:" . $self->category;
74
        $cache->clear_from_cache($key);
75
    }
76
77
    return $self;
78
}
79
80
=head2 delete
81
82
AuthorisedValue specific C<delete> to clear relevant caches on delete.
83
84
=cut
85
86
sub delete {
87
    my $self = shift @_;
88
    my $key  = "AV_descriptions:" . $self->category;
89
    $cache->clear_from_cache($key);
90
    $self->SUPER::delete(@_);
91
}
53
}
92
54
93
=head3 opac_description
55
=head3 opac_description
(-)a/Koha/AuthorisedValues.pm (-46 / +34 lines)
Lines 23-31 use Koha::Database; Link Here
23
23
24
use Koha::AuthorisedValue;
24
use Koha::AuthorisedValue;
25
use Koha::MarcSubfieldStructures;
25
use Koha::MarcSubfieldStructures;
26
use Koha::Cache::Memory::Lite;
27
26
28
use base qw(Koha::Objects Koha::Objects::Limit::Library);
27
use base qw(Koha::Objects::Cached Koha::Objects::Limit::Library);
29
28
30
=head1 NAME
29
=head1 NAME
31
30
Lines 115-121 sub find_by_koha_field { Link Here
115
            distinct => 1,
114
            distinct => 1,
116
        }
115
        }
117
    );
116
    );
118
    return $av->count ? $av->next : undef;
117
    return $av->next;
119
}
118
}
120
119
121
=head2 get_description_by_koha_field
120
=head2 get_description_by_koha_field
Lines 126-150 Missing POD for get_description_by_koha_field. Link Here
126
125
127
sub get_description_by_koha_field {
126
sub get_description_by_koha_field {
128
    my ( $self, $params ) = @_;
127
    my ( $self, $params ) = @_;
129
    my $frameworkcode    = $params->{frameworkcode} || '';
128
    $params->{frameworkcode} //= '';
130
    my $kohafield        = $params->{kohafield};
131
    my $authorised_value = $params->{authorised_value};
132
129
133
    return {} unless defined $authorised_value;
130
    return {} unless defined $params->{authorised_value};
134
135
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
136
    my $cache_key    = "AV_descriptions:$frameworkcode:$kohafield:$authorised_value";
137
    my $cached       = $memory_cache->get_from_cache($cache_key);
138
    return $cached if $cached;
139
131
140
    my $av = $self->find_by_koha_field($params);
132
    my $av = $self->find_by_koha_field($params);
141
    if ( !defined $av ) {
133
    return defined $av ? { lib => $av->lib, opac_description => $av->opac_description } : {};
142
        $memory_cache->set_in_cache( $cache_key, {} );
143
        return {};
144
    }
145
    my $descriptions = { lib => $av->lib, opac_description => $av->opac_description };
146
    $memory_cache->set_in_cache( $cache_key, $descriptions );
147
    return $descriptions;
148
}
134
}
149
135
150
=head2 get_descriptions_by_koha_field
136
=head2 get_descriptions_by_koha_field
Lines 155-178 Missing POD for get_descriptions_by_koha_field. Link Here
155
141
156
sub get_descriptions_by_koha_field {
142
sub get_descriptions_by_koha_field {
157
    my ( $self, $params ) = @_;
143
    my ( $self, $params ) = @_;
158
    my $frameworkcode = $params->{frameworkcode} || '';
144
    $params->{frameworkcode} //= '';
159
    my $kohafield     = $params->{kohafield};
160
161
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
162
    my $cache_key    = "AV_descriptions:$frameworkcode:$kohafield";
163
    my $cached       = $memory_cache->get_from_cache($cache_key);
164
    return @$cached if $cached;
165
145
166
    my @avs          = $self->search_by_koha_field($params)->as_list;
146
    my @avs          = $self->search_by_koha_field($params)->as_list;
167
    my @descriptions = map {
147
    my $descriptions = [
148
        map {
149
            {
150
                authorised_value => $_->authorised_value,
151
                lib              => $_->lib,
152
                opac_description => $_->opac_description
153
            }
154
        } @avs
155
    ];
156
    return @{$descriptions};
157
}
158
159
sub get_description_by_category_and_authorised_value {
160
    my ( $self, $params ) = @_;
161
    return unless defined $params->{category} and defined $params->{authorised_value};
162
163
    my $av = $self->search(
168
        {
164
        {
169
            authorised_value => $_->authorised_value,
165
            category         => $params->{category},
170
            lib              => $_->lib,
166
            authorised_value => $params->{authorised_value},
171
            opac_description => $_->opac_description
172
        }
167
        }
173
    } @avs;
168
    )->next;
174
    $memory_cache->set_in_cache( $cache_key, \@descriptions );
169
175
    return @descriptions;
170
    return $av
171
        ? {
172
        lib              => $av->lib,
173
        opac_description => $av->opac_description
174
        }
175
        : {};
176
}
176
}
177
177
178
=head3 get_descriptions_by_marc_field
178
=head3 get_descriptions_by_marc_field
Lines 183-209 sub get_descriptions_by_koha_field { Link Here
183
183
184
sub get_descriptions_by_marc_field {
184
sub get_descriptions_by_marc_field {
185
    my ( $self, $params ) = @_;
185
    my ( $self, $params ) = @_;
186
    my $frameworkcode = $params->{frameworkcode} || '';
186
    $params->{frameworkcode} //= '';
187
    my $tagfield      = $params->{tagfield};
188
    my $tagsubfield   = $params->{tagsubfield};
189
187
190
    return {} unless defined $params->{tagfield};
188
    return {} unless defined $params->{tagfield};
191
189
192
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
193
    my $cache_key    = "AV_descriptions_by_MARC:$frameworkcode:$tagfield";
194
    if ($tagsubfield) {
195
        $cache_key .= ":$tagsubfield";
196
    }
197
198
    my $cached = $memory_cache->get_from_cache($cache_key);
199
    return $cached if $cached;
200
201
    my $descriptions = {};
190
    my $descriptions = {};
202
    my @avs          = $self->search_by_marc_field($params)->as_list;
191
    my @avs          = $self->search_by_marc_field($params)->as_list;
203
    foreach my $av (@avs) {
192
    foreach my $av (@avs) {
204
        $descriptions->{ $av->authorised_value } = $av->lib;
193
        $descriptions->{ $av->authorised_value } = $av->lib;
205
    }
194
    }
206
    $memory_cache->set_in_cache( $cache_key, $descriptions );
207
    return $descriptions;
195
    return $descriptions;
208
}
196
}
209
197
(-)a/Koha/ClassSource.pm (-43 / +1 lines)
Lines 17-28 package Koha::ClassSource; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Caches;
21
use Koha::Database;
20
use Koha::Database;
22
21
23
use base qw(Koha::Object);
22
use base qw(Koha::Object::CachedExpiration);
24
25
my $cache = Koha::Caches->get_instance();
26
23
27
=head1 NAME
24
=head1 NAME
28
25
Lines 32-76 Koha::ClassSource - Koha Classfication Source Object class Link Here
32
29
33
=head2 Class Methods
30
=head2 Class Methods
34
31
35
=head3 store
36
37
ClassSource specific store to ensure relevant caches are flushed on change
38
39
=cut
40
41
sub store {
42
    my ($self) = @_;
43
44
    my $flush = 0;
45
46
    if ( !$self->in_storage ) {
47
        $flush = 1;
48
    } else {
49
        my $self_from_storage = $self->get_from_storage;
50
        $flush = 1 if ( $self_from_storage->description ne $self->description );
51
    }
52
53
    $self = $self->SUPER::store;
54
55
    if ($flush) {
56
        $cache->clear_from_cache('cn_sources:description');
57
    }
58
59
    return $self;
60
}
61
62
=head2 delete
63
64
ClassSource specific C<delete> to clear relevant caches on delete.
65
66
=cut
67
68
sub delete {
69
    my $self = shift @_;
70
    $cache->clear_from_cache('cn_sources:description');
71
    $self->SUPER::delete(@_);
72
}
73
74
=head3 _type
32
=head3 _type
75
33
76
Returns name of corresponding DBIC resultset
34
Returns name of corresponding DBIC resultset
(-)a/Koha/ClassSources.pm (-1 / +1 lines)
Lines 21-27 use Koha::Database; Link Here
21
21
22
use Koha::ClassSource;
22
use Koha::ClassSource;
23
23
24
use base qw(Koha::Objects);
24
use base qw(Koha::Objects::Cached);
25
25
26
=head1 NAME
26
=head1 NAME
27
27
(-)a/Koha/Library.pm (-42 lines)
Lines 21-27 use Modern::Perl; Link Here
21
21
22
use C4::Context;
22
use C4::Context;
23
23
24
use Koha::Caches;
25
use Koha::Database;
24
use Koha::Database;
26
use Koha::Desks;
25
use Koha::Desks;
27
use Koha::StockRotationStages;
26
use Koha::StockRotationStages;
Lines 30-37 use Koha::Library::Hours; Link Here
30
29
31
use base qw(Koha::Object::Mixin::AdditionalFields Koha::Object::CachedExpiration);
30
use base qw(Koha::Object::Mixin::AdditionalFields Koha::Object::CachedExpiration);
32
31
33
my $cache = Koha::Caches->get_instance();
34
35
=head1 NAME
32
=head1 NAME
36
33
37
Koha::Library - Koha Library Object class
34
Koha::Library - Koha Library Object class
Lines 40-84 Koha::Library - Koha Library Object class Link Here
40
37
41
=head2 Class methods
38
=head2 Class methods
42
39
43
=head3 store
44
45
Library specific store to ensure relevant caches are flushed on change
46
47
=cut
48
49
sub store {
50
    my ($self) = @_;
51
52
    my $flush = 0;
53
54
    if ( !$self->in_storage ) {
55
        $flush = 1;
56
    } else {
57
        my $self_from_storage = $self->get_from_storage;
58
        $flush = 1 if ( $self_from_storage->branchname ne $self->branchname );
59
    }
60
61
    $self = $self->SUPER::store;
62
63
    if ($flush) {
64
        $cache->clear_from_cache('libraries:name');
65
    }
66
67
    return $self;
68
}
69
70
=head2 delete
71
72
Library specific C<delete> to clear relevant caches on delete.
73
74
=cut
75
76
sub delete {
77
    my $self = shift @_;
78
    $cache->clear_from_cache('libraries:name');
79
    $self->SUPER::delete(@_);
80
}
81
82
=head3 stockrotationstages
40
=head3 stockrotationstages
83
41
84
  my $stages = Koha::Library->stockrotationstages;
42
  my $stages = Koha::Library->stockrotationstages;
(-)a/Koha/Localization.pm (-36 lines)
Lines 21-29 use Koha::Database; Link Here
21
21
22
use base qw(Koha::Object);
22
use base qw(Koha::Object);
23
23
24
use Koha::Caches;
25
my $cache = Koha::Caches->get_instance();
26
27
=head1 NAME
24
=head1 NAME
28
25
29
Koha::Localization - Koha Localization type Object class
26
Koha::Localization - Koha Localization type Object class
Lines 34-72 Koha::Localization - Koha Localization type Object class Link Here
34
31
35
=cut
32
=cut
36
33
37
=head3 store
38
39
Localization specific store to ensure relevant caches are flushed on change
40
41
=cut
42
43
sub store {
44
    my ($self) = @_;
45
    $self = $self->SUPER::store;
46
47
    if ( $self->entity eq 'itemtypes' ) {
48
        my $key = "itemtype:description:" . $self->lang;
49
        $cache->clear_from_cache($key);
50
    }
51
52
    return $self;
53
}
54
55
=head2 delete
56
57
Localization specific C<delete> to clear relevant caches on delete.
58
59
=cut
60
61
sub delete {
62
    my $self = shift @_;
63
    if ( $self->entity eq 'itemtypes' ) {
64
        my $key = "itemtype:description:" . $self->lang;
65
        $cache->clear_from_cache($key);
66
    }
67
    $self->SUPER::delete(@_);
68
}
69
70
sub _type {
34
sub _type {
71
    return 'Localization';
35
    return 'Localization';
72
}
36
}
(-)a/Koha/Objects/Limit/Library.pm (+2 lines)
Lines 57-62 sub search_with_library_limits { Link Here
57
    $library_id //= C4::Context->userenv->{branch}
57
    $library_id //= C4::Context->userenv->{branch}
58
        if defined C4::Context->userenv;
58
        if defined C4::Context->userenv;
59
59
60
    $attributes->{cache} = 0;
61
60
    return $self->search( $params, $attributes ) unless $library_id;
62
    return $self->search( $params, $attributes ) unless $library_id;
61
63
62
    my $library_limits       = $self->object_class()->_library_limits;
64
    my $library_limits       = $self->object_class()->_library_limits;
(-)a/Koha/Template/Plugin/AuthorisedValues.pm (-9 / +15 lines)
Lines 26-43 use Koha::AuthorisedValues; Link Here
26
26
27
sub GetByCode {
27
sub GetByCode {
28
    my ( $self, $category, $code, $opac ) = @_;
28
    my ( $self, $category, $code, $opac ) = @_;
29
    my $av = Koha::AuthorisedValues->search( { category => $category, authorised_value => $code } );
29
    my $av = Koha::AuthorisedValues->get_description_by_category_and_authorised_value(
30
    return
30
        {
31
          $av->count
31
            category => $category,
32
        ? $opac
32
            authorised_value => $code
33
            ? $av->next->opac_description
33
        }
34
            : $av->next->lib
34
    );
35
        : $code;
35
36
    my $description;
37
    if ($av) {
38
        $description = $opac ? $av->{opac_description} : $av->{lib};
39
    }
40
41
    return $description || $code;
36
}
42
}
37
43
38
sub Get {
44
sub Get {
39
    my ( $self, $category, $selected, $opac ) = @_;
45
    my ( $self, $category, $opac ) = @_;
40
    return GetAuthorisedValues( $category, $selected, $opac );
46
    return GetAuthorisedValues( $category, $opac );
41
}
47
}
42
48
43
sub GetAuthValueDropbox {
49
sub GetAuthValueDropbox {
(-)a/t/db_dependent/AuthorisedValues.t (-10 / +33 lines)
Lines 154-160 is_deeply( Link Here
154
);
154
);
155
155
156
subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_values' => sub {
156
subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_values' => sub {
157
    plan tests => 7;
157
    plan tests => 8;
158
158
159
    my $test_cat = Koha::AuthorisedValueCategories->find('TEST');
159
    my $test_cat = Koha::AuthorisedValueCategories->find('TEST');
160
    $test_cat->delete if $test_cat;
160
    $test_cat->delete if $test_cat;
Lines 301-306 subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v Link Here
301
    subtest 'get_descriptions_by_marc_field' => sub {
301
    subtest 'get_descriptions_by_marc_field' => sub {
302
        plan tests => 4;
302
        plan tests => 4;
303
303
304
        Koha::AuthorisedValues->_objects_cache_clear();
304
        my $control_descriptions =
305
        my $control_descriptions =
305
            Koha::AuthorisedValues->get_descriptions_by_marc_field( { frameworkcode => '', tagfield => '003', } );
306
            Koha::AuthorisedValues->get_descriptions_by_marc_field( { frameworkcode => '', tagfield => '003', } );
306
        is_deeply(
307
        is_deeply(
Lines 311-328 subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v Link Here
311
            },
312
            },
312
        );
313
        );
313
314
314
        my $control_descriptions_cached =
315
        # Trigger cache
315
            Koha::AuthorisedValues->get_descriptions_by_marc_field( { frameworkcode => '', tagfield => '003', } );
316
        Koha::AuthorisedValues->get_descriptions_by_marc_field( { frameworkcode => '', tagfield => '003', } );
316
317
        my $bucket = Koha::AuthorisedValues->_objects_cache_bucket('args');
317
        is(
318
        is(
318
            "$control_descriptions", "$control_descriptions_cached",
319
            scalar( keys %{$control_descriptions} ), ( values %{$bucket} )[0]->count,
319
            "Same memory address used proves cached control desc data"
320
            "Same number of cached descriptions as control descriptions"
320
        );
321
        );
321
322
322
        my $descriptions = Koha::AuthorisedValues->get_descriptions_by_marc_field(
323
        Koha::AuthorisedValues->_objects_cache_clear();
324
        $control_descriptions = Koha::AuthorisedValues->get_descriptions_by_marc_field(
323
            { frameworkcode => '', tagfield => '952', tagsubfield => 'c' } );
325
            { frameworkcode => '', tagfield => '952', tagsubfield => 'c' } );
324
        is_deeply(
326
        is_deeply(
325
            $descriptions,
327
            $control_descriptions,
326
            {
328
            {
327
                'location_1' => 'location_1',
329
                'location_1' => 'location_1',
328
                'location_2' => 'location_2',
330
                'location_2' => 'location_2',
Lines 330-338 subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v Link Here
330
            },
332
            },
331
        );
333
        );
332
334
333
        my $descriptions_cached = Koha::AuthorisedValues->get_descriptions_by_marc_field(
335
        Koha::AuthorisedValues->get_descriptions_by_marc_field(
334
            { frameworkcode => '', tagfield => '952', tagsubfield => 'c' } );
336
            { frameworkcode => '', tagfield => '952', tagsubfield => 'c' } );
335
        is( "$descriptions", "$descriptions_cached", "Same memory address used proves cached desc data" );
337
        $bucket = Koha::AuthorisedValues->_objects_cache_bucket('args');
338
        is(
339
            scalar( keys %{$control_descriptions} ), ( values %{$bucket} )[0]->count,
340
            "Same number of cached descriptions as control descriptions"
341
        );
336
    };
342
    };
337
343
338
    subtest 'authorised_values' => sub {
344
    subtest 'authorised_values' => sub {
Lines 363-368 subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v Link Here
363
369
364
        $schema->storage->txn_rollback;
370
        $schema->storage->txn_rollback;
365
    };
371
    };
372
373
    subtest 'get_description_by_category_and_authorised_value' => sub {
374
        plan tests => 1;
375
        my $description = Koha::AuthorisedValues->get_description_by_category_and_authorised_value(
376
            {
377
                category         => $av_0->category,
378
                authorised_value => $av_0->authorised_value,
379
            }
380
        );
381
        is_deeply(
382
            $description,
383
            {
384
                lib              => $av_0->lib,
385
                opac_description => $av_0->lib_opac
386
            }
387
        );
388
    };
366
};
389
};
367
390
368
subtest 'is_integer_only' => sub {
391
subtest 'is_integer_only' => sub {
(-)a/t/db_dependent/Koha/Filter/ExpandCodedFields.t (-6 lines)
Lines 69-80 subtest 'ExpandCodedFields tests' => sub { Link Here
69
    my $cache = Koha::Caches->get_instance;
69
    my $cache = Koha::Caches->get_instance;
70
    $cache->clear_from_cache("MarcCodedFields-");
70
    $cache->clear_from_cache("MarcCodedFields-");
71
71
72
    # Clear GetAuthorisedValueDesc-generated cache
73
    $cache->clear_from_cache("libraries:name");
74
    $cache->clear_from_cache("itemtype:description:en");
75
    $cache->clear_from_cache("cn_sources:description");
76
    $cache->clear_from_cache( "AV_descriptions:" . $av->category );
77
78
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
72
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
79
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
73
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
80
    $record = $biblio->metadata->record;
74
    $record = $biblio->metadata->record;
(-)a/t/db_dependent/Koha/Item.t (-15 / +6 lines)
Lines 2454-2463 subtest 'columns_to_str' => sub { Link Here
2454
    $cache->clear_from_cache("MarcStructure-0-");
2454
    $cache->clear_from_cache("MarcStructure-0-");
2455
    $cache->clear_from_cache("MarcStructure-1-");
2455
    $cache->clear_from_cache("MarcStructure-1-");
2456
    $cache->clear_from_cache("MarcSubfieldStructure-");
2456
    $cache->clear_from_cache("MarcSubfieldStructure-");
2457
    $cache->clear_from_cache("libraries:name");
2458
    $cache->clear_from_cache("itemtype:description:en");
2459
    $cache->clear_from_cache("cn_sources:description");
2460
    $cache->clear_from_cache("AV_descriptions:LOST");
2461
2457
2462
    # Creating subfields 'é', 'è' that are not linked with a kohafield
2458
    # Creating subfields 'é', 'è' that are not linked with a kohafield
2463
    Koha::MarcSubfieldStructures->search(
2459
    Koha::MarcSubfieldStructures->search(
Lines 2539-2548 subtest 'columns_to_str' => sub { Link Here
2539
    $cache->clear_from_cache("MarcStructure-0-");
2535
    $cache->clear_from_cache("MarcStructure-0-");
2540
    $cache->clear_from_cache("MarcStructure-1-");
2536
    $cache->clear_from_cache("MarcStructure-1-");
2541
    $cache->clear_from_cache("MarcSubfieldStructure-");
2537
    $cache->clear_from_cache("MarcSubfieldStructure-");
2542
    $cache->clear_from_cache("libraries:name");
2538
2543
    $cache->clear_from_cache("itemtype:description:en");
2539
    Koha::Libraries->_objects_cache_clear();
2544
    $cache->clear_from_cache("cn_sources:description");
2540
    Koha::ItemTypes->_objects_cache_clear();
2545
    $cache->clear_from_cache("AV_descriptions:LOST");
2546
2541
2547
    $schema->storage->txn_rollback;
2542
    $schema->storage->txn_rollback;
2548
};
2543
};
Lines 2559-2568 subtest 'strings_map() tests' => sub { Link Here
2559
    $cache->clear_from_cache("MarcStructure-0-");
2554
    $cache->clear_from_cache("MarcStructure-0-");
2560
    $cache->clear_from_cache("MarcStructure-1-");
2555
    $cache->clear_from_cache("MarcStructure-1-");
2561
    $cache->clear_from_cache("MarcSubfieldStructure-");
2556
    $cache->clear_from_cache("MarcSubfieldStructure-");
2562
    $cache->clear_from_cache("libraries:name");
2563
    $cache->clear_from_cache("itemtype:description:en");
2564
    $cache->clear_from_cache("cn_sources:description");
2565
    $cache->clear_from_cache("AV_descriptions:LOST");
2566
2557
2567
    # Recreating subfields just to be sure tests will be ok
2558
    # Recreating subfields just to be sure tests will be ok
2568
    # 1 => av (LOST)
2559
    # 1 => av (LOST)
Lines 2746-2754 subtest 'strings_map() tests' => sub { Link Here
2746
    $cache->clear_from_cache("MarcStructure-0-");
2737
    $cache->clear_from_cache("MarcStructure-0-");
2747
    $cache->clear_from_cache("MarcStructure-1-");
2738
    $cache->clear_from_cache("MarcStructure-1-");
2748
    $cache->clear_from_cache("MarcSubfieldStructure-");
2739
    $cache->clear_from_cache("MarcSubfieldStructure-");
2749
    $cache->clear_from_cache("libraries:name");
2740
2750
    $cache->clear_from_cache("itemtype:description:en");
2741
    Koha::Libraries->_objects_cache_clear();
2751
    $cache->clear_from_cache("cn_sources:description");
2742
    Koha::ItemTypes->_objects_cache_clear();
2752
2743
2753
    $schema->storage->txn_rollback;
2744
    $schema->storage->txn_rollback;
2754
};
2745
};
(-)a/t/db_dependent/Koha/OAI/Server/Repository.t (-6 lines)
Lines 53-63 subtest 'get_biblio_marcxml() tests' => sub { Link Here
53
    my $cache = Koha::Caches->get_instance;
53
    my $cache = Koha::Caches->get_instance;
54
    $cache->clear_from_cache("MarcCodedFields-");
54
    $cache->clear_from_cache("MarcCodedFields-");
55
55
56
    # Clear GetAuthorisedValueDesc-generated cache
57
    $cache->clear_from_cache("libraries:name");
58
    $cache->clear_from_cache("itemtype:description:en");
59
    $cache->clear_from_cache("cn_sources:description");
60
61
    my $cgi = Test::MockModule->new('CGI');
56
    my $cgi = Test::MockModule->new('CGI');
62
    $cgi->mock( 'Vars', sub { ( 'verb', 'Identify' ); } );
57
    $cgi->mock( 'Vars', sub { ( 'verb', 'Identify' ); } );
63
    my $yaml = Test::MockModule->new('YAML::XS');
58
    my $yaml = Test::MockModule->new('YAML::XS');
64
- 

Return to bug 31856