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

(-)a/C4/Biblio.pm (-10 / +57 lines)
Lines 94-99 use C4::Charset qw( Link Here
94
    SetMarcUnicodeFlag
94
    SetMarcUnicodeFlag
95
    SetUTF8Flag
95
    SetUTF8Flag
96
);
96
);
97
use C4::Languages;
97
use C4::Linker;
98
use C4::Linker;
98
use C4::OAI::Sets;
99
use C4::OAI::Sets;
99
use C4::Items qw( GetMarcItem );
100
use C4::Items qw( GetMarcItem );
Lines 1373-1397 descriptions rather than normal ones when they exist. Link Here
1373
sub GetAuthorisedValueDesc {
1374
sub GetAuthorisedValueDesc {
1374
    my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_;
1375
    my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_;
1375
1376
1377
    my $cache     = Koha::Caches->get_instance();
1378
    my $cache_key;
1376
    if ( !$category ) {
1379
    if ( !$category ) {
1377
1380
1378
        return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1381
        return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'};
1379
1382
1380
        #---- branch
1383
        #---- branch
1381
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1384
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
1382
            my $branch = Koha::Libraries->find($value);
1385
            $cache_key = "LibraryNames";
1383
            return $branch? $branch->branchname: q{};
1386
            my $libraries = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1387
            if ( !$libraries ) {
1388
                $libraries = {
1389
                    map { $_->branchcode => $_->branchname }
1390
                      Koha::Libraries->search( {},
1391
                        { columns => [ 'branchcode', 'branchname' ] } )
1392
                      ->as_list
1393
                };
1394
                $cache->set_in_cache($cache_key, $libraries);
1395
            }
1396
            return $libraries->{$value};
1384
        }
1397
        }
1385
1398
1386
        #---- itemtypes
1399
        #---- itemtypes
1387
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1400
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
1388
            my $itemtype = Koha::ItemTypes->find( $value );
1401
            my $lang = C4::Languages::getlanguage;
1389
            return $itemtype ? $itemtype->translated_description : q||;
1402
            $lang //= 'en';
1403
            $cache_key = $lang . 'ItemTypeDescriptions';
1404
            my $itypes = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1405
            if ( !$itypes ) {
1406
                $itypes =
1407
                  { map { $_->itemtype => $_->translated_description }
1408
                      Koha::ItemTypes->search()->as_list };
1409
                $cache->set_in_cache( $cache_key, $itypes );
1410
            }
1411
            return $itypes->{$value};
1390
        }
1412
        }
1391
1413
1392
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) {
1414
        if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "cn_source" ) {
1393
            my $source = GetClassSource($value);
1415
            $cache_key = "ClassSources";
1394
            return $source ? $source->{description} : q||;
1416
            my $cn_sources = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1417
            if ( !$cn_sources ) {
1418
                $cn_sources = {
1419
                    map { $_->cn_source => $_->description }
1420
                      Koha::ClassSources->search( {},
1421
                        { columns => [ 'cn_source', 'description' ] } )
1422
                      ->as_list
1423
                };
1424
                $cache->set_in_cache($cache_key, $cn_sources);
1425
            }
1426
            return $cn_sources->{$value};
1395
        }
1427
        }
1396
1428
1397
        #---- "true" authorized value
1429
        #---- "true" authorized value
