+=item clear_syspref_cache
+
+ C4::Context->clear_syspref_cache();
+
+ cleans the internal cache of sysprefs. Please call this method if
+ you update the systempreferences table. Otherwise, your new changes
+ will not be seen by this process.
+
+=cut
+
+sub clear_syspref_cache {
+ %sysprefs = ();
+}
+
+=item 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;
+}
+