From 71841c58b9d7f359946802e3a565a7a706e7ba3d 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 | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 0d8bce7458..712b3782a5 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 '' ); @@ -443,31 +440,13 @@ sub set_preference { $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(); - } + $self->dbh()->do("INSERT INTO systempreferencesi (variable, value, explanation, type, options) values ($variable, $value, $explanation, $type, $options) ON DUPLICATE KEY UPDATE value = '$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 +462,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