Lines 1400-1409 sub GetAuthorisedValueDesc { Link Here
1400
1432
1401
    my $dbh = C4::Context->dbh;
1433
    my $dbh = C4::Context->dbh;
1402
    if ( $category ne "" ) {
1434
    if ( $category ne "" ) {
1403
        my $sth = $dbh->prepare( "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" );
1435
        $cache_key = "AVDescriptions-" . $category;
1404
        $sth->execute( $category, $value );
1436
        my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1405
        my $data = $sth->fetchrow_hashref;
1437
        if ( !$av_descriptions ) {
1406
        return ( $opac && $data->{'lib_opac'} ) ? $data->{'lib_opac'} : $data->{'lib'};
1438
            $av_descriptions = {
1439
                map {
1440
                    $_->authorised_value =>
1441
                      { lib => $_->lib, lib_opac => $_->lib_opac }
1442
                } Koha::AuthorisedValues->search(
1443
                    { category => $category },
1444
                    {
1445
                        columns => [ 'authorised_value', 'lib_opac', 'lib' ]
1446
                    }
1447
                )->as_list
1448
            };
1449
            $cache->set_in_cache($cache_key, $av_descriptions);
1450
        }
1451
        return ( $opac && $av_descriptions->{$value}->{'lib_opac'} )
1452
          ? $av_descriptions->{$value}->{'lib_opac'}
1453
          : $av_descriptions->{$value}->{'lib'};
1407
    } else {
1454
    } else {
1408
        return $value;    # if nothing is found return the original value
1455
        return $value;    # if nothing is found return the original value
1409
    }
1456
    }
(-)a/Koha/AuthorisedValue.pm (-1 / +32 lines)
Lines 19-25 package Koha::AuthorisedValue; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
22
use Koha::Caches;
23
use Koha::Database;
23
use Koha::Database;
24
24
25
use base qw(Koha::Object Koha::Object::Limit::Library);
25
use base qw(Koha::Object Koha::Object::Limit::Library);
Lines 34-39 Koha::AuthorisedValue - Koha Authorised value Object class Link Here
34
34
35
=cut
35
=cut
36
36
37
=head3 store
38
39
AuthorisedValue specific store to ensure relevant caches are flushed on change
40
41
=cut
42
43
sub store {
44
    my ($self) = @_;
45
46
    my $flush = 0;
47
48
    if ( !$self->in_storage ) {
49
        $flush = 1;
50
    }
51
    else {
52
        my $self_from_storage = $self->get_from_storage;
53
        $flush = 1 if ( $self_from_storage->lib ne $self->lib );
54
        $flush = 1 if ( $self_from_storage->lib_opac ne $self->lib_opac );
55
    }
56
57
    $self = $self->SUPER::store;
58
59
    if ($flush) {
60
        my $cache = Koha::Caches->get_instance();
61
        my $key = "AVDescriptions-".$self->category;
62
        $cache->clear_from_cache($key);
63
    }
64
65
    return $self;
66
}
67
37
=head3 opac_description
68
=head3 opac_description
38
69
39
my $description = $av->opac_description();
70
my $description = $av->opac_description();
(-)a/Koha/ClassSource.pm (-1 / +28 lines)
Lines 17-23 package Koha::ClassSource; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
20
use Koha::Caches;
21
use Koha::Database;
21
use Koha::Database;
22
22
23
use base qw(Koha::Object);
23
use base qw(Koha::Object);
Lines 30-37 Koha::ClassSource - Koha Classfication Source Object class Link Here
30
30
31
=head2 Class Methods
31
=head2 Class Methods
32
32
33
=head3 store
34
35
ClassSource specific store to ensure relevant caches are flushed on change
36
33
=cut
37
=cut
34
38
39
sub store {
40
    my ($self) = @_;
41
42
    my $flush = 0;
43
44
    if ( !$self->in_storage ) {
45
        $flush = 1;
46
    }
47
    else {
48
        my $self_from_storage = $self->get_from_storage;
49
        $flush = 1 if ( $self_from_storage->description ne $self->description );
50
    }
51
52
    $self = $self->SUPER::store;
53
54
    if ($flush) {
55
        my $cache = Koha::Caches->get_instance();
56
        $cache->clear_from_cache('ClassSources');
57
    }
58
59
    return $self;
60
}
61
35
=head3 _type
62
=head3 _type
36
63
37
Returns name of corresponding DBIC resultset
64
Returns name of corresponding DBIC resultset
(-)a/Koha/ItemType.pm (+31 lines)
Lines 20-25 use Modern::Perl; Link Here
20
20
21
use C4::Koha qw( getitemtypeimagelocation );
21
use C4::Koha qw( getitemtypeimagelocation );
22
use C4::Languages;
22
use C4::Languages;
23
use Koha::Caches;
23
use Koha::Database;
24
use Koha::Database;
24
use Koha::CirculationRules;
25
use Koha::CirculationRules;
25
use Koha::Localizations;
26
use Koha::Localizations;
Lines 36-41 Koha::ItemType - Koha Item type Object class Link Here
36
37
37
=cut
38
=cut
38
39
40
=head3 store
41
42
ItemType specific store to ensure relevant caches are flushed on change
43
44
=cut
45
46
sub store {
47
    my ($self) = @_;
48
49
    my $flush = 0;
50
51
    if ( !$self->in_storage ) {
52
        $flush = 1;
53
    }
54
    else {
55
        my $self_from_storage = $self->get_from_storage;
56
        $flush = 1 if ( $self_from_storage->description ne $self->description );
57
    }
58
59
    $self = $self->SUPER::store;
60
61
    if ($flush) {
62
        my $cache = Koha::Caches->get_instance();
63
        my $key = "enItemTypeDescriptions";
64
        $cache->clear_from_cache($key);
65
    }
66
67
    return $self;
68
}
69
39
=head3 image_location
70
=head3 image_location
40
71
41
=cut
72
=cut
(-)a/Koha/Library.pm (+30 lines)
Lines 22-27 use Modern::Perl; Link Here
22
22
23
use C4::Context;
23
use C4::Context;
24
24
25
use Koha::Caches;
25
use Koha::Database;
26
use Koha::Database;
26
use Koha::StockRotationStages;
27
use Koha::StockRotationStages;
27
use Koha::SMTP::Servers;
28
use Koha::SMTP::Servers;
Lines 36-41 Koha::Library - Koha Library Object class Link Here
36
37
37
=head2 Class methods
38
=head2 Class methods
38
39
40
=head3 store
41
42
Library specific store to ensure relevant caches are flushed on change
43
44
=cut
45
46
sub store {
47
    my ($self) = @_;
48
49
    my $flush = 0;
50
51
    if ( !$self->in_storage ) {
52
        $flush = 1;
53
    }
54
    else {
55
        my $self_from_storage = $self->get_from_storage;
56
        $flush = 1 if ( $self_from_storage->branchname ne $self->branchname );
57
    }
58
59
    $self = $self->SUPER::store;
60
61
    if ($flush) {
62
        my $cache = Koha::Caches->get_instance();
63
        $cache->clear_from_cache('LibraryNames');
64
    }
65
66
    return $self;
67
}
68
39
=head3 stockrotationstages
69
=head3 stockrotationstages
40
70
41
  my $stages = Koha::Library->stockrotationstages;
71
  my $stages = Koha::Library->stockrotationstages;
(-)a/Koha/Localization.pm (-1 / +29 lines)
Lines 21-26 use Koha::Database; Link Here
21
21
22
use base qw(Koha::Object);
22
use base qw(Koha::Object);
23
23
24
=head1 NAME
25
26
Koha::Localization - Koha Localization type Object class
27
28
=head1 API
29
30
=head2 Class methods
31
32
=cut
33
34
=head3 store
35
36
Localization specific store to ensure relevant caches are flushed on change
37
38
=cut
39
40
sub store {
41
    my ($self) = @_;
42
    $self = $self->SUPER::store;
43
44
    if ($self->entity eq 'itemtypes') {
45
        my $cache = Koha::Caches->get_instance();
46
        my $key = $self->lang."ItemTypeDescriptions";
47
        $cache->clear_from_cache($key);
48
    }
49
50
    return $self;
51
}
52
24
sub _type {
53
sub _type {
25
    return 'Localization';
54
    return 'Localization';
26
}
55
}
27
- 

Return to bug 30920