From f729e5abf57ba1e52b679791f4cfdf14cc8a6435 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 24 May 2013 06:56:50 -0400 Subject: [PATCH] Bug 10325 - Allow system preferences to be overridable from koha-httpd.conf Content-Type: text/plain; charset=utf-8 For Koha installations with multiple OPAC URLs, It would be nice to be able to override systeprefs from the http conf file. Case in point, a library wants to have two separate opacs, one the is only viewable from within the library that allows patrons to place holds, and a second public one that does not. In this case, overriding the system preference RequestOnOpac would accomplish this simply, and with no ill affects. This feature would of course be should only be used to override cosmetic effects on the system, and should not be used for system preferences such as CircControl, but would be great for preferences such as OpacStarRatings, opacuserjs, OpacHighlightedWords and many others! Test Plan: 1) Apply this patch 2) Disable the system pref OpacHighlightedWords 3) Do a seach in the OPAC, not the term is not highlighted 4) Edit your koha-http.conf file, add the line SetEnv OVERRIDE_SYSPREF_OpacHighlightedWords "1" to your koha-http.conf file's OPAC section. Also add the line SetEnv OVERRIDE_SYSPREF_NAMES "OpacHighlightedWords" to the Intranet section 5) Restart your web server, or just reload it's config 6) Do a seach, now your search term should be highlighted! 7) From the intranet preference editor, view the pref, You should see a warning the this preference has been overridden. Signed-off-by: Marcel de Rooy --- C4/Context.pm | 27 ++++++++++++------- admin/preferences.pl | 5 +++- etc/koha-httpd.conf | 12 +++++++++ .../intranet-tmpl/prog/en/css/preferences.css | 8 +++++- .../prog/en/modules/admin/preferences.tt | 6 ++++ 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 7709f7e..7bc7097 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -540,7 +540,7 @@ my $use_syspref_cache = 1; sub preference { my $self = shift; - my $var = lc(shift); # The system preference to return + my $var = shift; # The system preference to return if ($use_syspref_cache && exists $sysprefs{$var}) { return $sysprefs{$var}; @@ -548,15 +548,22 @@ sub preference { my $dbh = C4::Context->dbh or return 0; - # Look up systempreferences.variable==$var - my $sql = <<'END_SQL'; - SELECT value - FROM systempreferences - WHERE variable=? - LIMIT 1 -END_SQL - $sysprefs{$var} = $dbh->selectrow_array( $sql, {}, $var ); - return $sysprefs{$var}; + my $value; + if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) { + $value = $ENV{"OVERRIDE_SYSPREF_$var"}; + } else { + # Look up systempreferences.variable==$var + my $sql = q{ + SELECT value + FROM systempreferences + WHERE variable = ? + LIMIT 1 + }; + $value = $dbh->selectrow_array( $sql, {}, $var ); + } + + $sysprefs{$var} = $value; + return $value; } sub boolean_preference { diff --git a/admin/preferences.pl b/admin/preferences.pl index db91e76..e144613 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -33,6 +33,7 @@ use C4::Budgets qw(GetCurrency); use File::Spec; use IO::File; use YAML::Syck qw(); +use List::MoreUtils qw(any); $YAML::Syck::ImplicitTyping = 1; our $lang; @@ -120,6 +121,8 @@ sub TransformPrefsToHTML { my $tab = $data->{ $title }; $tab = { '' => $tab } if ( ref( $tab ) eq 'ARRAY' ); + my @override_syspref_names = split( /,/, $ENV{"OVERRIDE_SYSPREF_NAMES"} ); + foreach my $group ( sort keys %$tab ) { if ( $group ) { push @lines, { is_group_title => 1, title => $group }; @@ -156,6 +159,7 @@ sub TransformPrefsToHTML { $name_entry->{'highlighted'} = 1; } } + $name_entry->{'overridden'} = 1 if ( any { $name eq $_ } @override_syspref_names ); push @names, $name_entry; } else { push @chunks, $piece; @@ -164,7 +168,6 @@ sub TransformPrefsToHTML { push @chunks, { type_text => 1, contents => $piece }; } } - push @lines, { CHUNKS => \@chunks, NAMES => \@names, is_group_title => 0 }; } } diff --git a/etc/koha-httpd.conf b/etc/koha-httpd.conf index dd5ec41..6233c9d 100644 --- a/etc/koha-httpd.conf +++ b/etc/koha-httpd.conf @@ -20,6 +20,13 @@ SetEnv MEMCACHED_SERVERS "__MEMCACHED_SERVERS__" SetEnv MEMCACHED_NAMESPACE "__MEMCACHED_NAMESPACE__" + # This syntax allows you to override a system preference + # for a given virtual host. Use with caution! + # You should add all the system preferences you override + # in one or more vhosts to the environment variable + # OVERRIDE_SYSPREF_NAMES for your staff intranet vhost +# SevEnv OVERRIDE_SYSPREF_PrefName + Options -Indexes @@ -126,6 +133,11 @@ SetEnv MEMCACHED_NAMESPACE "__MEMCACHED_NAMESPACE__" Options +FollowSymLinks + # If you are overriding any system preferences, + # list them in this variable so the preference editor + # knows that they have been overridden. +# SevEnv OVERRIDE_SYSPREF_NAMES "Pref1,Pref2,Pref3" + ErrorDocument 400 /cgi-bin/koha/errors/400.pl ErrorDocument 401 /cgi-bin/koha/errors/401.pl ErrorDocument 403 /cgi-bin/koha/errors/403.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/preferences.css b/koha-tmpl/intranet-tmpl/prog/en/css/preferences.css index d9f8e16..c714718 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/preferences.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/preferences.css @@ -82,4 +82,10 @@ h3.collapsed { background: transparent url("../../img/spinner-small.gif") top left no-repeat; padding : 0 4px; vertical-align: middle; -} \ No newline at end of file +} + +span.overridden { + font-style: italic; + font-weight: bold; + color: red; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index be7ed9f..9e89538 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -89,6 +89,12 @@ [% ELSE %] [% NAME.name %] [% END %] + + [% IF NAME.overridden %] + + [Overridden] + + [% END %] [% UNLESS ( loop.last ) %]
[% END %] [% END %] -- 1.7.7.6