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

(-)a/C4/Context.pm (-21 / +15 lines)
Lines 101-113 use DBIx::Connector; Link Here
101
use Encode;
101
use Encode;
102
use ZOOM;
102
use ZOOM;
103
use XML::Simple;
103
use XML::Simple;
104
use C4::Boolean;
105
use C4::Debug;
106
use POSIX ();
104
use POSIX ();
107
use DateTime::TimeZone;
105
use DateTime::TimeZone;
108
use Module::Load::Conditional qw(can_load);
106
use Module::Load::Conditional qw(can_load);
109
use Carp;
107
use Carp;
110
108
109
use C4::Boolean;
110
use C4::Debug;
111
use Koha::SysPrefs;
112
111
=head1 NAME
113
=head1 NAME
112
114
113
C4::Context - Maintain and manipulate the context of a Koha script
115
C4::Context - Maintain and manipulate the context of a Koha script
Lines 554-567 sub preference { Link Here
554
    if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) {
556
    if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) {
555
        $value = $ENV{"OVERRIDE_SYSPREF_$var"};
557
        $value = $ENV{"OVERRIDE_SYSPREF_$var"};
556
    } else {
558
    } else {
557
        # Look up systempreferences.variable==$var
559
        my $syspref = Koha::SysPrefs->find( lc $var );
558
        my $sql = q{
560
        $value = $syspref ? $syspref->value() : undef;
559
            SELECT  value
560
            FROM    systempreferences
561
            WHERE   variable = ?
562
            LIMIT   1
563
        };
564
        $value = $dbh->selectrow_array( $sql, {}, lc $var );
565
    }
561
    }
566
562
567
    $sysprefs{lc $var} = $value;
563
    $sysprefs{lc $var} = $value;
Lines 632-654 sub set_preference { Link Here
632
    my $var = lc(shift);
628
    my $var = lc(shift);
633
    my $value = shift;
629
    my $value = shift;
634
630
635
    my $dbh = C4::Context->dbh or return 0;
631
    my $syspref = Koha::SysPrefs->find( $var );
636
632
    my $type = $syspref ? $syspref->type() : undef;
637
    my $type = $dbh->selectrow_array( "SELECT type FROM systempreferences WHERE variable = ?", {}, $var );
638
633
639
    $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' );
634
    $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' );
640
635
641
    my $sth = $dbh->prepare( "
636
    if ($syspref) {
642
      INSERT INTO systempreferences
637
        $syspref = $syspref->set( { value => $value } )->store();
643
        ( variable, value )
638
    }
644
        VALUES( ?, ? )
639
    else {
645
        ON DUPLICATE KEY UPDATE value = VALUES(value)
640
        $syspref = Koha::Syspref->new( { variable => $var, value => $value } )->store();
646
    " );
641
    }
647
642
648
    if($sth->execute( $var, $value )) {
643
    if ($syspref) {
649
        $sysprefs{$var} = $value;
644
        $sysprefs{$var} = $value;
650
    }
645
    }
651
    $sth->finish;
652
}
646
}
653
647
654
# AUTOLOAD
648
# AUTOLOAD
(-)a/Koha/SysPref.pm (+52 lines)
Line 0 Link Here
1
package Koha::SysPref;
2
3
# Copyright ByWater Solutions 2014
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::SysPref - Koha Sysstem Preference Object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub type {
43
    return 'Systempreference';
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall <kyle@bywatersolutions.com>
49
50
=cut
51
52
1;
(-)a/Koha/SysPrefs.pm (-1 / +58 lines)
Line 0 Link Here
0
- 
1
package Koha::SysPrefs;
2
3
# Copyright ByWater Solutions 2014
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::SysPref;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::SysPrefs - Koha Borrower Object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub type {
45
    return 'Systempreference';
46
}
47
48
sub object_class {
49
    return 'Koha::SysPref';
50
}
51
52
=head1 AUTHOR
53
54
Kyle M Hall <kyle@bywatersolutions.com>
55
56
=cut
57
58
1;

Return to bug 13967