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