Bug 3814: SIP2 Server logging doesn't work on OpenSolaris
[koha.git] / C4 / Context.pm
index 99019ea..25f1a22 100644 (file)
@@ -71,7 +71,7 @@ BEGIN {
                                }       
                 print "</body></html>";
                        }
-               CGI::Carp::set_message(\&handle_errors);
+               #CGI::Carp::set_message(\&handle_errors);
                ## give a stack backtrace if KOHA_BACKTRACES is set
                ## can't rely on DebugLevel for this, as we're not yet connected
                if ($ENV{KOHA_BACKTRACES}) {
@@ -507,6 +507,37 @@ sub clear_syspref_cache {
     %sysprefs = ();
 }
 
+=head2 set_preference
+
+  C4::Context->set_preference( $variable, $value );
+
+  This updates a preference's value both in the systempreferences table and in
+  the sysprefs cache.
+
+=cut
+
+sub set_preference {
+    my $self = shift;
+    my $var = shift;
+    my $value = shift;
+
+    my $dbh = C4::Context->dbh or return 0;
+
+    my $type = $dbh->selectrow_array( "SELECT type FROM systempreferences WHERE variable = ?", {}, $var );
+
+    $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' );
+
+    my $sth = $dbh->prepare( "
+      INSERT INTO systempreferences
+        ( variable, value )
+        VALUES( ?, ? )
+        ON DUPLICATE KEY UPDATE value = VALUES(value)
+    " );
+
+    $sth->execute( $var, $value );
+    $sth->finish;
+}
+
 # AUTOLOAD
 # This implements C4::Config->foo, and simply returns
 # C4::Context->config("foo"), as described in the documentation for