Bugzilla – Attachment 36592 Details for
Bug 11998
Syspref caching issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11998: Add Koha::Config::SystemPreference
Bug-11998-Add-KohaConfigSystemPreference.patch (text/plain), 4.61 KB, created by
Brendan Gallagher
on 2015-03-05 13:37:52 UTC
(
hide
)
Description:
Bug 11998: Add Koha::Config::SystemPreference
Filename:
MIME Type:
Creator:
Brendan Gallagher
Created:
2015-03-05 13:37:52 UTC
Size:
4.61 KB
patch
obsolete
>From 2b0d399fb90b27a3def943cf71253ea0553e5940 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Thu, 20 Nov 2014 17:14:35 +0100 >Subject: [PATCH] Bug 11998: Add Koha::Config::SystemPreference > >This (dirty) patch extract the syspref set and delete routine into a >module. >It fixes the circular dependency and the logging problem. > >Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com> >--- > C4/Context.pm | 44 ++++++++-------------------------- > Koha/Config/SystemPreference.pm | 50 +++++++++++++++++++++++++++++++++++++++ > 2 files changed, 60 insertions(+), 34 deletions(-) > create mode 100644 Koha/Config/SystemPreference.pm > >diff --git a/C4/Context.pm b/C4/Context.pm >index f021929..fc812d4 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -18,6 +18,9 @@ package C4::Context; > > use strict; > use warnings; >+ >+use Koha::Config::SystemPreference; >+ > use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached); > BEGIN { > if ($ENV{'HTTP_USER_AGENT'}) { >@@ -629,40 +632,15 @@ preference. > > sub set_preference { > my ( $self, $var, $value, $expl, $type, $options ) = @_; >- $var = lc($var); > >- my $dbh = C4::Context->dbh or return 0; >+ $var = lc $var; > >- my $db_type = $dbh->selectrow_array( >- "SELECT type FROM systempreferences WHERE variable = ?", >- {}, $var ); >+ my $set = Koha::Config::SystemPreference::set( $var, $value, $expl, $type, $options ); > >- $value = 0 if ( $db_type && $db_type eq 'YesNo' && $value eq '' ); >+ $syspref_cache->set_in_cache("syspref_$var", $value) >+ if $use_syspref_cache and $set; > >- my ( $query, @params, $logtype ); >- if ( !defined($db_type) ) { >- $query = ' >-INSERT INTO systempreferences >- ( variable, value, explanation, type, options ) >-VALUES( ?, ?, ?, ?, ? )'; >- @params = ( $var, $value, $expl, $type, $options ); >- $logtype = 'ADD'; >- } >- else { >- $query = ' >-INSERT INTO systempreferences >- ( variable, value ) >-VALUES( ?, ? ) >-ON DUPLICATE KEY UPDATE value = VALUES(value)'; >- @params = ( $var, $value ); >- $logtype = 'MODIFY'; >- } >- my $sth = $dbh->prepare($query); >- if ( $sth->execute(@params) ) { >- $syspref_cache->set_in_cache("syspref_$var", $value) if $use_syspref_cache; >- logaction( $dbh, userenv(), 'SYSTEMPREFERENCE', $logtype, undef, $var . " | " . $value ); >- } >- $sth->finish; >+ return $set; > } > > =head2 delete_preference >@@ -681,15 +659,13 @@ sub delete_preference { > # We want to log the previous value > my $val = C4::Context->preference($var); > my $dbh = C4::Context->dbh or die "Unable to talk to the database"; >- my $sth = $dbh->prepare("DELETE FROM systempreferences WHERE variable=?"); >- my $res = $sth->execute($var); >- if ($res) { >+ >+ if ( Koha::Config::SystemPreference::delete($var) ) { > $syspref_cache->clear_from_cache("syspref_$var") if $use_syspref_cache; > logaction( $dbh, userenv(), 'SYSTEMPREFERENCE', 'DELETE', undef, > $var . " | " . ( $val // 'undefined' ) ); > return 1; > } >- warn "Unable to delete syspref: " . $sth->errstr; > return 0; > } > # AUTOLOAD >diff --git a/Koha/Config/SystemPreference.pm b/Koha/Config/SystemPreference.pm >new file mode 100644 >index 0000000..791fe44 >--- /dev/null >+++ b/Koha/Config/SystemPreference.pm >@@ -0,0 +1,50 @@ >+package Koha::Config::SystemPreference; >+ >+use Koha::Database; >+use C4::Log qw( logaction ); >+ >+sub set { >+ my ( $variable, $value, $expl, $type, $options ) = @_; >+ >+ my $dbh = C4::Context->dbh or return 0; >+ >+ my $pref = Koha::Database->new->schema->resultset('Systempreference')->find($variable); >+ >+ if ( $pref ) { >+ $value = 0 if ( $pref->type && $pref->type eq 'YesNo' && $pref->type eq '' ); >+ } >+ >+ $pref = Koha::Database->new->schema->resultset('Systempreference')->update_or_new( >+ { >+ variable => $variable, >+ value => $value, >+ explanation => $expl, >+ type => $type, >+ options => $options, >+ } >+ ); >+ >+ if ( $pref->in_storage ) { >+ logaction('SYSTEMPREFERENCE', 'MODIFY', undef, $variable . ' | ' . $value); >+ return 1; >+ } >+ >+ my $inserted = $pref->insert; >+ logaction('SYSTEMPREFERENCE', 'ADD', undef, $variable . ' | ' . $value) if $inserted; >+ >+ return $inserted; >+} >+ >+sub delete { >+ my ( $variable ) = @_; >+ >+ my $deleted = Koha::Database->new->schema->resultset('Systempreference')->find($variable)->delete; >+ >+ return unless $deleted; >+ >+ logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring ); >+ >+ return 1 >+} >+ >+1 >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11998
:
26575
|
26621
|
26714
|
26716
|
26717
|
27382
|
31801
|
31802
|
32870
|
32871
|
32872
|
32873
|
32874
|
33183
|
33447
|
33670
|
33671
|
33685
|
33724
|
33725
|
33746
|
33829
|
33940
|
36523
|
36524
|
36525
|
36526
|
36527
|
36528
|
36529
|
36530
|
36531
|
36532
|
36533
|
36534
|
36571
|
36583
|
36584
|
36585
|
36586
|
36587
|
36588
|
36589
|
36590
|
36591
|
36592
|
36593
|
36594
|
36595
|
48640
|
48652
|
48655
|
48687
|
48688
|
48727
|
48758
|
48928
|
48929
|
48930
|
48931
|
48932
|
48933
|
48934
|
48935
|
48936
|
48961
|
49022
|
49023
|
49024
|
49025
|
49026
|
49027
|
49028
|
49029
|
49030
|
49100
|
49101
|
49102
|
49103
|
49104
|
49105
|
49106
|
49107
|
49108