View | Details | Raw Unified | Return to bug 11998
Collapse All | Expand All

(-)a/C4/Context.pm (-33 / +10 lines)
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
(-)a/Koha/Config/SystemPreference.pm (-1 / +50 lines)
Line 0 Link Here
0
- 
1
package Koha::Config::SystemPreference;
2
3
use Koha::Database;
4
use C4::Log qw( logaction );
5
6
sub set {
7
    my ( $variable, $value, $expl, $type, $options ) = @_;
8
9
    my $dbh = C4::Context->dbh or return 0;
10
11
    my $pref = Koha::Database->new->schema->resultset('Systempreference')->find($variable);
12
13
    if ( $pref ) {
14
        $value = 0 if ( $pref->type && $pref->type eq 'YesNo' && $pref->type eq '' );
15
    }
16
17
    $pref = Koha::Database->new->schema->resultset('Systempreference')->update_or_new(
18
        {
19
            variable => $variable,
20
            value => $value,
21
            explanation => $expl,
22
            type => $type,
23
            options => $options,
24
        }
25
    );
26
27
    if ( $pref->in_storage ) {
28
        logaction('SYSTEMPREFERENCE', 'MODIFY', undef, $variable . ' | ' . $value);
29
        return 1;
30
    }
31
32
    my $inserted  = $pref->insert;
33
    logaction('SYSTEMPREFERENCE', 'ADD', undef, $variable . ' | ' . $value) if $inserted;
34
35
    return $inserted;
36
}
37
38
sub delete {
39
    my ( $variable ) = @_;
40
41
    my $deleted = Koha::Database->new->schema->resultset('Systempreference')->find($variable)->delete;
42
43
    return unless $deleted;
44
45
    logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
46
47
    return 1
48
}
49
50
1

Return to bug 11998