Lines 18-23
package C4::Context;
Link Here
|
18 |
|
18 |
|
19 |
use strict; |
19 |
use strict; |
20 |
use warnings; |
20 |
use warnings; |
|
|
21 |
|
22 |
use Koha::Config::SystemPreference; |
23 |
|
21 |
use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached); |
24 |
use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached); |
22 |
BEGIN { |
25 |
BEGIN { |
23 |
if ($ENV{'HTTP_USER_AGENT'}) { |
26 |
if ($ENV{'HTTP_USER_AGENT'}) { |
Lines 627-665
preference.
Link Here
|
627 |
|
630 |
|
628 |
sub set_preference { |
631 |
sub set_preference { |
629 |
my ( $self, $var, $value, $expl, $type, $options ) = @_; |
632 |
my ( $self, $var, $value, $expl, $type, $options ) = @_; |
630 |
$var = lc($var); |
|
|
631 |
|
633 |
|
632 |
my $dbh = C4::Context->dbh or return 0; |
634 |
$var = lc $var; |
633 |
|
635 |
|
634 |
my $db_type = $dbh->selectrow_array( |
636 |
my $set = Koha::Config::SystemPreference::set( $var, $value, $expl, $type, $options ); |
635 |
"SELECT type FROM systempreferences WHERE variable = ?", |
|
|
636 |
{}, $var ); |
637 |
|
637 |
|
638 |
$value = 0 if ( $db_type && $db_type eq 'YesNo' && $value eq '' ); |
638 |
$syspref_cache->set_in_cache("syspref_$var", $value) |
|
|
639 |
if $use_syspref_cache and $set; |
639 |
|
640 |
|
640 |
my ( $query, @params, $logtype ); |
641 |
return $set; |
641 |
if ( !defined($db_type) ) { |
|
|
642 |
$query = ' |
643 |
INSERT INTO systempreferences |
644 |
( variable, value, explanation, type, options ) |
645 |
VALUES( ?, ?, ?, ?, ? )'; |
646 |
@params = ( $var, $value, $expl, $type, $options ); |
647 |
$logtype = 'ADD'; |
648 |
} |
649 |
else { |
650 |
$query = ' |
651 |
INSERT INTO systempreferences |
652 |
( variable, value ) |
653 |
VALUES( ?, ? ) |
654 |
ON DUPLICATE KEY UPDATE value = VALUES(value)'; |
655 |
@params = ( $var, $value ); |
656 |
$logtype = 'MODIFY'; |
657 |
} |
658 |
my $sth = $dbh->prepare($query); |
659 |
if ( $sth->execute(@params) ) { |
660 |
$syspref_cache->set_in_cache("syspref_$var", $value) if $use_syspref_cache; |
661 |
} |
662 |
$sth->finish; |
663 |
} |
642 |
} |
664 |
|
643 |
|
665 |
=head2 delete_preference |
644 |
=head2 delete_preference |
Lines 678-690
sub delete_preference {
Link Here
|
678 |
# We want to log the previous value |
657 |
# We want to log the previous value |
679 |
my $val = C4::Context->preference($var); |
658 |
my $val = C4::Context->preference($var); |
680 |
my $dbh = C4::Context->dbh or die "Unable to talk to the database"; |
659 |
my $dbh = C4::Context->dbh or die "Unable to talk to the database"; |
681 |
my $sth = $dbh->prepare("DELETE FROM systempreferences WHERE variable=?"); |
660 |
|
682 |
my $res = $sth->execute($var); |
661 |
if ( Koha::Config::SystemPreference::delete($var) ) { |
683 |
if ($res) { |
|
|
684 |
$syspref_cache->clear_from_cache("syspref_$var") if $use_syspref_cache; |
662 |
$syspref_cache->clear_from_cache("syspref_$var") if $use_syspref_cache; |
685 |
return 1; |
663 |
return 1; |
686 |
} |
664 |
} |
687 |
warn "Unable to delete syspref: " . $sth->errstr; |
|
|
688 |
return 0; |
665 |
return 0; |
689 |
} |
666 |
} |
690 |
# AUTOLOAD |
667 |
# AUTOLOAD |