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

(-)a/C4/Context.pm (-13 / +16 lines)
Lines 368-373 sub new { Link Here
368
    $self->{"activeuser"} = undef;        # current active user
368
    $self->{"activeuser"} = undef;        # current active user
369
    $self->{"shelves"} = undef;
369
    $self->{"shelves"} = undef;
370
    $self->{tz} = undef; # local timezone object
370
    $self->{tz} = undef; # local timezone object
371
    $self->{sysprefs} = {};
371
372
372
    bless $self, $class;
373
    bless $self, $class;
373
    $self->{db_driver} = db_scheme2dbi($self->config('db_scheme'));  # cache database driver
374
    $self->{db_driver} = db_scheme2dbi($self->config('db_scheme'));  # cache database driver
Lines 505-533 with this method. Link Here
505
# FIXME: running this under mod_perl will require a means of
506
# FIXME: running this under mod_perl will require a means of
506
# flushing the caching mechanism.
507
# flushing the caching mechanism.
507
508
508
my %sysprefs;
509
my $use_syspref_cache = 1;
509
my $use_syspref_cache = 1;
510
510
511
sub preference {
511
sub preference {
512
    my $self = shift;
512
    my $self = shift;
513
    my $var  = shift;    # The system preference to return
513
    my $var  = shift;    # The system preference to return
514
    my $lc_var = lc $var;
514
515
515
    if ($use_syspref_cache && exists $sysprefs{lc $var}) {
516
    $self = $context unless ref $self;
516
        return $sysprefs{lc $var};
517
517
    }
518
    return $self->{sysprefs}{$lc_var} if $use_syspref_cache && $self && exists $self->{sysprefs}{$lc_var};
518
519
519
    my $dbh  = C4::Context->dbh or return 0;
520
    my $dbh  = C4::Context->dbh or return 0;
520
521
521
    my $value;
522
    my $value;
522
    if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) {
523
    if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) {
523
        $value = $ENV{"OVERRIDE_SYSPREF_$var"};
524
        $value = $ENV{"OVERRIDE_SYSPREF_$var"};
524
    } else {
525
    } elsif ( my $syspref = Koha::Config::SysPrefs->find( $lc_var ) ) {
525
        my $syspref;
526
        $value = $syspref->value();
526
        eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) };
527
        $value = $syspref ? $syspref->value() : undef;
528
    }
527
    }
529
528
530
    $sysprefs{lc $var} = $value;
529
    $self->{sysprefs}{$lc_var} = $value if $use_syspref_cache && $self;
531
    return $value;
530
    return $value;
532
}
531
}
533
532
Lines 578-584 will not be seen by this process. Link Here
578
=cut
577
=cut
579
578
580
sub clear_syspref_cache {
579
sub clear_syspref_cache {
581
    %sysprefs = ();
580
    my ($self) = @_;
581
582
    $self = $context unless ref $self;
583
584
    $self->{sysprefs} = {} if $self;
582
}
585
}
583
586
584
=head2 set_preference
587
=head2 set_preference
Lines 595-600 sub set_preference { Link Here
595
    my $var = lc(shift);
598
    my $var = lc(shift);
596
    my $value = shift;
599
    my $value = shift;
597
600
601
    $self = $context unless ref $self;
602
598
    my $syspref = Koha::Config::SysPrefs->find( $var );
603
    my $syspref = Koha::Config::SysPrefs->find( $var );
599
    my $type = $syspref ? $syspref->type() : undef;
604
    my $type = $syspref ? $syspref->type() : undef;
600
605
Lines 612-620 sub set_preference { Link Here
612
        $syspref = Koha::Config::SysPref->new( { variable => $var, value => $value } )->store();
617
        $syspref = Koha::Config::SysPref->new( { variable => $var, value => $value } )->store();
613
    }
618
    }
614
619
615
    if ($syspref) {
620
    $self->{sysprefs}{$var} = $value if $use_syspref_cache && $self;
616
        $sysprefs{$var} = $value;
617
    }
618
}
621
}
619
622
620
=head2 Zconn
623
=head2 Zconn
(-)a/t/db_dependent/sysprefs.t (-2 / +13 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 => 5;
22
use Test::More tests => 8;
23
use C4::Context;
23
use C4::Context;
24
24
25
# Start transaction
25
# Start transaction
Lines 48-50 is( C4::Context->preference('IDoNotExist'), undef, 'Get a non-existent system pr Link Here
48
48
49
C4::Context->set_preference( 'IDoNotExist', 'NonExistent' );
49
C4::Context->set_preference( 'IDoNotExist', 'NonExistent' );
50
is( C4::Context->preference('IDoNotExist'), 'NonExistent', 'Test creation of non-existent system preference' );
50
is( C4::Context->preference('IDoNotExist'), 'NonExistent', 'Test creation of non-existent system preference' );
51
- 
51
52
delete $ENV{OVERRIDE_SYSPREF_opacheader};
53
54
my $context1 = C4::Context->new();
55
is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"');
56
57
my $context2 = C4::Context->new();
58
$context2->set_preference( 'opacheader', $newopacheader );
59
is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"');
60
is( $context2->preference('opacheader'), $newopacheader, 'context2 "opacheader"');
61
62
$dbh->rollback;

Return to bug 15562