$ismemcached = $memcached->set('ismemcached','1');
}
- $VERSION = '3.00.00.036';
+ $VERSION = '3.07.00.049';
}
use DBI;
use C4::Boolean;
use C4::Debug;
use POSIX ();
+use DateTime::TimeZone;
=head1 NAME
if ($ismemcached) {
return $memcached;
} else {
- return undef;
+ return;
}
}
if (/Postgres|Pg|PostgresSQL/) { return("Pg"); }
if (/oracle/) { return("Oracle"); }
}
- return undef; # Just in case
+ return; # Just in case
}
sub import {
$conf_fname = CONFIG_FNAME;
} else {
warn "unable to locate Koha configuration file koha-conf.xml";
- return undef;
+ return;
}
}
$self->{"config_file"} = $conf_fname;
warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"});
- return undef if !defined($self->{"config"});
+ return if !defined($self->{"config"});
$self->{"dbh"} = undef; # Database handle
$self->{"Zconn"} = undef; # Zebra Connections
$self->{"userenv"} = undef; # User env
$self->{"activeuser"} = undef; # current active user
$self->{"shelves"} = undef;
+ $self->{tz} = undef; # local timezone object
bless $self, $class;
return $self;
=cut
-sub _common_config ($$) {
+sub _common_config {
my $var = shift;
my $term = shift;
- return undef if !defined($context->{$term});
+ return if !defined($context->{$term});
# Presumably $self->{$term} might be
# undefined if the config file given to &new
# didn't exist, and the caller didn't bother
# flushing the caching mechanism.
my %sysprefs;
+my $use_syspref_cache = 1;
sub preference {
my $self = shift;
my $var = lc(shift); # The system preference to return
- if (exists $sysprefs{$var}) {
+ if ($use_syspref_cache && exists $sysprefs{$var}) {
return $sysprefs{$var};
}
return $sysprefs{$var};
}
-sub boolean_preference ($) {
+sub boolean_preference {
my $self = shift;
my $var = shift; # The system preference to return
my $it = preference($self, $var);
return defined($it)? C4::Boolean::true_p($it): undef;
}
+=head2 enable_syspref_cache
+
+ C4::Context->enable_syspref_cache();
+
+Enable the in-memory syspref cache used by C4::Context. This is the
+default behavior.
+
+=cut
+
+sub enable_syspref_cache {
+ my ($self) = @_;
+ $use_syspref_cache = 1;
+}
+
+=head2 disable_syspref_cache
+
+ C4::Context->disable_syspref_cache();
+
+Disable the in-memory syspref cache used by C4::Context. This should be
+used with Plack and other persistent environments.
+
+=cut
+
+sub disable_syspref_cache {
+ my ($self) = @_;
+ $use_syspref_cache = 0;
+ $self->clear_syspref_cache();
+}
+
=head2 clear_syspref_cache
C4::Context->clear_syspref_cache();
$context->{"Zconn"}->{$server}->destroy() if defined($context->{"Zconn"}->{$server});
$context->{"Zconn"}->{$server} = &_new_Zconn($server,$async,$auth,$piggyback,$syntax);
+ $context->{ Zconn }->{ $server }->option(
+ preferredRecordSyntax => C4::Context->preference("marcflavour") );
return $context->{"Zconn"}->{$server};
}
}
#'
sub set_userenv {
my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
- my $var=$context->{"activeuser"};
+ my $var=$context->{"activeuser"} || '';
my $cell = {
"number" => $usernum,
"id" => $userid,
return $cell;
}
-sub set_shelves_userenv ($$) {
- my ($type, $shelves) = @_ or return undef;
- my $activeuser = $context->{activeuser} or return undef;
+sub set_shelves_userenv {
+ my ($type, $shelves) = @_ or return;
+ my $activeuser = $context->{activeuser} or return;
$context->{userenv}->{$activeuser}->{barshelves} = $shelves if $type eq 'bar';
$context->{userenv}->{$activeuser}->{pubshelves} = $shelves if $type eq 'pub';
$context->{userenv}->{$activeuser}->{totshelves} = $shelves if $type eq 'tot';
}
-sub get_shelves_userenv () {
+sub get_shelves_userenv {
my $active;
unless ($active = $context->{userenv}->{$context->{activeuser}}) {
$debug and warn "get_shelves_userenv cannot retrieve context->{userenv}->{context->{activeuser}}";
- return undef;
+ return;
}
my $totshelves = $active->{totshelves} or undef;
my $pubshelves = $active->{pubshelves} or undef;
}
+=head2 tz
+
+ C4::Context->tz
+
+ Returns a DateTime::TimeZone object for the system timezone
+
+=cut
+
+sub tz {
+ my $self = shift;
+ if (!defined $context->{tz}) {
+ $context->{tz} = DateTime::TimeZone->new(name => 'local');
+ }
+ return $context->{tz};
+}
+
+
+
1;
__END__