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

(-)a/C4/Context.pm (-3 / +7 lines)
Lines 520-527 sub ModZebrations { Link Here
520
520
521
=head2 _cache_preference($variable, [$value])
521
=head2 _cache_preference($variable, [$value])
522
522
523
  _cache_preferences('opacusercss', $css);
523
  _cache_preference('opacusercss', $css);
524
  my $val = _cach_preferences('opacusercss');
524
  my $val = _cache_preference('opacusercss');
525
525
526
An interface into the syspref caching. One argument to get a value, two to set
526
An interface into the syspref caching. One argument to get a value, two to set
527
it. The single argument version will return C<undef> if the cache doesn't
527
it. The single argument version will return C<undef> if the cache doesn't
Lines 541-546 sub _cache_preference { Link Here
541
    my $memcached        = memcached();
541
    my $memcached        = memcached();
542
    my $memcached_prefix = "_syspref_";
542
    my $memcached_prefix = "_syspref_";
543
    if ( scalar(@_) == 1 ) {
543
    if ( scalar(@_) == 1 ) {
544
        # This means we want to fetch from the cache
544
        my ($var) = @_;
545
        my ($var) = @_;
545
        if ($memcached) {
546
        if ($memcached) {
546
            my $val = $memcached->get( $memcached_prefix . lc($var) );
547
            my $val = $memcached->get( $memcached_prefix . lc($var) );
Lines 556-561 sub _cache_preference { Link Here
556
        }
557
        }
557
    }
558
    }
558
    elsif ( scalar(@_) == 2 ) {
559
    elsif ( scalar(@_) == 2 ) {
560
        # Set something in the cache
559
        my ( $var, $val ) = @_;
561
        my ( $var, $val ) = @_;
560
        if ($memcached) {
562
        if ($memcached) {
561
            if ( !defined($val) ) {
563
            if ( !defined($val) ) {
Lines 572-577 sub _cache_preference { Link Here
572
            }
574
            }
573
            $syspref_cache{ lc $var } = [ time, $val ];
575
            $syspref_cache{ lc $var } = [ time, $val ];
574
        }
576
        }
577
    } else {
578
        confess "Invalid arguments to _cache_preference: " . join(', ', @_);
575
    }
579
    }
576
}
580
}
577
581
Lines 740-746 sub delete_preference { Link Here
740
    my $sth = $dbh->prepare("DELETE FROM systempreferences WHERE variable=?");
744
    my $sth = $dbh->prepare("DELETE FROM systempreferences WHERE variable=?");
741
    my $res = $sth->execute($var);
745
    my $res = $sth->execute($var);
742
    if ($res) {
746
    if ($res) {
743
        C4::Context->set_preference($var, undef);
747
        _cache_preference($var, undef);
744
        logaction( 'SYSTEMPREFERENCE', 'DELETE', undef,
748
        logaction( 'SYSTEMPREFERENCE', 'DELETE', undef,
745
            $var . " | " . ( $var // 'undefined' ) );
749
            $var . " | " . ( $var // 'undefined' ) );
746
        return 1;
750
        return 1;
(-)a/t/db_dependent/sysprefs.t (-2 / +12 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 => 3;
22
use Test::More tests => 6;
23
use C4::Context;
23
use C4::Context;
24
24
25
# Start transaction
25
# Start transaction
Lines 43-46 is(C4::Context->preference('opacheader'), Link Here
43
   'system preference value overridden from environment'
43
   'system preference value overridden from environment'
44
);
44
);
45
45
46
C4::Context->set_preference('testpreference', 'abc');
47
C4::Context->delete_preference('testpreference');
48
is(C4::Context->preference('testpreference'), undef, 'deleting preferences');
49
50
C4::Context->set_preference('testpreference', 'def');
51
# Delete from the database, it should still be in cache
52
$dbh->do("DELETE FROM systempreferences WHERE variable='testpreference'");
53
is(C4::Context->preference('testpreference'), 'def', 'caching preferences');
54
C4::Context->clear_syspref_cache();
55
is(C4::Context->preference('testpreference'), undef, 'clearing preference cache');
56
46
$dbh->rollback;
57
$dbh->rollback;
47
- 

Return to bug 11998