|
Lines 101-107
use C4::Boolean;
Link Here
|
| 101 |
use C4::Debug; |
101 |
use C4::Debug; |
| 102 |
use Koha; |
102 |
use Koha; |
| 103 |
use Koha::Config; |
103 |
use Koha::Config; |
| 104 |
use Koha::Config::SysPref; |
|
|
| 105 |
use Koha::Config::SysPrefs; |
104 |
use Koha::Config::SysPrefs; |
| 106 |
|
105 |
|
| 107 |
=head1 NAME |
106 |
=head1 NAME |
|
Lines 401-408
with this method.
Link Here
|
| 401 |
|
400 |
|
| 402 |
=cut |
401 |
=cut |
| 403 |
|
402 |
|
| 404 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
403 |
my $sysprefs = {}; |
| 405 |
my $use_syspref_cache = 1; |
404 |
my $use_syspref_cache = 1; |
|
|
405 |
|
| 406 |
sub preference { |
406 |
sub preference { |
| 407 |
my $self = shift; |
407 |
my $self = shift; |
| 408 |
my $var = shift; # The system preference to return |
408 |
my $var = shift; # The system preference to return |
|
Lines 410-430
sub preference {
Link Here
|
| 410 |
$var = lc $var; |
410 |
$var = lc $var; |
| 411 |
|
411 |
|
| 412 |
return $ENV{"OVERRIDE_SYSPREF_$var"} |
412 |
return $ENV{"OVERRIDE_SYSPREF_$var"} |
| 413 |
if defined $ENV{"OVERRIDE_SYSPREF_$var"}; |
413 |
if defined $ENV{"OVERRIDE_SYSPREF_$var"}; |
| 414 |
|
414 |
|
| 415 |
my $cached_var = $use_syspref_cache |
415 |
my $cached_var; |
| 416 |
? $syspref_cache->get_from_cache("syspref_$var") |
416 |
if ($use_syspref_cache) { |
| 417 |
: undef; |
417 |
unless (%$sysprefs) { |
|
|
418 |
# first hit |
| 419 |
my $syspref_cache = Koha::Caches->get_instance('sysprefs'); |
| 420 |
$sysprefs = $syspref_cache->get_from_cache('sysprefs'); |
| 421 |
unless ( $sysprefs and %$sysprefs) { |
| 422 |
# L2 is not populated yet |
| 423 |
map { $sysprefs->{ lc $_->{variable} } = $_->{value} or undef } @{ Koha::Config::SysPrefs->search()->unblessed }; |
| 424 |
$syspref_cache->set_in_cache( 'sysprefs', $sysprefs ); |
| 425 |
} |
| 426 |
} |
| 427 |
$cached_var = exists $sysprefs->{$var} ? $sysprefs->{$var} : undef; |
| 428 |
} |
| 418 |
return $cached_var if defined $cached_var; |
429 |
return $cached_var if defined $cached_var; |
| 419 |
|
430 |
|
| 420 |
my $syspref; |
431 |
my $syspref; |
| 421 |
eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; |
432 |
eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; |
| 422 |
my $value = $syspref ? $syspref->value() : undef; |
433 |
return $syspref ? $syspref->value() : undef; |
| 423 |
|
|
|
| 424 |
if ( $use_syspref_cache ) { |
| 425 |
$syspref_cache->set_in_cache("syspref_$var", $value); |
| 426 |
} |
| 427 |
return $value; |
| 428 |
} |
434 |
} |
| 429 |
|
435 |
|
| 430 |
sub boolean_preference { |
436 |
sub boolean_preference { |
|
Lines 477-483
will not be seen by this process.
Link Here
|
| 477 |
|
483 |
|
| 478 |
sub clear_syspref_cache { |
484 |
sub clear_syspref_cache { |
| 479 |
return unless $use_syspref_cache; |
485 |
return unless $use_syspref_cache; |
|
|
486 |
my $syspref_cache = Koha::Caches->get_instance('sysprefs'); |
| 480 |
$syspref_cache->flush_all; |
487 |
$syspref_cache->flush_all; |
|
|
488 |
$sysprefs = {}; |
| 481 |
} |
489 |
} |
| 482 |
|
490 |
|
| 483 |
=head2 set_preference |
491 |
=head2 set_preference |
|
Lines 528-538
sub set_preference {
Link Here
|
| 528 |
)->store(); |
536 |
)->store(); |
| 529 |
} |
537 |
} |
| 530 |
|
538 |
|
| 531 |
if ( $use_syspref_cache ) { |
539 |
$self->clear_syspref_cache; |
| 532 |
$syspref_cache->set_in_cache( "syspref_$variable", $value ); |
540 |
return $self->preference($variable); |
| 533 |
} |
|
|
| 534 |
|
| 535 |
return $syspref; |
| 536 |
} |
541 |
} |
| 537 |
|
542 |
|
| 538 |
=head2 delete_preference |
543 |
=head2 delete_preference |
|
Lines 550-555
sub delete_preference {
Link Here
|
| 550 |
|
555 |
|
| 551 |
if ( Koha::Config::SysPrefs->find( $var )->delete ) { |
556 |
if ( Koha::Config::SysPrefs->find( $var )->delete ) { |
| 552 |
if ( $use_syspref_cache ) { |
557 |
if ( $use_syspref_cache ) { |
|
|
558 |
my $syspref_cache = Koha::Caches->get_instance('sysprefs'); |
| 553 |
$syspref_cache->clear_from_cache("syspref_$var"); |
559 |
$syspref_cache->clear_from_cache("syspref_$var"); |
| 554 |
} |
560 |
} |
| 555 |
|
561 |
|
| 556 |
- |
|
|