Lines 41-49
use File::Spec;
Link Here
|
41 |
use List::MoreUtils qw(any); |
41 |
use List::MoreUtils qw(any); |
42 |
|
42 |
|
43 |
use Koha::Caches; |
43 |
use Koha::Caches; |
44 |
use Koha::Config::SysPref; |
|
|
45 |
use Koha::Config::SysPrefs; |
46 |
use Koha::Config; |
44 |
use Koha::Config; |
|
|
45 |
use Koha::Database; |
47 |
use Koha; |
46 |
use Koha; |
48 |
|
47 |
|
49 |
=head1 NAME |
48 |
=head1 NAME |
Lines 300-306
with this method.
Link Here
|
300 |
|
299 |
|
301 |
=cut |
300 |
=cut |
302 |
|
301 |
|
303 |
my $use_syspref_cache = 1; |
302 |
our $use_syspref_cache = 1; |
304 |
sub preference { |
303 |
sub preference { |
305 |
my $self = shift; |
304 |
my $self = shift; |
306 |
my $var = shift; # The system preference to return |
305 |
my $var = shift; # The system preference to return |
Lines 316-324
sub preference {
Link Here
|
316 |
return $cached_var if defined $cached_var; |
315 |
return $cached_var if defined $cached_var; |
317 |
} |
316 |
} |
318 |
|
317 |
|
319 |
my $syspref; |
318 |
my ($value) = $self->dbh()->selectrow_array("SELECT value FROM systempreferences WHERE variable like '$var'"); |
320 |
eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; |
|
|
321 |
my $value = $syspref ? $syspref->value() : undef; |
322 |
|
319 |
|
323 |
if ( $use_syspref_cache ) { |
320 |
if ( $use_syspref_cache ) { |
324 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
321 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
Lines 413-499
sub clear_syspref_cache {
Link Here
|
413 |
$syspref_cache->flush_all; |
410 |
$syspref_cache->flush_all; |
414 |
} |
411 |
} |
415 |
|
412 |
|
416 |
=head2 set_preference |
|
|
417 |
|
418 |
C4::Context->set_preference( $variable, $value, [ $explanation, $type, $options ] ); |
419 |
|
420 |
This updates a preference's value both in the systempreferences table and in |
421 |
the sysprefs cache. If the optional parameters are provided, then the query |
422 |
becomes a create. It won't update the parameters (except value) for an existing |
423 |
preference. |
424 |
|
425 |
=cut |
426 |
|
427 |
sub set_preference { |
428 |
my ( $self, $variable, $value, $explanation, $type, $options ) = @_; |
429 |
|
430 |
my $variable_case = $variable; |
431 |
$variable = lc $variable; |
432 |
|
433 |
my $syspref = Koha::Config::SysPrefs->find($variable); |
434 |
$type = |
435 |
$type ? $type |
436 |
: $syspref ? $syspref->type |
437 |
: undef; |
438 |
|
439 |
$value = 0 if ( $type && $type eq 'YesNo' && $value eq '' ); |
440 |
|
441 |
# force explicit protocol on OPACBaseURL |
442 |
if ( $variable eq 'opacbaseurl' && $value && substr( $value, 0, 4 ) !~ /http/ ) { |
443 |
$value = 'http://' . $value; |
444 |
} |
445 |
|
446 |
if ($syspref) { |
447 |
$syspref->set( |
448 |
{ ( defined $value ? ( value => $value ) : () ), |
449 |
( $explanation ? ( explanation => $explanation ) : () ), |
450 |
( $type ? ( type => $type ) : () ), |
451 |
( $options ? ( options => $options ) : () ), |
452 |
} |
453 |
)->store; |
454 |
} else { |
455 |
$syspref = Koha::Config::SysPref->new( |
456 |
{ variable => $variable_case, |
457 |
value => $value, |
458 |
explanation => $explanation || undef, |
459 |
type => $type, |
460 |
options => $options || undef, |
461 |
} |
462 |
)->store(); |
463 |
} |
464 |
|
465 |
if ( $use_syspref_cache ) { |
466 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
467 |
$syspref_cache->set_in_cache( "syspref_$variable", $value ); |
468 |
} |
469 |
|
470 |
return $syspref; |
471 |
} |
472 |
|
473 |
=head2 delete_preference |
474 |
|
475 |
C4::Context->delete_preference( $variable ); |
476 |
|
477 |
This deletes a system preference from the database. Returns a true value on |
478 |
success. Failure means there was an issue with the database, not that there |
479 |
was no syspref of the name. |
480 |
|
481 |
=cut |
482 |
|
483 |
sub delete_preference { |
484 |
my ( $self, $var ) = @_; |
485 |
|
486 |
if ( Koha::Config::SysPrefs->find( $var )->delete ) { |
487 |
if ( $use_syspref_cache ) { |
488 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
489 |
$syspref_cache->clear_from_cache("syspref_$var"); |
490 |
} |
491 |
|
492 |
return 1; |
493 |
} |
494 |
return 0; |
495 |
} |
496 |
|
497 |
=head2 csv_delimiter |
413 |
=head2 csv_delimiter |
498 |
|
414 |
|
499 |
$delimiter = C4::Context->csv_delimiter; |
415 |
$delimiter = C4::Context->csv_delimiter; |