@@ -, +, @@ --- C4/Context.pm | 13 +++++++++++++ Koha/Config/SysPref.pm | 16 ++++++++++++++++ admin/preferences.pl | 2 +- t/db_dependent/Context.t | 1 - t/db_dependent/sysprefs.t | 17 ++++++++++++++++- 5 files changed, 46 insertions(+), 3 deletions(-) --- a/C4/Context.pm +++ a/C4/Context.pm @@ -559,6 +559,19 @@ sub delete_preference { return 0; } +=head2 select_systempreferences +my $row = C4::Context->select_systempreferences($name); + +This subroutine retrieves and returns the value and type of systempreference records matching the variable value $name +=cut + +sub select_systempreferences { + my ($self, $name) = @_; + my $row = Koha::Config::SysPrefs->find($name); + return $row; +} + + =head2 Zconn $Zconn = C4::Context->Zconn --- a/Koha/Config/SysPref.pm +++ a/Koha/Config/SysPref.pm @@ -67,6 +67,22 @@ sub delete { return $deleted; } +=head3 select_systempreferences +my $row = Koha::Config::SysPrefs->find($name); + +This subroutine retrieves systempreference records with a specific variable value +=cut + +sub select_systempreferences { + my ($self, $name) = @_; + my $schema = Koha::Database->new()->schema(); + my $syspref = $schema->resultset('Systempreference')->search( + {variable => $name} + ); + return $syspref; + +} + =head3 type =cut --- a/admin/preferences.pl +++ a/admin/preferences.pl @@ -158,7 +158,7 @@ sub TransformPrefsToHTML { my $name = $piece->{'pref'}; if ( $name ) { - my $row = $dbh->selectrow_hashref( "SELECT value, type FROM systempreferences WHERE variable = ?", {}, $name ); + my $row = C4::Context->select_systempreferences($name); my $value; if ( ( !defined( $row ) || ( !defined( $row->{'value'} ) && $row->{'type'} ne 'YesNo' ) ) && defined( $piece->{'default'} ) ) { $value = $piece->{'default'}; --- a/t/db_dependent/Context.t +++ a/t/db_dependent/Context.t @@ -7,7 +7,6 @@ use Test::More; use Test::MockModule; use vars qw($debug $koha $dbh $config $ret); use t::lib::Mocks; - use Koha::Database; BEGIN { --- a/t/db_dependent/sysprefs.t +++ a/t/db_dependent/sysprefs.t @@ -19,8 +19,9 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 8; +use Test::More tests => 9; use C4::Context; +use Koha::Database; # Start transaction my $dbh = C4::Context->dbh; @@ -60,4 +61,18 @@ is(C4::Context->preference('testpreference'), 'def', 'caching preferences'); C4::Context->clear_syspref_cache(); is(C4::Context->preference('testpreference'), undef, 'clearing preference cache'); +sub select_systempreferences { + my ($name) = @_; + my $schema = Koha::Database->new()->schema(); + my $syspref = $schema->resultset('Systempreference')->search( + {variable => $name} + ); + return $syspref; +} + + +my $syspref = select_systempreferences('OPACHEADER'); +is( $syspref, 1, 'correct number of syspref found'); + + $dbh->rollback; --