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 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 430-439
sub set_preference {
Link Here
|
430 |
my $variable_case = $variable; |
427 |
my $variable_case = $variable; |
431 |
$variable = lc $variable; |
428 |
$variable = lc $variable; |
432 |
|
429 |
|
433 |
my $syspref = Koha::Config::SysPrefs->find($variable); |
430 |
my ($oldvalue, $oldtype) = $self->dbh()->selectrow_array("SELECT value FROM systempreferences WHERE variable like '$variable'"); |
434 |
$type = |
431 |
$type = |
435 |
$type ? $type |
432 |
$type ? $type |
436 |
: $syspref ? $syspref->type |
433 |
: defined $oldtype ? $oldtype |
437 |
: undef; |
434 |
: undef; |
438 |
|
435 |
|
439 |
$value = 0 if ( $type && $type eq 'YesNo' && $value eq '' ); |
436 |
$value = 0 if ( $type && $type eq 'YesNo' && $value eq '' ); |
Lines 442-473
sub set_preference {
Link Here
|
442 |
if ( $variable eq 'opacbaseurl' && $value && substr( $value, 0, 4 ) !~ /http/ ) { |
439 |
if ( $variable eq 'opacbaseurl' && $value && substr( $value, 0, 4 ) !~ /http/ ) { |
443 |
$value = 'http://' . $value; |
440 |
$value = 'http://' . $value; |
444 |
} |
441 |
} |
445 |
|
442 |
|
446 |
if ($syspref) { |
443 |
my $sth = $self->dbh()->prepare("INSERT INTO systempreferences (variable, value, explanation, type, options) values (?,?,?,?,?) ON DUPLICATE KEY UPDATE value = ?"); |
447 |
$syspref->set( |
444 |
$sth->execute($variable, $value, $explanation || '', $type || '', $options || '', $value); |
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 |
|
445 |
|
465 |
if ( $use_syspref_cache ) { |
446 |
if ( $use_syspref_cache ) { |
466 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
447 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
467 |
$syspref_cache->set_in_cache( "syspref_$variable", $value ); |
448 |
$syspref_cache->set_in_cache( "syspref_$variable", $value ); |
468 |
} |
449 |
} |
469 |
|
450 |
|
470 |
return $syspref; |
|
|
471 |
} |
451 |
} |
472 |
|
452 |
|
473 |
=head2 delete_preference |
453 |
=head2 delete_preference |
Lines 483-497
was no syspref of the name.
Link Here
|
483 |
sub delete_preference { |
463 |
sub delete_preference { |
484 |
my ( $self, $var ) = @_; |
464 |
my ( $self, $var ) = @_; |
485 |
|
465 |
|
486 |
if ( Koha::Config::SysPrefs->find( $var )->delete ) { |
466 |
my $rc = $self->dbh()->do("DELETE FROM systempreferences WHERE variable like '$var'"); |
487 |
if ( $use_syspref_cache ) { |
467 |
if ( $use_syspref_cache ) { |
488 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
468 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
489 |
$syspref_cache->clear_from_cache("syspref_$var"); |
469 |
$syspref_cache->clear_from_cache("syspref_$var"); |
490 |
} |
|
|
491 |
|
492 |
return 1; |
493 |
} |
470 |
} |
494 |
return 0; |
|
|
495 |
} |
471 |
} |
496 |
|
472 |
|
497 |
=head2 csv_delimiter |
473 |
=head2 csv_delimiter |
498 |
- |
|
|