From 72ba1f21d00b53a21156b94c1a2664104cd9281d Mon Sep 17 00:00:00 2001 From: Blou Date: Thu, 26 Oct 2023 13:52:54 -0400 Subject: [PATCH] Bug 28410: remove Koha::Config::Syspref(s) from C4::Context Use straigth SQL queries to access systempreferences instead of relying on the ORM, thus removing all direct and indirect dependencies to Koha::Object --- C4/Context.pm | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 0d8bce7458..7b45fe8c0d 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -41,9 +41,8 @@ use File::Spec; use List::MoreUtils qw(any); use Koha::Caches; -use Koha::Config::SysPref; -use Koha::Config::SysPrefs; use Koha::Config; +use Koha::Database; use Koha; =head1 NAME @@ -316,9 +315,7 @@ sub preference { return $cached_var if defined $cached_var; } - my $syspref; - eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; - my $value = $syspref ? $syspref->value() : undef; + my ($value) = $self->dbh()->selectrow_array("SELECT value FROM systempreferences WHERE variable like '$var'"); if ( $use_syspref_cache ) { my $syspref_cache = Koha::Caches->get_instance('syspref'); @@ -430,10 +427,10 @@ sub set_preference { my $variable_case = $variable; $variable = lc $variable; - my $syspref = Koha::Config::SysPrefs->find($variable); + my ($oldvalue, $oldtype) = $self->dbh()->selectrow_array("SELECT value FROM systempreferences WHERE variable like '$variable'"); $type = $type ? $type - : $syspref ? $syspref->type + : defined $oldtype ? $oldtype : undef; $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' ); @@ -442,32 +439,15 @@ sub set_preference { if ( $variable eq 'opacbaseurl' && $value && substr( $value, 0, 4 ) !~ /http/ ) { $value = 'http://' . $value; } - - if ($syspref) { - $syspref->set( - { ( defined $value ? ( value => $value ) : () ), - ( $explanation ? ( explanation => $explanation ) : () ), - ( $type ? ( type => $type ) : () ), - ( $options ? ( options => $options ) : () ), - } - )->store; - } else { - $syspref = Koha::Config::SysPref->new( - { variable => $variable_case, - value => $value, - explanation => $explanation || undef, - type => $type, - options => $options || undef, - } - )->store(); - } + + my $sth = $self->dbh()->prepare("INSERT INTO systempreferences (variable, value, explanation, type, options) values (?,?,?,?,?) ON DUPLICATE KEY UPDATE value = ?"); + $sth->execute($variable, $value, $explanation || '', $type || '', $options || '', $value); if ( $use_syspref_cache ) { my $syspref_cache = Koha::Caches->get_instance('syspref'); $syspref_cache->set_in_cache( "syspref_$variable", $value ); } - return $syspref; } =head2 delete_preference @@ -483,15 +463,11 @@ was no syspref of the name. sub delete_preference { my ( $self, $var ) = @_; - if ( Koha::Config::SysPrefs->find( $var )->delete ) { - if ( $use_syspref_cache ) { - my $syspref_cache = Koha::Caches->get_instance('syspref'); - $syspref_cache->clear_from_cache("syspref_$var"); - } - - return 1; + my $rc = $self->dbh()->do("DELETE FROM systempreferences WHERE variable like '$var'"); + if ( $use_syspref_cache ) { + my $syspref_cache = Koha::Caches->get_instance('syspref'); + $syspref_cache->clear_from_cache("syspref_$var"); } - return 0; } =head2 csv_delimiter -- 2.34.1