Lines 19-24
package C4::Context;
Link Here
|
19 |
use strict; |
19 |
use strict; |
20 |
use warnings; |
20 |
use warnings; |
21 |
use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached); |
21 |
use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached); |
|
|
22 |
use Koha::Cache; |
23 |
use Carp; |
22 |
|
24 |
|
23 |
BEGIN { |
25 |
BEGIN { |
24 |
if ($ENV{'HTTP_USER_AGENT'}) { |
26 |
if ($ENV{'HTTP_USER_AGENT'}) { |
Lines 534-561
with this method.
Link Here
|
534 |
# FIXME: running this under mod_perl will require a means of |
536 |
# FIXME: running this under mod_perl will require a means of |
535 |
# flushing the caching mechanism. |
537 |
# flushing the caching mechanism. |
536 |
|
538 |
|
537 |
my %sysprefs; |
539 |
my $sysprefs; |
538 |
my $use_syspref_cache = 1; |
540 |
my $use_syspref_cache = 1; |
|
|
541 |
my $cache; |
539 |
|
542 |
|
540 |
sub preference { |
543 |
sub preference { |
541 |
my $self = shift; |
544 |
my $self = shift; |
542 |
my $var = lc(shift); # The system preference to return |
545 |
my $var = lc(shift); # The system preference to return |
543 |
|
546 |
|
544 |
if ($use_syspref_cache && exists $sysprefs{$var}) { |
547 |
unless (defined $sysprefs) { |
545 |
return $sysprefs{$var}; |
548 |
unless ($cache) { |
|
|
549 |
$cache = Koha::Cache->new(); |
550 |
} |
551 |
$sysprefs = $cache->create_hash( |
552 |
{ |
553 |
'key' => 'syspref', |
554 |
'allowupdate' => 1, |
555 |
'cache_type' => $use_syspref_cache ? '' : 'null', |
556 |
'preload' => sub { |
557 |
my $dbh = C4::Context->dbh or return {}; |
558 |
my $vars = $dbh->selectall_arrayref("SELECT variable, value FROM systempreferences"); |
559 |
my %sysprefs = (); |
560 |
foreach my $row (@$vars) { |
561 |
$sysprefs{$row->[0]} = $row->[1]; |
562 |
} |
563 |
return \%sysprefs; |
564 |
}, |
565 |
'constructor' => sub { |
566 |
|
567 |
# Look up systempreferences.variable==$var |
568 |
my $var = pop; |
569 |
my $sysprefs = pop || {}; |
570 |
my $dbh = C4::Context->dbh or return 0; |
571 |
my $sql = |
572 |
"SELECT value FROM systempreferences WHERE variable=? LIMIT 1"; |
573 |
$ENV{DEBUG} && carp "Retrieving syspref $var from database"; |
574 |
my $sth = $dbh->prepare_cached($sql); |
575 |
$sth->execute($var); |
576 |
my $res = $sth->fetchrow_hashref; |
577 |
if ($res && $res->{'value'}) { |
578 |
$sysprefs->{$var} = $res->{'value'}; |
579 |
} else { |
580 |
$sysprefs->{$var} = ''; |
581 |
} |
582 |
return $sysprefs; |
583 |
}, |
584 |
} |
585 |
); |
546 |
} |
586 |
} |
547 |
|
587 |
return $sysprefs->{$var}; |
548 |
my $dbh = C4::Context->dbh or return 0; |
|
|
549 |
|
550 |
# Look up systempreferences.variable==$var |
551 |
my $sql = <<'END_SQL'; |
552 |
SELECT value |
553 |
FROM systempreferences |
554 |
WHERE variable=? |
555 |
LIMIT 1 |
556 |
END_SQL |
557 |
$sysprefs{$var} = $dbh->selectrow_array( $sql, {}, $var ); |
558 |
return $sysprefs{$var}; |
559 |
} |
588 |
} |
560 |
|
589 |
|
561 |
sub boolean_preference { |
590 |
sub boolean_preference { |
Lines 591-597
used with Plack and other persistent environments.
Link Here
|
591 |
sub disable_syspref_cache { |
620 |
sub disable_syspref_cache { |
592 |
my ($self) = @_; |
621 |
my ($self) = @_; |
593 |
$use_syspref_cache = 0; |
622 |
$use_syspref_cache = 0; |
594 |
$self->clear_syspref_cache(); |
623 |
$self->clear_syspref_cache() if defined($sysprefs); |
595 |
} |
624 |
} |
596 |
|
625 |
|
597 |
=head2 clear_syspref_cache |
626 |
=head2 clear_syspref_cache |
Lines 605-611
will not be seen by this process.
Link Here
|
605 |
=cut |
634 |
=cut |
606 |
|
635 |
|
607 |
sub clear_syspref_cache { |
636 |
sub clear_syspref_cache { |
608 |
%sysprefs = (); |
637 |
%{$sysprefs} = (); |
|
|
638 |
return; |
609 |
} |
639 |
} |
610 |
|
640 |
|
611 |
=head2 set_preference |
641 |
=head2 set_preference |
Lines 636-642
sub set_preference {
Link Here
|
636 |
" ); |
666 |
" ); |
637 |
|
667 |
|
638 |
if($sth->execute( $var, $value )) { |
668 |
if($sth->execute( $var, $value )) { |
639 |
$sysprefs{$var} = $value; |
669 |
$sysprefs->{$var} = $value; |
640 |
} |
670 |
} |
641 |
$sth->finish; |
671 |
$sth->finish; |
642 |
} |
672 |
} |
643 |
- |
|
|