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/Objects.pm (+2 lines)
Lines 84-89 sub find { Link Here
84
84
85
    my $result = $self->_resultset()->find($id);
85
    my $result = $self->_resultset()->find($id);
86
86
87
    return unless $result;
88
87
    my $object = $self->object_class()->_new_from_dbic( $result );
89
    my $object = $self->object_class()->_new_from_dbic( $result );
88
90
89
    return $object;
91
    return $object;
(-)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 (+58 lines)
Line 0 Link Here
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;
(-)a/t/db_dependent/sysprefs.t (-11 / +12 lines)
Lines 19-25 Link Here
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
use C4::Context;
23
use C4::Context;
24
24
25
# Start transaction
25
# Start transaction
Lines 27-46 my $dbh = C4::Context->dbh; Link Here
27
$dbh->{RaiseError} = 1;
27
$dbh->{RaiseError} = 1;
28
$dbh->{AutoCommit} = 0;
28
$dbh->{AutoCommit} = 0;
29
29
30
my $opacheader = C4::Context->preference('opacheader');
30
my $opacheader    = C4::Context->preference('opacheader');
31
my $newopacheader = "newopacheader";
31
my $newopacheader = "newopacheader";
32
32
33
C4::Context->set_preference('OPACHEADER', $newopacheader);
33
C4::Context->set_preference( 'OPACHEADER', $newopacheader );
34
ok(C4::Context->preference('opacheader') eq $newopacheader);
34
is( C4::Context->preference('opacheader'), $newopacheader );
35
35
36
C4::Context->set_preference('opacheader', $opacheader);
36
C4::Context->set_preference( 'opacheader', $opacheader );
37
ok(C4::Context->preference('OPACHEADER') eq $opacheader);
37
is( C4::Context->preference('OPACHEADER'), $opacheader );
38
38
39
$ENV{OVERRIDE_SYSPREF_opacheader} = 'this is an override';
39
$ENV{OVERRIDE_SYSPREF_opacheader} = 'this is an override';
40
C4::Context->clear_syspref_cache();
40
C4::Context->clear_syspref_cache();
41
is(C4::Context->preference('opacheader'),
41
is(
42
   'this is an override',
42
    C4::Context->preference('opacheader'),
43
   'system preference value overridden from environment'
43
    'this is an override',
44
    'system preference value overridden from environment'
44
);
45
);
45
46
46
$dbh->rollback;
47
C4::Context->set_preference( 'IDoNotExist', 'NonExistent' );
48
is( C4::Context->preference('IDoNotExist'), 'NonExistent', 'Test creation of non-existant system preferencer' );
47
- 

Return to bug 13967