[Koha-cvs] koha/C4 Context.pm [rel_3_0]
Antoine Farnault
antoine at koha-fr.org
Fri Oct 6 15:47:28 CEST 2006
CVSROOT: /sources/koha
Module name: koha
Branch: rel_3_0
Changes by: Antoine Farnault <toins> 06/10/06 13:47:28
Modified files:
C4 : Context.pm
Log message:
Synch with dev_week.
/!\ WARNING :: Please now use the new version of koha.xml.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Context.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.43&r2=1.43.2.1
Patches:
Index: Context.pm
===================================================================
RCS file: /sources/koha/koha/C4/Context.pm,v
retrieving revision 1.43
retrieving revision 1.43.2.1
diff -u -b -r1.43 -r1.43.2.1
--- Context.pm 10 Aug 2006 12:49:37 -0000 1.43
+++ Context.pm 6 Oct 2006 13:47:28 -0000 1.43.2.1
@@ -1,3 +1,4 @@
+package C4::Context;
# Copyright 2002 Katipo Communications
#
# This file is part of Koha.
@@ -15,17 +16,19 @@
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
-# $Id: Context.pm,v 1.43 2006/08/10 12:49:37 toins Exp $
-package C4::Context;
+# $Id: Context.pm,v 1.43.2.1 2006/10/06 13:47:28 toins Exp $
use strict;
use DBI;
-use C4::Boolean;
+use ZOOM;
use XML::Simple;
+
+use C4::Boolean;
+
use vars qw($VERSION $AUTOLOAD),
qw($context),
qw(@context_stack);
-$VERSION = do { my @v = '$Revision: 1.43 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.43.2.1 $' =~ /\d+/g;
shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
=head1 NAME
@@ -39,7 +42,13 @@
use C4::Context("/path/to/koha.xml");
$config_value = C4::Context->config("config_variable");
+
+ $koha_preference = C4::Context->preference("preference");
+
$db_handle = C4::Context->dbh;
+
+ $Zconn = C4::Context->Zconn;
+
$stopwordhash = C4::Context->stopwords;
=head1 DESCRIPTION
@@ -97,38 +106,46 @@
$context = undef; # Initially, no context is set
@context_stack = (); # Initially, no saved contexts
-# read_config_file
-# Reads the specified Koha config file. Returns a reference-to-hash
-# whose keys are the configuration variables, and whose values are the
-# configuration values (duh).
-# Returns undef in case of error.
-#
-# Revision History:
-# 2004-08-10 A. Tarallo: Added code that checks if a variable is already
-# assigned and prints a message, otherwise create a new entry in the hash to
-# be returned.
-# Also added code that complaints if finds a line that isn't a variable
-# assignmet and skips the line.
-# Added a quick hack that makes the translation between the db_schema
-# and the DBI driver for that schema.
-#
-sub read_config_file
-{
- my $fname = shift; # Config file to read
+=item read_config_file
+
+=over 4
+
+Reads the specified Koha config file.
+
+Returns an object containing the configuration variables. The object's
+structure is a bit complex to the uninitiated ... take a look at the
+koha.xml file as well as the XML::Simple documentation for details. Or,
+here are a few examples that may give you what you need:
+
+The simple elements nested within the <config> element:
- my $retval = {}; # Return value: ref-to-hash holding the
- # configuration
+ my $pass = $koha->{'config'}->{'pass'};
-my $koha = XMLin($fname, keyattr => ['id'],forcearray => ['listen']);
+The <listen> elements:
+ my $listen = $koha->{'listen'}->{'biblioserver'}->{'content'};
+
+The elements nested within the <server> element:
+
+ my $ccl2rpn = $koha->{'server'}->{'biblioserver'}->{'cql2rpn'};
+
+Returns undef in case of error.
+
+=back
+
+=cut
+
+sub read_config_file {
+ my $fname = shift; # Config file to read
+ my $retval = {}; # Return value: ref-to-hash holding the configuration
+ my $koha = XMLin($fname, keyattr => ['id'],forcearray => ['listen']);
return $koha;
}
# db_scheme2dbi
# Translates the full text name of a database into de appropiate dbi name
#
-sub db_scheme2dbi
-{
+sub db_scheme2dbi {
my $name = shift;
for ($name) {
@@ -140,8 +157,7 @@
return undef; # Just in case
}
-sub import
-{
+sub import {
my $package = shift;
my $conf_fname = shift; # Config file name
my $context;
@@ -170,8 +186,7 @@
#'
# Revision History:
# 2004-08-10 A. Tarallo: Added check if the conf file is not empty
-sub new
-{
+sub new {
my $class = shift;
my $conf_fname = shift; # Config file to load
my $self = {};
@@ -190,14 +205,11 @@
$self = read_config_file($conf_fname);
$self->{"config_file"} = $conf_fname;
-
-
warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"});
return undef if !defined($self->{"config"});
$self->{"dbh"} = undef; # Database handle
$self->{"Zconn"} = undef; # Zebra Connection
- $self->{"Zconnauth"} = undef; # Zebra Connection for updating
$self->{"stopwords"} = undef; # stopwords list
$self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
$self->{"userenv"} = undef; # User env
@@ -311,12 +323,6 @@
# Return the value of the requested config variable
return $context->{"config"}->{$var};
}
-=item zebraconfig
-$serverdir=C4::Context->zebraconfig("biblioserver")->{directory};
-
-returns the zebra server specific details for different zebra servers
-similar to C4:Context->config
-=cut
sub zebraconfig
{
@@ -324,6 +330,11 @@
my $var = shift; # The config variable to return
return undef if !defined($context->{"server"});
+ # Presumably $self->{config} might be
+ # undefined if the config file given to &new
+ # didn't exist, and the caller didn't bother
+ # to check the return value.
+
# Return the value of the requested config variable
return $context->{"server"}->{$var};
}
@@ -387,117 +398,112 @@
=item Zconn
$Zconn = C4::Context->Zconn
-$Zconnauth = C4::Context->Zconnauth
+
Returns a connection to the Zebra database for the current
context. If no connection has yet been made, this method
creates one and connects.
+C<$self>
+
+C<$server> one of the servers defined in the koha.xml file
+
+C<$async> whether this is a asynchronous connection
+
+C<$auth> whether this connection has rw access (1) or just r access (0 or NULL)
+
+
=cut
sub Zconn {
- my $self = shift;
-my $server=shift;
- my $Zconn;
- if (defined($context->{"Zconn"})) {
- $Zconn = $context->{"Zconn"};
+ my $self=shift;
+ my $server=shift;
+ my $async=shift;
+ my $auth=shift;
+ my $piggyback=shift;
+ my $syntax=shift;
+
+ if ( defined($context->{"Zconn"}) ) {
return $context->{"Zconn"};
+
+ # No connection object or it died. Create one.
} else {
- $context->{"Zconn"} = &new_Zconn($server);
+ $context->{"Zconn"} = &_new_Zconn($server,$async,$auth,$piggyback,$syntax);
return $context->{"Zconn"};
}
}
-sub Zconnauth {
- my $self = shift;
- my $server="biblioserver"; #shift;
- my $Zconnauth;
- if (defined($context->{"Zconnauth"})) {
- $Zconnauth = $context->{"Zconnauth"};
- return $context->{"Zconnauth"};
- } else {
- $context->{"Zconnauth"} = &new_Zconnauth($server);
- return $context->{"Zconnauth"};
- }
-}
+=item _new_Zconn
+
+$context->{"Zconn"} = &_new_Zconn($server,$async);
+Internal function. Creates a new database connection from the data given in the current context and returns it.
+C<$server> one of the servers defined in the koha.xml file
-=item new_Zconn
+C<$async> whether this is a asynchronous connection
-Internal helper function. creates a new database connection from
-the data given in the current context and returns it.
+C<$auth> whether this connection has rw access (1) or just r access (0 or NULL)
=cut
-sub new_Zconn {
-use ZOOM;
-my $server=shift;
-my $tried=0;
-my $Zconn;
-my ($tcp,$host,$port)=split /:/,$context->{"listen"}->{$server}->{"content"};
+sub _new_Zconn {
+ my ($server,$async,$auth,$piggyback,$syntax) = @_;
+
+ my $tried=0; # first attempt
+ my $Zconn; # connection object
+ $server = "biblioserver" unless $server;
+ $syntax = "usmarc" unless $syntax;
-retry:
+ my $host = $context->{'listen'}->{$server}->{'content'};
+ my $user = $context->{"serverinfo"}->{$server}->{"user"};
+ my $password = $context->{"serverinfo"}->{$server}->{"password"};
+
+ retry:
eval {
- $Zconn=new ZOOM::Connection($context->config("hostname"),$port,databaseName=>$context->{"config"}->{$server},
- preferredRecordSyntax => "USmarc",elementSetName=> "F");
- $Zconn->option(cqlfile=> $context->{"config"}->{"zebradir"}."/etc/cql.properties");
- $Zconn->option(cclfile=> $context->{"config"}->{"zebradir"}."/etc/ccl.properties");
+ # set options
+ my $o = new ZOOM::Options();
+ $o->option(async => 1) if $async;
+ $o->option(count => $piggyback) if $piggyback;
+ $o->option(cqlfile=> $context->{"server"}->{$server}->{"cql2rpn"});
+ $o->option(cclfile=> $context->{"serverinfo"}->{$server}->{"ccl2rpn"});
+ $o->option(preferredRecordSyntax => $syntax);
+ $o->option(elementSetName => "F"); # F for 'full' as opposed to B for 'brief'
+ $o->option(user=>$user) if $auth;
+ $o->option(password=>$password) if $auth;
+ $o->option(databaseName => "biblios"); #$context->{"config"}->{$server});
+
+ # create a new connection object
+ $Zconn= create ZOOM::Connection($o);
+
+ # forge to server
+ $Zconn->connect($host, 0);
+
+ # check for errors and warn
+ if ($Zconn->errcode() !=0) {
+ warn "something wrong with the connection: ". $Zconn->errmsg();
+ }
+
};
- if ($@){
-###Uncomment the lines below if you want to automatically restart your zebra if its stop
-###The system call is for Windows it should be changed to unix deamon starting for Unix platforms
-# if ($@->code==10000 && $tried==0){ ##No connection try restarting Zebra
-# $tried==1;
-# my $res=system('sc start "Z39.50 Server" >c:/zebraserver/error.log');
-# goto "retry";
-# }else{
+ if ($@) {
+ # Koha manages the Zebra server -- this doesn't work currently for me because of permissions issues
+ # Also, I'm skeptical about whether it's the best approach anyway
+ warn "problem with Zebra";
+ if ( C4::Context->preference("ManageZebra") ) {
+ if ($@->code==10000 && $tried==0) { ##No connection try restarting Zebra
+ $tried=1;
+ warn "trying to restart Zebra";
+ my $res=system("zebrasrv -f $ENV{'KOHA_CONF'} >/koha/log/zebra-error.log");
+ goto "retry";
+ } else {
warn "Error ", $@->code(), ": ", $@->message(), "\n";
$Zconn="error";
return $Zconn;
-# }
}
-
- return $Zconn;
-}
-
-## Zebra handler with write permission
-sub new_Zconnauth {
-use ZOOM;
-my $server=shift;
-my $tried=0;
-my $Zconnauth;
-my ($tcp,$host,$port)=split /:/,$context->{"listen"}->{$server}->{"content"};
- my $o = new ZOOM::Options();
- $o->option(async => 1);
- $o->option(preferredRecordSyntax => "usmarc");
- $o->option(elementSetName => "F");
- $o->option(user=>$context->{"config"}->{"zebrauser"});
- $o->option(password=>$context->{"config"}->{"zebrapass"});
- $o->option(databaseName=>$context->{"config"}->{$server});
-
-retry:
-eval{
- $Zconnauth=new ZOOM::Connection($context->config("hostname"),$port,databaseName=>$context->{"config"}->{$server},
- user=>$context->{"config"}->{"zebrauser"},
- password=>$context->{"config"}->{"zebrapass"},preferredRecordSyntax => "USmarc",elementSetName=> "F");
-};
- if ($@){
-###Uncomment the lines below if you want to automatically restart your zebra if its stop
-###The system call is for Windows it should be changed to unix deamon starting for Unix platforms
-# if ($@->code==10000 && $tried==0){ ##No connection try restarting Zebra
-# $tried==1;
-# my $res=system('sc start "Z39.50 Server" >c:/zebraserver/error.log');
-# goto "retry";
-# }else{
- warn "Error ", $@->code(), ": ", $@->message(), "\n";
- $Zconnauth="error";
- return $Zconnauth;
-# }
}
- return $Zconnauth;
+ }
+ return $Zconn;
}
-
# _new_dbh
# Internal helper function (not a method!). This creates a new
# database connection from the data given in the current context, and
@@ -754,7 +760,7 @@
=cut
#'
sub set_userenv{
- my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress,$branchprinter)= @_;
+ my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress)= @_;
my $var=$context->{"activeuser"};
my $cell = {
"number" => $usernum,
@@ -767,7 +773,6 @@
"branchname" => $branchname,
"flags" => $userflags,
"emailaddress" => $emailaddress,
- "branchprinter" => $branchprinter,
};
$context->{userenv}->{$var} = $cell;
return $cell;
@@ -828,42 +833,75 @@
=head1 SEE ALSO
-DBI(3)
-
-=head1 AUTHOR
+=head1 AUTHORS
Andrew Arensburger <arensb at ooblick dot com>
+Joshua Ferraro <jmf at liblime dot com>
+
=cut
# $Log: Context.pm,v $
-# Revision 1.43 2006/08/10 12:49:37 toins
-# sync with dev_week.
-#
-# Revision 1.42 2006/07/04 14:36:51 toins
-# Head & rel_2_2 merged
-#
-# Revision 1.41 2006/05/20 14:36:09 tgarip1957
-# Typo error. Missing '>'
-#
-# Revision 1.40 2006/05/20 14:28:02 tgarip1957
-# Adding support to read zebra database name from config files
-#
-# Revision 1.39 2006/05/19 09:52:54 alaurin
-# committing new feature ip and printer management
-# adding two fields in branches table (branchip,branchprinter)
-#
-# branchip : if the library enter an ip or ip range any librarian that connect from computer in this ip range will be temporarly affected to the corresponding branch .
-#
-# branchprinter : the library can select a default printer for a branch
-#
-# Revision 1.38 2006/05/14 00:22:31 tgarip1957
-# Adding support for getting details of different zebra servers
-#
-# Revision 1.37 2006/05/13 19:51:39 tgarip1957
-# Now reads koha.xml rather than koha.conf.
-# koha.xml contains both the koha configuration and zebraserver configuration.
-# Zebra connection is modified to allow connection to authority zebra as well.
-# It will break head if koha.conf is not replaced with koha.xml
+# Revision 1.43.2.1 2006/10/06 13:47:28 toins
+# Synch with dev_week.
+# /!\ WARNING :: Please now use the new version of koha.xml.
+#
+# Revision 1.18.2.5.2.14 2006/09/24 15:24:06 kados
+# remove Zebraauth routine, fold the functionality into Zconn
+# Zconn can now take several arguments ... this will probably
+# change soon as I'm not completely happy with the readability
+# of the current format ... see the POD for details.
+#
+# cleaning up Biblio.pm, removing unnecessary routines.
+#
+# DeleteBiblio - used to delete a biblio from zebra and koha tables
+# -- checks to make sure there are no existing issues
+# -- saves backups of biblio,biblioitems,items in deleted* tables
+# -- does commit operation
+#
+# getRecord - used to retrieve one record from zebra in piggyback mode using biblionumber
+# brought back z3950_extended_services routine
+#
+# Lots of modifications to Context.pm, you can now store user and pass info for
+# multiple servers (for federated searching) using the <serverinfo> element.
+# I'll commit my koha.xml to demonstrate this or you can refer to the POD in
+# Context.pm (which I also expanded on).
+#
+# Revision 1.18.2.5.2.13 2006/08/10 02:10:21 kados
+# Turned warnings on, and running a search turned up lots of warnings.
+# Cleaned up those ...
+#
+# removed getitemtypes from Koha.pm (one in Search.pm looks newer)
+# removed itemcount from Biblio.pm
+#
+# made some local subs local with a _ prefix (as they were redefined
+# elsewhere)
+#
+# Add two new search subs to Search.pm the start of a new search API
+# that's a bit more scalable
+#
+# Revision 1.18.2.5.2.10 2006/07/21 17:50:51 kados
+# moving the *.properties files to intranetdir/etc dir
+#
+# Revision 1.18.2.5.2.9 2006/07/17 08:05:20 tipaul
+# there was a hardcoded link to /koha/etc/ I replaced it with intranetdir config value
+#
+# Revision 1.18.2.5.2.8 2006/07/11 12:20:37 kados
+# adding ccl and cql files ... Tumer, if you want to fit these into the
+# config file by all means do.
+#
+# Revision 1.18.2.5.2.7 2006/06/04 22:50:33 tgarip1957
+# We do not hard code cql2rpn conversion file in context.pm our koha.xml configuration file already describes the path for this file.
+# At cql searching we use method CQL not CQL2RPN as the cql2rpn conversion file is defined at server level
+#
+# Revision 1.18.2.5.2.6 2006/06/02 23:11:24 kados
+# Committing my working dev_week. It's been tested only with
+# searching, and there's quite a lot of config stuff to set up
+# beforehand. As things get closer to a release, we'll be making
+# some scripts to do it for us
+#
+# Revision 1.18.2.5.2.5 2006/05/28 18:49:12 tgarip1957
+# This is an unusual commit. The main purpose is a working model of Zebra on a modified rel2_2.
+# Any questions regarding these commits should be asked to Joshua Ferraro unless you are Joshua whom I'll report to
#
# Revision 1.36 2006/05/09 13:28:08 tipaul
# adding the branchname and the librarian name in every page :
More information about the Koha-cvs
mailing list