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

(-)a/C4/Context.pm (-17 / +19 lines)
Lines 370-375 sub new { Link Here
370
    $self->{"activeuser"} = undef;        # current active user
370
    $self->{"activeuser"} = undef;        # current active user
371
    $self->{"shelves"} = undef;
371
    $self->{"shelves"} = undef;
372
    $self->{tz} = undef; # local timezone object
372
    $self->{tz} = undef; # local timezone object
373
    $self->{sysprefs} = {};
373
374
374
    bless $self, $class;
375
    bless $self, $class;
375
    $self->{db_driver} = db_scheme2dbi($self->config('db_scheme'));  # cache database driver
376
    $self->{db_driver} = db_scheme2dbi($self->config('db_scheme'));  # cache database driver
Lines 505-511 with this method. Link Here
505
=cut
506
=cut
506
507
507
my $syspref_cache = Koha::Cache->get_instance();
508
my $syspref_cache = Koha::Cache->get_instance();
508
my %syspref_L1_cache;
509
my $use_syspref_cache = 1;
509
my $use_syspref_cache = 1;
510
sub preference {
510
sub preference {
511
    my $self = shift;
511
    my $self = shift;
Lines 513-522 sub preference { Link Here
513
513
514
    $var = lc $var;
514
    $var = lc $var;
515
515
516
    # Return the value if the var has already been accessed
516
    $self = $context unless ref $self;
517
    if ($use_syspref_cache && exists $syspref_L1_cache{$var}) {
517
518
        return $syspref_L1_cache{$var};
518
    return $self->{sysprefs}{$var} if $use_syspref_cache && $self && exists $self->{sysprefs}{$var};
519
    }
520
519
521
    my $cached_var = $use_syspref_cache
520
    my $cached_var = $use_syspref_cache
522
        ? $syspref_cache->get_from_cache("syspref_$var")
521
        ? $syspref_cache->get_from_cache("syspref_$var")
Lines 526-540 sub preference { Link Here
526
    my $value;
525
    my $value;
527
    if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) {
526
    if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) {
528
        $value = $ENV{"OVERRIDE_SYSPREF_$var"};
527
        $value = $ENV{"OVERRIDE_SYSPREF_$var"};
529
    } else {
528
    } elsif ( my $syspref = Koha::Config::SysPrefs->find( $var ) ) {
530
        my $syspref;
529
        $value = $syspref->value();
531
        eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) };
532
        $value = $syspref ? $syspref->value() : undef;
533
    }
530
    }
534
531
535
    if ( $use_syspref_cache ) {
532
    if ( $use_syspref_cache ) {
536
        $syspref_cache->set_in_cache("syspref_$var", $value);
533
        $syspref_cache->set_in_cache("syspref_$var", $value);
537
        $syspref_L1_cache{$var} = $value;
534
        $self->{sysprefs}{$var} = $value if $self;
538
    }
535
    }
539
    return $value;
536
    return $value;
540
}
537
}
Lines 588-600 will not be seen by this process. Link Here
588
=cut
585
=cut
589
586
590
sub clear_syspref_cache {
587
sub clear_syspref_cache {
588
    my ($self) = @_;
589
590
    $self = $context unless ref $self;
591
591
    return unless $use_syspref_cache;
592
    return unless $use_syspref_cache;
592
    $syspref_cache->flush_all;
593
    clear_syspref_L1_cache()
594
}
595
593
596
sub clear_syspref_L1_cache {
594
    $syspref_cache->flush_all;
597
    %syspref_L1_cache = ();
595
    $self->{sysprefs} = {} if $self;
598
}
596
}
599
597
600
=head2 set_preference
598
=head2 set_preference
Lines 613-618 sub set_preference { Link Here
613
611
614
    $variable = lc $variable;
612
    $variable = lc $variable;
615
613
614
    $self = $context unless ref $self;
615
616
    my $syspref = Koha::Config::SysPrefs->find($variable);
616
    my $syspref = Koha::Config::SysPrefs->find($variable);
617
    $type =
617
    $type =
618
        $type    ? $type
618
        $type    ? $type
Lines 647-653 sub set_preference { Link Here
647
647
648
    if ( $use_syspref_cache ) {
648
    if ( $use_syspref_cache ) {
649
        $syspref_cache->set_in_cache( "syspref_$variable", $value );
649
        $syspref_cache->set_in_cache( "syspref_$variable", $value );
650
        $syspref_L1_cache{$variable} = $value;
650
        $self->{sysprefs}{$variable} = $value if $self;
651
    }
651
    }
652
652
653
    return $syspref;
653
    return $syspref;
Lines 666-675 was no syspref of the name. Link Here
666
sub delete_preference {
666
sub delete_preference {
667
    my ( $self, $var ) = @_;
667
    my ( $self, $var ) = @_;
668
668
669
    $self = $context unless ref $self;
670
669
    if ( Koha::Config::SysPrefs->find( $var )->delete ) {
671
    if ( Koha::Config::SysPrefs->find( $var )->delete ) {
670
        if ( $use_syspref_cache ) {
672
        if ( $use_syspref_cache ) {
671
            $syspref_cache->clear_from_cache("syspref_$var");
673
            $syspref_cache->clear_from_cache("syspref_$var");
672
            delete $syspref_L1_cache{$var};
674
            delete $self->{sysprefs}{$var} if $self;
673
        }
675
        }
674
676
675
        return 1;
677
        return 1;
(-)a/t/db_dependent/sysprefs.t (-2 / +11 lines)
Lines 19-25 Link Here
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
use Test::More tests => 8;
22
use Test::More tests => 11;
23
use C4::Context;
23
use C4::Context;
24
24
25
# Start transaction
25
# Start transaction
Lines 60-63 is(C4::Context->preference('testpreference'), 'def', 'caching preferences'); Link Here
60
C4::Context->clear_syspref_cache();
60
C4::Context->clear_syspref_cache();
61
is(C4::Context->preference('testpreference'), undef, 'clearing preference cache');
61
is(C4::Context->preference('testpreference'), undef, 'clearing preference cache');
62
62
63
delete $ENV{OVERRIDE_SYSPREF_opacheader};
64
65
my $context1 = C4::Context->new();
66
is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"');
67
68
my $context2 = C4::Context->new();
69
$context2->set_preference( 'opacheader', $newopacheader );
70
is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"');
71
is( $context2->preference('opacheader'), $newopacheader, 'context2 "opacheader"');
72
63
$dbh->rollback;
73
$dbh->rollback;
64
- 

Return to bug 15562