use strict;
use warnings;
use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached);
+use Koha::Cache;
+use Carp;
BEGIN {
if ($ENV{'HTTP_USER_AGENT'}) {
use C4::Debug;
use POSIX ();
use DateTime::TimeZone;
+use Module::Load::Conditional qw(can_load);
=head1 NAME
do $cgidir."/kohaversion.pl" || die "NO $cgidir/kohaversion.pl";
return kohaversion();
}
+
+=head2 final_linear_version
+
+Returns the version number of the final update to run in updatedatabase.pl.
+This number is equal to the version in kohaversion.pl
+
+=cut
+
+sub final_linear_version {
+ return KOHAVERSION;
+}
+
=head2 read_config_file
Reads the specified Koha config file.
# FIXME: running this under mod_perl will require a means of
# flushing the caching mechanism.
-my %sysprefs;
+my $sysprefs;
my $use_syspref_cache = 1;
+my $cache;
sub preference {
my $self = shift;
my $var = lc(shift); # The system preference to return
- if ($use_syspref_cache && exists $sysprefs{$var}) {
- return $sysprefs{$var};
+ unless (defined $sysprefs) {
+ unless ($cache) {
+ $cache = Koha::Cache->new();
+ }
+ $sysprefs = $cache->create_hash(
+ {
+ 'key' => 'syspref',
+ 'allowupdate' => 1,
+ 'cache_type' => $use_syspref_cache ? '' : 'null',
+ 'preload' => sub {
+ my $dbh = C4::Context->dbh or return {};
+ my $vars = $dbh->selectall_arrayref("SELECT variable, value FROM systempreferences");
+ my %sysprefs = ();
+ foreach my $row (@$vars) {
+ $sysprefs{$row->[0]} = $row->[1];
+ }
+ return \%sysprefs;
+ },
+ 'constructor' => sub {
+
+ # Look up systempreferences.variable==$var
+ my $var = pop;
+ my $sysprefs = pop || {};
+ my $dbh = C4::Context->dbh or return 0;
+ my $sql =
+"SELECT value FROM systempreferences WHERE variable=? LIMIT 1";
+ $ENV{DEBUG} && carp "Retrieving syspref $var from database";
+ my $sth = $dbh->prepare_cached($sql);
+ $sth->execute($var);
+ my $res = $sth->fetchrow_hashref;
+ if ($res && $res->{'value'}) {
+ $sysprefs->{$var} = $res->{'value'};
+ } else {
+ $sysprefs->{$var} = '';
+ }
+ return $sysprefs;
+ },
+ }
+ );
}
-
- 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};
+ return $sysprefs->{$var};
}
sub boolean_preference {
sub disable_syspref_cache {
my ($self) = @_;
$use_syspref_cache = 0;
- $self->clear_syspref_cache();
+ $self->clear_syspref_cache() if defined($sysprefs);
}
=head2 clear_syspref_cache
=cut
sub clear_syspref_cache {
- %sysprefs = ();
+ %{$sysprefs} = ();
+ return;
}
=head2 set_preference
" );
if($sth->execute( $var, $value )) {
- $sysprefs{$var} = $value;
+ $sysprefs->{$var} = $value;
}
$sth->finish;
}
# return something, then this function should, too.
}
+=head2 queryparser
+
+ $queryparser = C4::Context->queryparser
+
+Returns a handle to an initialized Koha::QueryParser::Driver::PQF object.
+
+=cut
+
+sub queryparser {
+ my $self = shift;
+ unless (defined $context->{"queryparser"}) {
+ $context->{"queryparser"} = &_new_queryparser();
+ }
+
+ return
+ defined( $context->{"queryparser"} )
+ ? $context->{"queryparser"}->new
+ : undef;
+}
+
+=head2 _new_queryparser
+
+Internal helper function to create a new QueryParser object. QueryParser
+is loaded dynamically so as to keep the lack of the QueryParser library from
+getting in anyone's way.
+
+=cut
+
+sub _new_queryparser {
+ my $qpmodules = {
+ 'OpenILS::QueryParser' => undef,
+ 'Koha::QueryParser::Driver::PQF' => undef
+ };
+ if ( can_load( 'modules' => $qpmodules ) ) {
+ my $QParser = Koha::QueryParser::Driver::PQF->new();
+ my $config_file = $context->config('queryparser_config');
+ $config_file ||= '/etc/koha/searchengine/queryparser.yaml';
+ if ( $QParser->load_config($config_file) ) {
+ # TODO: allow indexes to be configured in the database
+ return $QParser;
+ }
+ }
+ return;
+}
+
=head2 marcfromkohafield
$dbh = C4::Context->marcfromkohafield;
#'
sub userenv {
my $var = $context->{"activeuser"};
- return $context->{"userenv"}->{$var} if (defined $var and defined $context->{"userenv"}->{$var});
- # insecure=1 management
- if ($context->{"dbh"} && $context->preference('insecure') eq 'yes') {
- my %insecure;
- $insecure{flags} = '16382';
- $insecure{branchname} ='Insecure';
- $insecure{number} ='0';
- $insecure{cardnumber} ='0';
- $insecure{id} = 'insecure';
- $insecure{branch} = 'INS';
- $insecure{emailaddress} = 'test@mode.insecure.com';
- return \%insecure;
+ if (defined $var and defined $context->{"userenv"}->{$var}) {
+ return $context->{"userenv"}->{$var};
} else {
return;
}
=head2 set_userenv
C4::Context->set_userenv($usernum, $userid, $usercnum, $userfirstname,
- $usersurname, $userbranch, $userflags, $emailaddress);
+ $usersurname, $userbranch, $userflags, $emailaddress, $branchprinter,
+ $persona);
Establish a hash of user environment variables.
#'
sub set_userenv {
- my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
+ my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona)= @_;
my $var=$context->{"activeuser"} || '';
my $cell = {
"number" => $usernum,
"branchname" => $branchname,
"flags" => $userflags,
"emailaddress" => $emailaddress,
- "branchprinter" => $branchprinter
+ "branchprinter" => $branchprinter,
+ "persona" => $persona,
};
$context->{userenv}->{$var} = $cell;
return $cell;