From d02ca2d487098c68703f276a356245af2f9146ae Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Fri, 17 Mar 2017 23:54:02 +0000 Subject: [PATCH] Bug 18291 - Removed the SQL query out of admin/preferences.pl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Placed a subroutine into Context.pm which in turn calls Koha::Config::SysPref.pm where the SQL query has been re-written as a DBIx query Followed test plan from comment #3, works as expected Signed-off-by: Marc VĂ©ron --- 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(-) diff --git a/C4/Context.pm b/C4/Context.pm index a50ddfd..d3d57f1 100644 --- a/C4/Context.pm +++ b/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 diff --git a/Koha/Config/SysPref.pm b/Koha/Config/SysPref.pm index 1e71b8c..785bc43 100644 --- a/Koha/Config/SysPref.pm +++ b/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 diff --git a/admin/preferences.pl b/admin/preferences.pl index 032789f..5c0623a 100755 --- a/admin/preferences.pl +++ b/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'}; diff --git a/t/db_dependent/Context.t b/t/db_dependent/Context.t index bce0cef..b848579 100755 --- a/t/db_dependent/Context.t +++ b/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 { diff --git a/t/db_dependent/sysprefs.t b/t/db_dependent/sysprefs.t index 340e89a..98d0c92 100755 --- a/t/db_dependent/sysprefs.t +++ b/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; -- 2.1.4