Bug 10325 - Allow system preferences to be overridable from koha-httpd.conf
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 24 May 2013 10:56:50 +0000 (06:56 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Sun, 8 Sep 2013 02:09:53 +0000 (02:09 +0000)
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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

C4/Context.pm
admin/preferences.pl
etc/koha-httpd.conf
koha-tmpl/intranet-tmpl/prog/en/css/preferences.css
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt

index 7709f7e..7bc7097 100644 (file)
@@ -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 {
index 09d648f..8636afe 100755 (executable)
@@ -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 };
         }
     }
index dd5ec41..6233c9d 100644 (file)
    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
+
    <Directory "__OPAC_WWW_DIR__">
       Options -Indexes
    </Directory>
    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
index d9f8e16..c714718 100644 (file)
@@ -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;
+}
index be7ed9f..9e89538 100644 (file)
                                                        [% ELSE %]
                                                        [% NAME.name %]
                                                        [% END %]
+
+                            [% IF NAME.overridden %]
+                                <span class="overridden" title="The system preference [% NAME.name %] been overridden from this value by one or more virtual hosts.">
+                                    [Overridden]
+                                </span>
+                            [% END %]
                                                </label>
                         [% UNLESS ( loop.last ) %]<br />[% END %]
                         [% END %]