|
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 629-668
preference.
Link Here
|
| 629 |
|
632 |
|
| 630 |
sub set_preference { |
633 |
sub set_preference { |
| 631 |
my ( $self, $var, $value, $expl, $type, $options ) = @_; |
634 |
my ( $self, $var, $value, $expl, $type, $options ) = @_; |
| 632 |
$var = lc($var); |
|
|
| 633 |
|
635 |
|
| 634 |
my $dbh = C4::Context->dbh or return 0; |
636 |
$var = lc $var; |
| 635 |
|
637 |
|
| 636 |
my $db_type = $dbh->selectrow_array( |
638 |
my $set = Koha::Config::SystemPreference::set( $var, $value, $expl, $type, $options ); |
| 637 |
"SELECT type FROM systempreferences WHERE variable = ?", |
|
|
| 638 |
{}, $var ); |
| 639 |
|
639 |
|
| 640 |
$value = 0 if ( $db_type && $db_type eq 'YesNo' && $value eq '' ); |
640 |
$syspref_cache->set_in_cache("syspref_$var", $value) |
|
|
641 |
if $use_syspref_cache and $set; |
| 641 |
|
642 |
|
| 642 |
my ( $query, @params, $logtype ); |
643 |
return $set; |
| 643 |
if ( !defined($db_type) ) { |
|
|
| 644 |
$query = ' |
| 645 |
INSERT INTO systempreferences |
| 646 |
( variable, value, explanation, type, options ) |
| 647 |
VALUES( ?, ?, ?, ?, ? )'; |
| 648 |
@params = ( $var, $value, $expl, $type, $options ); |
| 649 |
$logtype = 'ADD'; |
| 650 |
} |
| 651 |
else { |
| 652 |
$query = ' |
| 653 |
INSERT INTO systempreferences |
| 654 |
( variable, value ) |
| 655 |
VALUES( ?, ? ) |
| 656 |
ON DUPLICATE KEY UPDATE value = VALUES(value)'; |
| 657 |
@params = ( $var, $value ); |
| 658 |
$logtype = 'MODIFY'; |
| 659 |
} |
| 660 |
my $sth = $dbh->prepare($query); |
| 661 |
if ( $sth->execute(@params) ) { |
| 662 |
$syspref_cache->set_in_cache("syspref_$var", $value) if $use_syspref_cache; |
| 663 |
logaction( $dbh, userenv(), 'SYSTEMPREFERENCE', $logtype, undef, $var . " | " . $value ); |
| 664 |
} |
| 665 |
$sth->finish; |
| 666 |
} |
644 |
} |
| 667 |
|
645 |
|
| 668 |
=head2 delete_preference |
646 |
=head2 delete_preference |
|
Lines 681-695
sub delete_preference {
Link Here
|
| 681 |
# We want to log the previous value |
659 |
# We want to log the previous value |
| 682 |
my $val = C4::Context->preference($var); |
660 |
my $val = C4::Context->preference($var); |
| 683 |
my $dbh = C4::Context->dbh or die "Unable to talk to the database"; |
661 |
my $dbh = C4::Context->dbh or die "Unable to talk to the database"; |
| 684 |
my $sth = $dbh->prepare("DELETE FROM systempreferences WHERE variable=?"); |
662 |
|
| 685 |
my $res = $sth->execute($var); |
663 |
if ( Koha::Config::SystemPreference::delete($var) ) { |
| 686 |
if ($res) { |
|
|
| 687 |
$syspref_cache->clear_from_cache("syspref_$var") if $use_syspref_cache; |
664 |
$syspref_cache->clear_from_cache("syspref_$var") if $use_syspref_cache; |
| 688 |
logaction( $dbh, userenv(), 'SYSTEMPREFERENCE', 'DELETE', undef, |
665 |
logaction( $dbh, userenv(), 'SYSTEMPREFERENCE', 'DELETE', undef, |
| 689 |
$var . " | " . ( $val // 'undefined' ) ); |
666 |
$var . " | " . ( $val // 'undefined' ) ); |
| 690 |
return 1; |
667 |
return 1; |
| 691 |
} |
668 |
} |
| 692 |
warn "Unable to delete syspref: " . $sth->errstr; |
|
|
| 693 |
return 0; |
669 |
return 0; |
| 694 |
} |
670 |
} |
| 695 |
# AUTOLOAD |
671 |
# AUTOLOAD |