← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 17:10:45 2013
Reported on Tue Oct 15 17:11:21 2013

Filename/usr/share/koha/lib/C4/Context.pm
StatementsExecuted 10370 statements in 1.61s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1423271231.2ms1.46sC4::Context::::dbhC4::Context::dbh
11125.0ms28.5msC4::Context::::BEGIN@101C4::Context::BEGIN@101
13541011216.4ms436msC4::Context::::preferenceC4::Context::preference
1119.42ms17.9msC4::Context::::BEGIN@102C4::Context::BEGIN@102
1117.47ms7.84msC4::Context::::BEGIN@103C4::Context::BEGIN@103
1116.83ms123msC4::Context::::BEGIN@23C4::Context::BEGIN@23
1113.63ms18.8msC4::Context::::BEGIN@108C4::Context::BEGIN@108
1113.11ms11.9msC4::Context::::BEGIN@107C4::Context::BEGIN@107
1111.58ms12.8msC4::Context::::_new_marcfromkohafieldC4::Context::_new_marcfromkohafield
111793µs3.52msC4::Context::::BEGIN@106C4::Context::BEGIN@106
111465µs871µsC4::Context::::BEGIN@105C4::Context::BEGIN@105
44177462µs880µsC4::Context::::configC4::Context::config
111455µs1.01msC4::Context::::BEGIN@21C4::Context::BEGIN@21
111453µs833µsC4::Context::::BEGIN@104C4::Context::BEGIN@104
9321432µs13.2msC4::Context::::marcfromkohafieldC4::Context::marcfromkohafield
4411418µs418µsC4::Context::::_common_configC4::Context::_common_config
4154364µs364µsC4::Context::::userenvC4::Context::userenv
111252µs362µsC4::Context::::KOHAVERSIONC4::Context::KOHAVERSION
111212µs73.2msC4::Context::::_new_dbhC4::Context::_new_dbh
414141165µs1.49msC4::Context::::importC4::Context::import
333165µs2.80msC4::Context::::newC4::Context::new
111122µs690µsC4::Context::::_new_ZconnC4::Context::_new_Zconn
33244µs120µsC4::Context::::AUTOLOADC4::Context::AUTOLOAD
11136µs793µsC4::Context::::ZconnC4::Context::Zconn
11121µs101µsC4::Context::::BEGIN@191C4::Context::BEGIN@191
11121µs54µsC4::Context::::BEGIN@1203C4::Context::BEGIN@1203
11116µs19µsC4::Context::::BEGIN@19C4::Context::BEGIN@19
22215µs15µsC4::Context::::ismemcachedC4::Context::ismemcached
11113µs24µsC4::Context::::BEGIN@20C4::Context::BEGIN@20
44213µs13µsC4::Context::::memcachedC4::Context::memcached
11112µs12µsC4::Context::::_new_userenvC4::Context::_new_userenv
1117µs7µsC4::Context::::db_scheme2dbiC4::Context::db_scheme2dbi
1115µs5µsC4::Context::::set_contextC4::Context::set_context
0000s0sC4::Context::::ModZebrationsC4::Context::ModZebrations
0000s0sC4::Context::::_new_queryparserC4::Context::_new_queryparser
0000s0sC4::Context::::_new_stopwordsC4::Context::_new_stopwords
0000s0sC4::Context::::_unset_userenvC4::Context::_unset_userenv
0000s0sC4::Context::::boolean_preferenceC4::Context::boolean_preference
0000s0sC4::Context::::clear_syspref_cacheC4::Context::clear_syspref_cache
0000s0sC4::Context::::disable_syspref_cacheC4::Context::disable_syspref_cache
0000s0sC4::Context::::enable_syspref_cacheC4::Context::enable_syspref_cache
0000s0sC4::Context::::final_linear_versionC4::Context::final_linear_version
0000s0sC4::Context::::get_shelves_userenvC4::Context::get_shelves_userenv
0000s0sC4::Context::::get_versionsC4::Context::get_versions
0000s0sC4::Context::::handle_errorsC4::Context::handle_errors
0000s0sC4::Context::::new_dbhC4::Context::new_dbh
0000s0sC4::Context::::queryparserC4::Context::queryparser
0000s0sC4::Context::::read_config_fileC4::Context::read_config_file
0000s0sC4::Context::::restore_contextC4::Context::restore_context
0000s0sC4::Context::::restore_dbhC4::Context::restore_dbh
0000s0sC4::Context::::set_dbhC4::Context::set_dbh
0000s0sC4::Context::::set_preferenceC4::Context::set_preference
0000s0sC4::Context::::set_shelves_userenvC4::Context::set_shelves_userenv
0000s0sC4::Context::::set_userenvC4::Context::set_userenv
0000s0sC4::Context::::stopwordsC4::Context::stopwords
0000s0sC4::Context::::tzC4::Context::tz
0000s0sC4::Context::::zebraconfigC4::Context::zebraconfig
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package C4::Context;
2# Copyright 2002 Katipo Communications
3#
4# This file is part of Koha.
5#
6# Koha is free software; you can redistribute it and/or modify it under the
7# terms of the GNU General Public License as published by the Free Software
8# Foundation; either version 2 of the License, or (at your option) any later
9# version.
10#
11# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with Koha; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19326µs223µs
# spent 19µs (16+4) within C4::Context::BEGIN@19 which was called: # once (16µs+4µs) by main::BEGIN@31 at line 19
use strict;
# spent 19µs making 1 call to C4::Context::BEGIN@19 # spent 4µs making 1 call to strict::import
20331µs235µs
# spent 24µs (13+11) within C4::Context::BEGIN@20 which was called: # once (13µs+11µs) by main::BEGIN@31 at line 20
use warnings;
# spent 24µs making 1 call to C4::Context::BEGIN@20 # spent 11µs making 1 call to warnings::import
213412µs21.12ms
# spent 1.01ms (455µs+558µs) within C4::Context::BEGIN@21 which was called: # once (455µs+558µs) by main::BEGIN@31 at line 21
use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached);
# spent 1.01ms making 1 call to C4::Context::BEGIN@21 # spent 104µs making 1 call to vars::import
22
23
# spent 123ms (6.83+116) within C4::Context::BEGIN@23 which was called: # once (6.83ms+116ms) by main::BEGIN@31 at line 99
BEGIN {
247141µs if ($ENV{'HTTP_USER_AGENT'}) {
25 require CGI::Carp;
26 # FIXME for future reference, CGI::Carp doc says
27 # "Note that fatalsToBrowser does not work with mod_perl version 2.0 and higher."
28 import CGI::Carp qw(fatalsToBrowser);
29 sub handle_errors {
30 my $msg = shift;
31 my $debug_level;
32 eval {C4::Context->dbh();};
33 if ($@){
34 $debug_level = 1;
35 }
36 else {
37 $debug_level = C4::Context->preference("DebugLevel");
38 }
39
40 print q(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
41 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
42 <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
43 <head><title>Koha Error</title></head>
44 <body>
45 );
46 if ($debug_level eq "2"){
47 # debug 2 , print extra info too.
48 my %versions = get_versions();
49
50 # a little example table with various version info";
51 print "
52 <h1>Koha error</h1>
53 <p>The following fatal error has occurred:</p>
54 <pre><code>$msg</code></pre>
55 <table>
56 <tr><th>Apache</th><td> $versions{apacheVersion}</td></tr>
57 <tr><th>Koha</th><td> $versions{kohaVersion}</td></tr>
58 <tr><th>Koha DB</th><td> $versions{kohaDbVersion}</td></tr>
59 <tr><th>MySQL</th><td> $versions{mysqlVersion}</td></tr>
60 <tr><th>OS</th><td> $versions{osVersion}</td></tr>
61 <tr><th>Perl</th><td> $versions{perlVersion}</td></tr>
62 </table>";
63
64 } elsif ($debug_level eq "1"){
65 print "
66 <h1>Koha error</h1>
67 <p>The following fatal error has occurred:</p>
68 <pre><code>$msg</code></pre>";
69 } else {
70 print "<p>production mode - trapped fatal error</p>";
71 }
72 print "</body></html>";
73 }
74 #CGI::Carp::set_message(\&handle_errors);
75 ## give a stack backtrace if KOHA_BACKTRACES is set
76 ## can't rely on DebugLevel for this, as we're not yet connected
77 if ($ENV{KOHA_BACKTRACES}) {
78 $main::SIG{__DIE__} = \&CGI::Carp::confess;
79 }
80 } # else there is no browser to send fatals to!
81
82 # Check if there are memcached servers set
83 $servers = $ENV{'MEMCACHED_SERVERS'};
84 if ($servers) {
85 # Load required libraries and create the memcached object
86 require Cache::Memcached;
8712.25ms $memcached = Cache::Memcached->new({
# spent 2.25ms making 1 call to Cache::Memcached::new
88 servers => [ $servers ],
89 debug => 0,
90 compress_threshold => 10_000,
91 expire_time => 600,
92 namespace => $ENV{'MEMCACHED_NAMESPACE'} || 'koha'
93 });
94 # Verify memcached available (set a variable and test the output)
9511.44ms $ismemcached = $memcached->set('ismemcached','1');
# spent 1.44ms making 1 call to Cache::Memcached::set
96 }
97
98 $VERSION = '3.07.00.049';
99160µs1123ms}
# spent 123ms making 1 call to C4::Context::BEGIN@23
100
1013256µs228.6ms
# spent 28.5ms (25.0+3.53) within C4::Context::BEGIN@101 which was called: # once (25.0ms+3.53ms) by main::BEGIN@31 at line 101
use DBI;
# spent 28.5ms making 1 call to C4::Context::BEGIN@101 # spent 66µs making 1 call to Exporter::import
1023252µs117.9ms
# spent 17.9ms (9.42+8.46) within C4::Context::BEGIN@102 which was called: # once (9.42ms+8.46ms) by main::BEGIN@31 at line 102
use ZOOM;
# spent 17.9ms making 1 call to C4::Context::BEGIN@102
1033163µs27.87ms
# spent 7.84ms (7.47+369µs) within C4::Context::BEGIN@103 which was called: # once (7.47ms+369µs) by main::BEGIN@31 at line 103
use XML::Simple;
# spent 7.84ms making 1 call to C4::Context::BEGIN@103 # spent 26µs making 1 call to XML::Simple::import
1043144µs2859µs
# spent 833µs (453+379) within C4::Context::BEGIN@104 which was called: # once (453µs+379µs) by main::BEGIN@31 at line 104
use C4::Boolean;
# spent 833µs making 1 call to C4::Context::BEGIN@104 # spent 26µs making 1 call to Exporter::import
1053185µs21.03ms
# spent 871µs (465+407) within C4::Context::BEGIN@105 which was called: # once (465µs+407µs) by main::BEGIN@31 at line 105
use C4::Debug;
# spent 871µs making 1 call to C4::Context::BEGIN@105 # spent 160µs making 1 call to Exporter::import
1063133µs13.52ms
# spent 3.52ms (793µs+2.72) within C4::Context::BEGIN@106 which was called: # once (793µs+2.72ms) by main::BEGIN@31 at line 106
use POSIX ();
# spent 3.52ms making 1 call to C4::Context::BEGIN@106
1073142µs111.9ms
# spent 11.9ms (3.11+8.84) within C4::Context::BEGIN@107 which was called: # once (3.11ms+8.84ms) by main::BEGIN@31 at line 107
use DateTime::TimeZone;
# spent 11.9ms making 1 call to C4::Context::BEGIN@107
1083295µs218.9ms
# spent 18.8ms (3.63+15.2) within C4::Context::BEGIN@108 which was called: # once (3.63ms+15.2ms) by main::BEGIN@31 at line 108
use Module::Load::Conditional qw(can_load);
# spent 18.8ms making 1 call to C4::Context::BEGIN@108 # spent 114µs making 1 call to Exporter::import
109
110=head1 NAME
111
- -
161#'
162# In addition to what is said in the POD above, a Context object is a
163# reference-to-hash with the following fields:
164#
165# config
166# A reference-to-hash whose keys and values are the
167# configuration variables and values specified in the config
168# file (/etc/koha/koha-conf.xml).
169# dbh
170# A handle to the appropriate database for this context.
171# dbh_stack
172# Used by &set_dbh and &restore_dbh to hold other database
173# handles for this context.
174# Zconn
175# A connection object for the Zebra server
176
177# Koha's main configuration file koha-conf.xml
178# is searched for according to this priority list:
179#
180# 1. Path supplied via use C4::Context '/path/to/koha-conf.xml'
181# 2. Path supplied in KOHA_CONF environment variable.
182# 3. Path supplied in INSTALLED_CONFIG_FNAME, as long
183# as value has changed from its default of
184# '/etc/koha/koha-conf.xml', as happens
185# when Koha is installed in 'standard' or 'single'
186# mode.
187# 4. Path supplied in CONFIG_FNAME.
188#
189# The first entry that refers to a readable file is used.
190
19134.23ms2180µs
# spent 101µs (21+80) within C4::Context::BEGIN@191 which was called: # once (21µs+80µs) by main::BEGIN@31 at line 191
use constant CONFIG_FNAME => "/etc/koha/koha-conf.xml";
# spent 101µs making 1 call to C4::Context::BEGIN@191 # spent 80µs making 1 call to constant::import
192 # Default config file, if none is specified
193
19411µsmy $INSTALLED_CONFIG_FNAME = '/etc/koha/koha-conf.xml';
195 # path to config file set by installer
196 # /etc/koha is set by rewrite-confg.PL
197 # when Koha is installed in 'standard' or 'single'
198 # mode. If Koha was installed in 'dev' mode,
199 # /etc/koha is *not* rewritten; instead
200 # developers should set the KOHA_CONF environment variable
201
2021400ns$context = undef; # Initially, no context is set
20311µs@context_stack = (); # Initially, no saved contexts
204
205
206=head2 KOHAVERSION
207
- -
212
# spent 362µs (252+111) within C4::Context::KOHAVERSION which was called: # once (252µs+111µs) by C4::Auth::_version_check at line 571 of /usr/share/koha/lib/C4/Auth.pm
sub KOHAVERSION {
2134188µs159µs my $cgidir = C4::Context->intranetdir;
# spent 59µs making 1 call to C4::Context::AUTOLOAD
214
215 # Apparently the GIT code does not run out of a CGI-BIN subdirectory
216 # but distribution code does? (Stan, 1jan08)
217117µs if(-d $cgidir . "/cgi-bin"){
# spent 17µs making 1 call to C4::Context::CORE:ftdir
218 my $cgidir .= "/cgi-bin";
219 }
220
221 do $cgidir."/kohaversion.pl" || die "NO $cgidir/kohaversion.pl";
22213µs return kohaversion();
# spent 3µs making 1 call to C4::Context::kohaversion
223}
224
225=head2 final_linear_version
226
- -
232sub final_linear_version {
233 return KOHAVERSION;
234}
235
236=head2 read_config_file
237
- -
261sub read_config_file { # Pass argument naming config file to read
262 my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
263
264 if ($ismemcached) {
265 $memcached->set('kohaconf',$koha);
266 }
267
268 return $koha; # Return value: ref-to-hash holding the configuration
269}
270
271=head2 ismemcached
272
- -
277
# spent 15µs within C4::Context::ismemcached which was called 2 times, avg 7µs/call: # once (11µs+0s) by C4::Reserves::BEGIN@27 at line 144 of /usr/share/koha/lib/C4/Biblio.pm # once (4µs+0s) by C4::Templates::BEGIN@35 at line 29 of /usr/share/koha/lib/C4/Languages.pm
sub ismemcached {
278235µs return $ismemcached;
279}
280
281=head2 memcached
282
- -
288
# spent 13µs within C4::Context::memcached which was called 4 times, avg 3µs/call: # once (6µs+0s) by C4::Reserves::BEGIN@27 at line 148 of /usr/share/koha/lib/C4/Biblio.pm # once (3µs+0s) by C4::Templates::BEGIN@35 at line 33 of /usr/share/koha/lib/C4/Languages.pm # once (2µs+0s) by C4::Templates::BEGIN@35 at line 34 of /usr/share/koha/lib/C4/Languages.pm # once (2µs+0s) by C4::Templates::BEGIN@35 at line 35 of /usr/share/koha/lib/C4/Languages.pm
sub memcached {
289423µs if ($ismemcached) {
290 return $memcached;
291 } else {
292 return;
293 }
294}
295
296# db_scheme2dbi
297# Translates the full text name of a database into de appropiate dbi name
298#
299
# spent 7µs within C4::Context::db_scheme2dbi which was called: # once (7µs+0s) by C4::Context::_new_dbh at line 792
sub db_scheme2dbi {
30028µs my $name = shift;
301 # for instance, we support only mysql, so don't care checking
302 return "mysql";
303 for ($name) {
304# FIXME - Should have other databases.
305 if (/mysql/) { return("mysql"); }
306 if (/Postgres|Pg|PostgresSQL/) { return("Pg"); }
307 if (/oracle/) { return("Oracle"); }
308 }
309 return; # Just in case
310}
311
312
# spent 1.49ms (165µs+1.32) within C4::Context::import which was called 41 times, avg 36µs/call: # once (13µs+1.32ms) by main::BEGIN@31 at line 31 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (8µs+0s) by C4::Circulation::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Circulation.pm # once (7µs+0s) by C4::Auth::BEGIN@28 at line 28 of /usr/share/koha/lib/C4/Auth.pm # once (7µs+0s) by C4::Members::Attributes::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/Members/Attributes.pm # once (6µs+0s) by C4::XSLT::BEGIN@26 at line 26 of /usr/share/koha/lib/C4/XSLT.pm # once (6µs+0s) by C4::Linker::BEGIN@48 at line 48 of /usr/share/koha/lib/C4/Linker.pm # once (6µs+0s) by C4::ItemCirculationAlertPreference::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/ItemCirculationAlertPreference.pm # once (6µs+0s) by C4::Stats::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/Stats.pm # once (6µs+0s) by C4::Overdues::BEGIN@27 at line 27 of /usr/share/koha/lib/C4/Overdues.pm # once (6µs+0s) by C4::Items::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Items.pm # once (6µs+0s) by C4::Auth_with_ldap::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Auth_with_ldap.pm # once (5µs+0s) by C4::Search::BEGIN@21 at line 21 of /usr/share/koha/lib/C4/Search.pm # once (5µs+0s) by Koha::Calendar::BEGIN@9 at line 9 of /usr/share/koha/lib/Koha/Calendar.pm # once (4µs+0s) by C4::Tags::BEGIN@26 at line 26 of /usr/share/koha/lib/C4/Tags.pm # once (4µs+0s) by C4::NewsChannels::BEGIN@23 at line 23 of /usr/share/koha/lib/C4/NewsChannels.pm # once (4µs+0s) by C4::Accounts::BEGIN@23 at line 23 of /usr/share/koha/lib/C4/Accounts.pm # once (4µs+0s) by C4::Log::BEGIN@27 at line 27 of /usr/share/koha/lib/C4/Log.pm # once (4µs+0s) by C4::ClassSource::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/ClassSource.pm # once (4µs+0s) by C4::Ratings::BEGIN@27 at line 27 of /usr/share/koha/lib/C4/Ratings.pm # once (4µs+0s) by C4::Koha::BEGIN@26 at line 26 of /usr/share/koha/lib/C4/Koha.pm # once (4µs+0s) by C4::VirtualShelves::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/VirtualShelves.pm # once (4µs+0s) by C4::Languages::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Languages.pm # once (3µs+0s) by C4::Auth_with_cas::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/Auth_with_cas.pm # once (3µs+0s) by C4::OAI::Sets::BEGIN@33 at line 33 of /usr/share/koha/lib/C4/OAI/Sets.pm # once (3µs+0s) by C4::SocialData::BEGIN@20 at line 20 of /usr/share/koha/lib/C4/SocialData.pm # once (3µs+0s) by C4::Budgets::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/Budgets.pm # once (3µs+0s) by C4::SMS::BEGIN@38 at line 38 of /usr/share/koha/lib/C4/SMS.pm # once (3µs+0s) by C4::Members::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Members.pm # once (2µs+0s) by Koha::DateUtils::BEGIN@24 at line 24 of /usr/share/koha/lib/Koha/DateUtils.pm # once (2µs+0s) by C4::Message::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/Message.pm # once (2µs+0s) by C4::Members::Messaging::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/Members/Messaging.pm # once (2µs+0s) by C4::SQLHelper::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/SQLHelper.pm # once (2µs+0s) by C4::Templates::BEGIN@37 at line 37 of /usr/share/koha/lib/C4/Templates.pm # once (2µs+0s) by C4::Output::BEGIN@33 at line 33 of /usr/share/koha/lib/C4/Output.pm # once (2µs+0s) by C4::Branch::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/Branch.pm # once (2µs+0s) by C4::Reserves::BEGIN@26 at line 26 of /usr/share/koha/lib/C4/Reserves.pm # once (2µs+0s) by C4::Members::AttributeTypes::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/Members/AttributeTypes.pm # once (2µs+0s) by C4::ItemType::BEGIN@23 at line 23 of /usr/share/koha/lib/C4/ItemType.pm # once (2µs+0s) by C4::ClassSortRoutine::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/ClassSortRoutine.pm # once (2µs+0s) by C4::Dates::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Dates.pm # once (2µs+0s) by C4::Category::BEGIN@23 at line 23 of /usr/share/koha/lib/C4/Category.pm
sub import {
313 # Create the default context ($C4::Context::Context)
314 # the first time the module is called
315 # (a config file can be optionaly passed)
316
317 # default context allready exists?
31846504µs return if $context;
319
320 # no ? so load it!
321 my ($pkg,$config_file) = @_ ;
32211.32ms my $new_ctx = __PACKAGE__->new($config_file);
# spent 1.32ms making 1 call to C4::Context::new
323 return unless $new_ctx;
324
325 # if successfully loaded, use it by default
32615µs $new_ctx->set_context;
# spent 5µs making 1 call to C4::Context::set_context
327 1;
328}
329
330=head2 new
331
- -
348#'
349# Revision History:
350# 2004-08-10 A. Tarallo: Added check if the conf file is not empty
351
# spent 2.80ms (165µs+2.63) within C4::Context::new which was called 3 times, avg 932µs/call: # once (44µs+1.27ms) by C4::Context::import at line 322 # once (69µs+724µs) by C4::Auth::BEGIN@39 at line 55 of /usr/share/koha/lib/C4/Auth_with_ldap.pm # once (52µs+634µs) by C4::Auth::BEGIN@39 at line 40 of /usr/share/koha/lib/C4/Auth_with_cas.pm
sub new {
35266204µs my $class = shift;
353 my $conf_fname = shift; # Config file to load
354 my $self = {};
355
356 # check that the specified config file exists and is not empty
357 undef $conf_fname unless
358 (defined $conf_fname && -s $conf_fname);
359 # Figure out a good config file to load if none was specified.
360 if (!defined($conf_fname))
361 {
362 # If the $KOHA_CONF environment variable is set, use
363 # that. Otherwise, use the built-in default.
364337µs if (exists $ENV{"KOHA_CONF"} and $ENV{'KOHA_CONF'} and -s $ENV{"KOHA_CONF"}) {
# spent 37µs making 3 calls to C4::Context::CORE:ftsize, avg 12µs/call
365 $conf_fname = $ENV{"KOHA_CONF"};
366 } elsif ($INSTALLED_CONFIG_FNAME !~ /__KOHA_CONF_DIR/ and -s $INSTALLED_CONFIG_FNAME) {
367 # NOTE: be careful -- don't change __KOHA_CONF_DIR in the above
368 # regex to anything else -- don't want installer to rewrite it
369 $conf_fname = $INSTALLED_CONFIG_FNAME;
370 } elsif (-s CONFIG_FNAME) {
371 $conf_fname = CONFIG_FNAME;
372 } else {
373 warn "unable to locate Koha configuration file koha-conf.xml";
374 return;
375 }
376 }
377
378 if ($ismemcached) {
379 # retreive from memcached
38032.59ms $self = $memcached->get('kohaconf');
# spent 2.59ms making 3 calls to Cache::Memcached::get, avg 865µs/call
381 if (not defined $self) {
382 # not in memcached yet
383 $self = read_config_file($conf_fname);
384 }
385 } else {
386 # non-memcached env, read from file
387 $self = read_config_file($conf_fname);
388 }
389
390 $self->{"config_file"} = $conf_fname;
391 warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"});
392 return if !defined($self->{"config"});
393
394 $self->{"dbh"} = undef; # Database handle
395 $self->{"Zconn"} = undef; # Zebra Connections
396 $self->{"stopwords"} = undef; # stopwords list
397 $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
398 $self->{"userenv"} = undef; # User env
399 $self->{"activeuser"} = undef; # current active user
400 $self->{"shelves"} = undef;
401 $self->{tz} = undef; # local timezone object
402
403 bless $self, $class;
404 return $self;
405}
406
407=head2 set_context
408
- -
424#'
425sub set_context
426
# spent 5µs within C4::Context::set_context which was called: # once (5µs+0s) by C4::Context::import at line 326
{
42767µs my $self = shift;
428 my $new_context; # The context to set
429
430 # Figure out whether this is a class or instance method call.
431 #
432 # We're going to make the assumption that control got here
433 # through valid means, i.e., that the caller used an instance
434 # or class method call, and that control got here through the
435 # usual inheritance mechanisms. The caller can, of course,
436 # break this assumption by playing silly buggers, but that's
437 # harder to do than doing it properly, and harder to check
438 # for.
439 if (ref($self) eq "")
440 {
441 # Class method. The new context is the next argument.
442 $new_context = shift;
443 } else {
444 # Instance method. The new context is $self.
445 $new_context = $self;
446 }
447
448 # Save the old context, if any, on the stack
449 push @context_stack, $context if defined($context);
450
451 # Set the new context
452 $context = $new_context;
453}
454
455=head2 restore_context
456
- -
463#'
464sub restore_context
465{
466 my $self = shift;
467
468 if ($#context_stack < 0)
469 {
470 # Stack underflow.
471 die "Context stack underflow";
472 }
473
474 # Pop the old context and set it.
475 $context = pop @context_stack;
476
477 # FIXME - Should this return something, like maybe the context
478 # that was current when this was called?
479}
480
481=head2 config
482
- -
496
# spent 418µs within C4::Context::_common_config which was called 44 times, avg 10µs/call: # 44 times (418µs+0s) by C4::Context::config at line 510, avg 10µs/call
sub _common_config {
497176604µs my $var = shift;
498 my $term = shift;
499 return if !defined($context->{$term});
500 # Presumably $self->{$term} might be
501 # undefined if the config file given to &new
502 # didn't exist, and the caller didn't bother
503 # to check the return value.
504
505 # Return the value of the requested config variable
506 return $context->{$term}->{$var};
507}
508
509
# spent 880µs (462+418) within C4::Context::config which was called 44 times, avg 20µs/call: # 25 times (295µs+274µs) by C4::XSLT::XSLTParse4Display at line 183 of /usr/share/koha/lib/C4/XSLT.pm, avg 23µs/call # 3 times (24µs+21µs) by C4::Context::AUTOLOAD at line 660, avg 15µs/call # 2 times (15µs+10µs) by C4::Templates::new at line 62 of /usr/share/koha/lib/C4/Templates.pm, avg 13µs/call # once (17µs+14µs) by C4::Auth::BEGIN@39 at line 53 of /usr/share/koha/lib/C4/Auth.pm # once (13µs+10µs) by C4::Budgets::BEGIN@24 at line 31 of /usr/share/koha/lib/C4/SQLHelper.pm # once (10µs+9µs) by C4::Templates::_get_template_file at line 217 of /usr/share/koha/lib/C4/Templates.pm # once (10µs+8µs) by C4::Auth::BEGIN@39 at line 56 of /usr/share/koha/lib/C4/Auth_with_ldap.pm # once (9µs+9µs) by C4::Output::BEGIN@36 at line 208 of /usr/share/koha/lib/C4/Templates.pm # once (9µs+8µs) by C4::Templates::new at line 50 of /usr/share/koha/lib/C4/Templates.pm # once (8µs+8µs) by C4::Context::_new_dbh at line 791 # once (7µs+8µs) by C4::Context::_new_dbh at line 798 # once (8µs+7µs) by C4::Context::_new_dbh at line 800 # once (8µs+6µs) by C4::Context::_new_dbh at line 797 # once (8µs+7µs) by C4::Context::_new_dbh at line 801 # once (8µs+6µs) by main::BEGIN@45 at line 72 of /usr/share/koha/lib/C4/Output.pm # once (7µs+7µs) by C4::Context::_new_dbh at line 799 # once (7µs+6µs) by C4::Context::_new_dbh at line 792
sub config {
51044355µs44418µs return _common_config($_[1],'config');
# spent 418µs making 44 calls to C4::Context::_common_config, avg 10µs/call
511}
512sub zebraconfig {
513 return _common_config($_[1],'server');
514}
515sub ModZebrations {
516 return _common_config($_[1],'serverinfo');
517}
518
519=head2 preference
520
- -
535# FIXME: running this under mod_perl will require a means of
536# flushing the caching mechanism.
537
5381200nsmy %sysprefs;
5391300nsmy $use_syspref_cache = 1;
540
541
# spent 436ms (16.4+420) within C4::Context::preference which was called 1354 times, avg 322µs/call: # 550 times (3.27ms+34.2ms) by C4::XSLT::XSLTParse4Display at line 212 of /usr/share/koha/lib/C4/XSLT.pm, avg 68µs/call # 80 times (696µs+0s) by C4::Koha::getitemtypeimagesrc at line 474 of /usr/share/koha/lib/C4/Koha.pm, avg 9µs/call # 69 times (3.66ms+148ms) by C4::Auth::get_template_and_user at line 381 of /usr/share/koha/lib/C4/Auth.pm, avg 2.20ms/call # 57 times (578µs+1.98ms) by C4::Koha::getitemtypeimagesrc at line 471 of /usr/share/koha/lib/C4/Koha.pm, avg 45µs/call # 32 times (277µs+2.51ms) by C4::Items::GetHiddenItemnumbers at line 1640 of /usr/share/koha/lib/C4/Items.pm, avg 87µs/call # 32 times (384µs+1.47ms) by C4::Search::searchResults at line 1859 of /usr/share/koha/lib/C4/Search.pm, avg 58µs/call # 32 times (119µs+0s) by C4::Search::searchResults at line 1860 of /usr/share/koha/lib/C4/Search.pm, avg 4µs/call # 25 times (270µs+2.41ms) by C4::Search::searchResults at line 1829 of /usr/share/koha/lib/C4/Search.pm, avg 107µs/call # 25 times (182µs+1.88ms) by main::RUNTIME at line 590 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 83µs/call # 25 times (416µs+0s) by C4::XSLT::XSLTParse4Display at line 200 of /usr/share/koha/lib/C4/XSLT.pm, avg 17µs/call # 25 times (356µs+0s) by C4::Search::searchResults at line 2014 of /usr/share/koha/lib/C4/Search.pm, avg 14µs/call # 25 times (249µs+0s) by C4::Biblio::GetMarcBiblio at line 1259 of /usr/share/koha/lib/C4/Biblio.pm, avg 10µs/call # 25 times (244µs+0s) by C4::Biblio::GetCOinSBiblio at line 1371 of /usr/share/koha/lib/C4/Biblio.pm, avg 10µs/call # 25 times (229µs+0s) by C4::Items::GetItemsInfo at line 1206 of /usr/share/koha/lib/C4/Items.pm, avg 9µs/call # 25 times (226µs+0s) by C4::Search::searchResults at line 2020 of /usr/share/koha/lib/C4/Search.pm, avg 9µs/call # 25 times (167µs+0s) by C4::Search::searchResults at line 1778 of /usr/share/koha/lib/C4/Search.pm, avg 7µs/call # 25 times (161µs+0s) by C4::XSLT::XSLTParse4Display at line 185 of /usr/share/koha/lib/C4/XSLT.pm, avg 6µs/call # 25 times (139µs+0s) by C4::Search::searchResults at line 1716 of /usr/share/koha/lib/C4/Search.pm, avg 6µs/call # 25 times (130µs+0s) by C4::Biblio::GetMarcBiblio at line 1263 of /usr/share/koha/lib/C4/Biblio.pm, avg 5µs/call # 25 times (117µs+0s) by C4::XSLT::XSLTParse4Display at line 184 of /usr/share/koha/lib/C4/XSLT.pm, avg 5µs/call # 25 times (111µs+0s) by C4::Search::searchResults at line 2044 of /usr/share/koha/lib/C4/Search.pm, avg 4µs/call # 25 times (88µs+0s) by C4::XSLT::XSLTParse4Display at line 161 of /usr/share/koha/lib/C4/XSLT.pm, avg 4µs/call # 23 times (163µs+1.65ms) by C4::Search::__ANON__[/usr/share/koha/lib/C4/Search.pm:670] at line 582 of /usr/share/koha/lib/C4/Search.pm, avg 79µs/call # 15 times (918µs+30.2ms) by C4::Auth::get_template_and_user at line 303 of /usr/share/koha/lib/C4/Auth.pm, avg 2.08ms/call # 4 times (111µs+5.42ms) by main::RUNTIME at line 353 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 1.38ms/call # 3 times (81µs+2.08ms) by C4::Templates::getlanguage at line 326 of /usr/share/koha/lib/C4/Templates.pm, avg 722µs/call # 3 times (78µs+1.82ms) by C4::Auth::get_session at line 1519 of /usr/share/koha/lib/C4/Auth.pm, avg 632µs/call # 2 times (95µs+4.28ms) by main::RUNTIME at line 165 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 2.19ms/call # 2 times (49µs+2.22ms) by C4::Auth::get_template_and_user at line 297 of /usr/share/koha/lib/C4/Auth.pm, avg 1.14ms/call # 2 times (63µs+2.09ms) by C4::Templates::themelanguage at line 289 of /usr/share/koha/lib/C4/Templates.pm, avg 1.08ms/call # 2 times (20µs+0s) by main::RUNTIME at line 576 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 10µs/call # 2 times (10µs+0s) by main::RUNTIME at line 141 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 5µs/call # once (77µs+74.4ms) by C4::Auth::BEGIN@39 at line 54 of /usr/share/koha/lib/C4/Auth.pm # once (50µs+4.20ms) by C4::Search::buildQuery at line 1262 of /usr/share/koha/lib/C4/Search.pm # once (44µs+4.13ms) by main::RUNTIME at line 885 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (41µs+2.59ms) by C4::Search::buildQuery at line 1266 of /usr/share/koha/lib/C4/Search.pm # once (36µs+2.49ms) by C4::Search::buildQuery at line 1264 of /usr/share/koha/lib/C4/Search.pm # once (69µs+2.44ms) by C4::Auth::_version_check at line 556 of /usr/share/koha/lib/C4/Auth.pm # once (54µs+2.36ms) by main::RUNTIME at line 123 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (53µs+2.32ms) by main::BEGIN@85 at line 86 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (94µs+2.27ms) by main::RUNTIME at line 33 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (43µs+2.31ms) by main::RUNTIME at line 718 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (59µs+2.30ms) by C4::Auth::BEGIN@39 at line 55 of /usr/share/koha/lib/C4/Auth.pm # once (45µs+2.30ms) by main::RUNTIME at line 479 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (82µs+2.26ms) by C4::Auth::checkauth at line 624 of /usr/share/koha/lib/C4/Auth.pm # once (77µs+2.24ms) by C4::Branch::onlymine at line 146 of /usr/share/koha/lib/C4/Branch.pm # once (46µs+2.26ms) by C4::Search::getRecords at line 343 of /usr/share/koha/lib/C4/Search.pm # once (63µs+2.23ms) by C4::Templates::gettemplate at line 233 of /usr/share/koha/lib/C4/Templates.pm # once (45µs+2.25ms) by main::RUNTIME at line 147 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (61µs+2.23ms) by main::RUNTIME at line 116 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (98µs+2.16ms) by C4::Auth::get_template_and_user at line 373 of /usr/share/koha/lib/C4/Auth.pm # once (56µs+2.20ms) by main::RUNTIME at line 895 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (73µs+2.13ms) by main::RUNTIME at line 101 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (47µs+2.14ms) by main::RUNTIME at line 61 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (41µs+2.13ms) by C4::Search::parseQuery at line 1178 of /usr/share/koha/lib/C4/Search.pm # once (46µs+2.11ms) by C4::Search::buildQuery at line 1263 of /usr/share/koha/lib/C4/Search.pm # once (46µs+2.10ms) by main::RUNTIME at line 148 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (62µs+2.08ms) by C4::Auth::checkauth at line 817 of /usr/share/koha/lib/C4/Auth.pm # once (45µs+2.08ms) by C4::Templates::output at line 103 of /usr/share/koha/lib/C4/Templates.pm # once (38µs+2.08ms) by main::RUNTIME at line 439 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (44µs+2.07ms) by main::RUNTIME at line 757 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (42µs+2.07ms) by C4::Search::buildQuery at line 1265 of /usr/share/koha/lib/C4/Search.pm # once (47µs+2.02ms) by main::RUNTIME at line 893 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (45µs+2.01ms) by main::RUNTIME at line 150 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (50µs+1.99ms) by C4::Auth::get_template_and_user at line 290 of /usr/share/koha/lib/C4/Auth.pm # once (53µs+1.99ms) by main::RUNTIME at line 751 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (37µs+1.99ms) by main::RUNTIME at line 857 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (64µs+1.93ms) by C4::Auth::get_template_and_user at line 361 of /usr/share/koha/lib/C4/Auth.pm # once (35µs+1.95ms) by main::RUNTIME at line 890 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (50µs+1.94ms) by main::RUNTIME at line 494 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (37µs+1.95ms) by main::RUNTIME at line 894 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (87µs+1.89ms) by C4::Auth::_timeout_syspref at line 596 of /usr/share/koha/lib/C4/Auth.pm # once (48µs+1.92ms) by main::RUNTIME at line 481 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (62µs+1.89ms) by C4::Auth::BEGIN@39 at line 53 of /usr/share/koha/lib/C4/Auth_with_cas.pm # once (67µs+1.86ms) by C4::Tags::BEGIN@35 at line 54 of /usr/share/koha/lib/C4/Tags.pm # once (41µs+1.87ms) by main::RUNTIME at line 888 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (55µs+1.85ms) by main::RUNTIME at line 210 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (47µs+1.81ms) by C4::Auth::get_template_and_user at line 365 of /usr/share/koha/lib/C4/Auth.pm # once (51µs+1.74ms) by C4::Auth::_version_check at line 551 of /usr/share/koha/lib/C4/Auth.pm # once (35µs+1.69ms) by main::RUNTIME at line 438 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (19µs+0s) by main::RUNTIME at line 207 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (13µs+0s) by main::RUNTIME at line 586 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (12µs+0s) by C4::Search::searchResults at line 1638 of /usr/share/koha/lib/C4/Search.pm # once (10µs+0s) by C4::Koha::getFacets at line 689 of /usr/share/koha/lib/C4/Koha.pm # once (9µs+0s) by C4::Search::_build_weighted_query at line 847 of /usr/share/koha/lib/C4/Search.pm # once (8µs+0s) by C4::Templates::output at line 110 of /usr/share/koha/lib/C4/Templates.pm # once (8µs+0s) by C4::Search::searchResults at line 1695 of /usr/share/koha/lib/C4/Search.pm # once (8µs+0s) by C4::Koha::getFacets at line 786 of /usr/share/koha/lib/C4/Koha.pm # once (8µs+0s) by main::RUNTIME at line 712 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (8µs+0s) by C4::Auth::get_template_and_user at line 461 of /usr/share/koha/lib/C4/Auth.pm # once (7µs+0s) by C4::Context::Zconn at line 702 # once (7µs+0s) by main::RUNTIME at line 162 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (7µs+0s) by main::RUNTIME at line 153 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (6µs+0s) by C4::Templates::output at line 113 of /usr/share/koha/lib/C4/Templates.pm # once (6µs+0s) by C4::Templates::output at line 112 of /usr/share/koha/lib/C4/Templates.pm # once (5µs+0s) by main::RUNTIME at line 755 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (4µs+0s) by main::RUNTIME at line 608 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (4µs+0s) by main::RUNTIME at line 624 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl # once (4µs+0s) by C4::Search::__ANON__[/usr/share/koha/lib/C4/Search.pm:670] at line 650 of /usr/share/koha/lib/C4/Search.pm # once (3µs+0s) by C4::Search::_build_weighted_query at line 848 of /usr/share/koha/lib/C4/Search.pm # once (3µs+0s) by C4::Search::_build_weighted_query at line 849 of /usr/share/koha/lib/C4/Search.pm
sub preference {
542470615.8ms my $self = shift;
543 my $var = lc(shift); # The system preference to return
544
545 if ($use_syspref_cache && exists $sysprefs{$var}) {
546 return $sysprefs{$var};
547 }
548
549161236ms my $dbh = C4::Context->dbh or return 0;
# spent 236ms making 161 calls to C4::Context::dbh, avg 1.46ms/call
550
551 # Look up systempreferences.variable==$var
552 my $sql = <<'END_SQL';
553 SELECT value
554 FROM systempreferences
555 WHERE variable=?
556 LIMIT 1
557END_SQL
5581174ms483209ms $sysprefs{$var} = $dbh->selectrow_array( $sql, {}, $var );
# spent 182ms making 161 calls to DBI::db::selectrow_array, avg 1.13ms/call # spent 14.1ms making 161 calls to DBI::db::prepare, avg 88µs/call # spent 12.8ms making 161 calls to DBD::mysql::db::prepare, avg 80µs/call
5594832.50ms return $sysprefs{$var};
# spent 1.97ms making 322 calls to DBI::common::DESTROY, avg 6µs/call # spent 527µs making 161 calls to DBD::_mem::common::DESTROY, avg 3µs/call
560}
561
562sub boolean_preference {
563 my $self = shift;
564 my $var = shift; # The system preference to return
565 my $it = preference($self, $var);
566 return defined($it)? C4::Boolean::true_p($it): undef;
567}
568
569=head2 enable_syspref_cache
570
- -
578sub enable_syspref_cache {
579 my ($self) = @_;
580 $use_syspref_cache = 1;
581}
582
583=head2 disable_syspref_cache
584
- -
592sub disable_syspref_cache {
593 my ($self) = @_;
594 $use_syspref_cache = 0;
595 $self->clear_syspref_cache();
596}
597
598=head2 clear_syspref_cache
599
- -
608sub clear_syspref_cache {
609 %sysprefs = ();
610}
611
612=head2 set_preference
613
- -
621sub set_preference {
622 my $self = shift;
623 my $var = lc(shift);
624 my $value = shift;
625
626 my $dbh = C4::Context->dbh or return 0;
627
628 my $type = $dbh->selectrow_array( "SELECT type FROM systempreferences WHERE variable = ?", {}, $var );
629
630 $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' );
631
632 my $sth = $dbh->prepare( "
633 INSERT INTO systempreferences
634 ( variable, value )
635 VALUES( ?, ? )
636 ON DUPLICATE KEY UPDATE value = VALUES(value)
637 " );
638
639 if($sth->execute( $var, $value )) {
640 $sysprefs{$var} = $value;
641 }
642 $sth->finish;
643}
644
645# AUTOLOAD
646# This implements C4::Config->foo, and simply returns
647# C4::Context->config("foo"), as described in the documentation for
648# &config, above.
649
650# FIXME - Perhaps this should be extended to check &config first, and
651# then &preference if that fails. OTOH, AUTOLOAD could lead to crappy
652# code, so it'd probably be best to delete it altogether so as not to
653# encourage people to use it.
654sub AUTOLOAD
655
# spent 120µs (44+76) within C4::Context::AUTOLOAD which was called 3 times, avg 40µs/call: # once (18µs+41µs) by C4::Context::KOHAVERSION at line 213 # once (16µs+24µs) by C4::Auth::BEGIN@39 at line 56 of /usr/share/koha/lib/C4/Auth.pm # once (9µs+11µs) by C4::Auth::BEGIN@39 at line 58 of /usr/share/koha/lib/C4/Auth.pm
{
656977µs my $self = shift;
657
658330µs $AUTOLOAD =~ s/.*:://; # Chop off the package name,
# spent 30µs making 3 calls to C4::Context::CORE:subst, avg 10µs/call
659 # leaving only the function name.
660345µs return $self->config($AUTOLOAD);
# spent 45µs making 3 calls to C4::Context::config, avg 15µs/call
661}
662
663=head2 Zconn
664
- -
682
# spent 793µs (36+756) within C4::Context::Zconn which was called: # once (36µs+756µs) by C4::Search::getRecords at line 349 of /usr/share/koha/lib/C4/Search.pm
sub Zconn {
6831132µs my $self=shift;
684 my $server=shift;
685 my $async=shift;
686 my $auth=shift;
687 my $piggyback=shift;
688 my $syntax=shift;
689 if ( defined($context->{"Zconn"}->{$server}) && (0 == $context->{"Zconn"}->{$server}->errcode()) ) {
690 return $context->{"Zconn"}->{$server};
691 # No connection object or it died. Create one.
692 }else {
693 # release resources if we're closing a connection and making a new one
694 # FIXME: this needs to be smarter -- an error due to a malformed query or
695 # a missing index does not necessarily require us to close the connection
696 # and make a new one, particularly for a batch job. However, at
697 # first glance it does not look like there's a way to easily check
698 # the basic health of a ZOOM::Connection
699 $context->{"Zconn"}->{$server}->destroy() if defined($context->{"Zconn"}->{$server});
700
7011690µs $context->{"Zconn"}->{$server} = &_new_Zconn($server,$async,$auth,$piggyback,$syntax);
# spent 690µs making 1 call to C4::Context::_new_Zconn
702266µs $context->{ Zconn }->{ $server }->option(
# spent 59µs making 1 call to ZOOM::Connection::option # spent 7µs making 1 call to C4::Context::preference
703 preferredRecordSyntax => C4::Context->preference("marcflavour") );
704 return $context->{"Zconn"}->{$server};
705 }
706}
707
708=head2 _new_Zconn
709
- -
722
# spent 690µs (122+568) within C4::Context::_new_Zconn which was called: # once (122µs+568µs) by C4::Context::Zconn at line 701
sub _new_Zconn {
7232593µs my ($server,$async,$auth,$piggyback,$syntax) = @_;
724
725 my $tried=0; # first attempt
726 my $Zconn; # connection object
727 $server = "biblioserver" unless $server;
728 $syntax = "usmarc" unless $syntax;
729
730 my $host = $context->{'listen'}->{$server}->{'content'};
731 my $servername = $context->{"config"}->{$server};
732 my $user = $context->{"serverinfo"}->{$server}->{"user"};
733 my $password = $context->{"serverinfo"}->{$server}->{"password"};
734 $auth = 1 if($user && $password);
735 retry:
736 eval {
737 # set options
7381108µs my $o = new ZOOM::Options();
# spent 108µs making 1 call to ZOOM::Options::new
739181µs $o->option(user=>$user) if $auth;
# spent 81µs making 1 call to ZOOM::Options::option
740127µs $o->option(password=>$password) if $auth;
# spent 27µs making 1 call to ZOOM::Options::option
741150µs $o->option(async => 1) if $async;
# spent 50µs making 1 call to ZOOM::Options::option
742 $o->option(count => $piggyback) if $piggyback;
743133µs $o->option(cqlfile=> $context->{"server"}->{$server}->{"cql2rpn"});
# spent 33µs making 1 call to ZOOM::Options::option
744116µs $o->option(cclfile=> $context->{"serverinfo"}->{$server}->{"ccl2rpn"});
# spent 16µs making 1 call to ZOOM::Options::option
745116µs $o->option(preferredRecordSyntax => $syntax);
# spent 16µs making 1 call to ZOOM::Options::option
746140µs $o->option(elementSetName => "F"); # F for 'full' as opposed to B for 'brief'
# spent 40µs making 1 call to ZOOM::Options::option
747116µs $o->option(databaseName => ($servername?$servername:"biblios"));
# spent 16µs making 1 call to ZOOM::Options::option
748
749 # create a new connection object
750182µs $Zconn= create ZOOM::Connection($o);
# spent 82µs making 1 call to ZOOM::Connection::create
751
752 # forge to server
753179µs $Zconn->connect($host, 0);
# spent 79µs making 1 call to ZOOM::Connection::connect
754
755 # check for errors and warn
756120µs if ($Zconn->errcode() !=0) {
# spent 20µs making 1 call to ZOOM::Connection::errcode
757 warn "something wrong with the connection: ". $Zconn->errmsg();
758 }
759
760 };
761# if ($@) {
762# # Koha manages the Zebra server -- this doesn't work currently for me because of permissions issues
763# # Also, I'm skeptical about whether it's the best approach
764# warn "problem with Zebra";
765# if ( C4::Context->preference("ManageZebra") ) {
766# if ($@->code==10000 && $tried==0) { ##No connection try restarting Zebra
767# $tried=1;
768# warn "trying to restart Zebra";
769# my $res=system("zebrasrv -f $ENV{'KOHA_CONF'} >/koha/log/zebra-error.log");
770# goto "retry";
771# } else {
772# warn "Error ", $@->code(), ": ", $@->message(), "\n";
773# $Zconn="error";
774# return $Zconn;
775# }
776# }
777# }
778 return $Zconn;
779}
780
781# _new_dbh
782# Internal helper function (not a method!). This creates a new
783# database connection from the data given in the current context, and
784# returns it.
785sub _new_dbh
786
# spent 73.2ms (212µs+73.0) within C4::Context::_new_dbh which was called: # once (212µs+73.0ms) by C4::Context::dbh at line 861
{
787
788 ## $context
789 ## correct name for db_schme
790202.59ms my $db_driver;
791116µs if ($context->config("db_scheme")){
# spent 16µs making 1 call to C4::Context::config
792220µs $db_driver=db_scheme2dbi($context->config("db_scheme"));
# spent 13µs making 1 call to C4::Context::config # spent 7µs making 1 call to C4::Context::db_scheme2dbi
793 }else{
794 $db_driver="mysql";
795 }
796
797115µs my $db_name = $context->config("database");
# spent 15µs making 1 call to C4::Context::config
798115µs my $db_host = $context->config("hostname");
# spent 15µs making 1 call to C4::Context::config
799114µs my $db_port = $context->config("port") || '';
# spent 14µs making 1 call to C4::Context::config
800115µs my $db_user = $context->config("user");
# spent 15µs making 1 call to C4::Context::config
801114µs my $db_passwd = $context->config("pass");
# spent 14µs making 1 call to C4::Context::config
802 # MJR added or die here, as we can't work without dbh
803170.5ms my $dbh = DBI->connect("DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",
# spent 70.5ms making 1 call to DBI::connect
804 $db_user, $db_passwd, {'RaiseError' => $ENV{DEBUG}?1:0 }) or die $DBI::errstr;
805
806 # Check for the existence of a systempreference table; if we don't have this, we don't
807 # have a valid database and should not set RaiseError in order to allow the installer
808 # to run; installer will not run otherwise since we raise all db errors
809
810210µs eval {
# spent 10µs making 2 calls to DBI::common::STORE, avg 5µs/call
811327µs local $dbh->{PrintError} = 0;
# spent 18µs making 1 call to DBI::common::FETCH # spent 9µs making 2 calls to DBI::common::STORE, avg 4µs/call
812314µs local $dbh->{RaiseError} = 1;
# spent 8µs making 2 calls to DBI::common::STORE, avg 4µs/call # spent 6µs making 1 call to DBI::common::FETCH
81311.32ms $dbh->do(qq{SELECT * FROM systempreferences WHERE 1 = 0 });
# spent 1.32ms making 1 call to DBI::db::do
814 };
815
816 if ($@) {
817 $dbh->{RaiseError} = 0;
818 }
819
820 my $tz = $ENV{TZ};
821 if ( $db_driver eq 'mysql' ) {
822 # Koha 3.0 is utf-8, so force utf8 communication between mySQL and koha, whatever the mysql default config.
823 # this is better than modifying my.cnf (and forcing all communications to be in utf8)
82412µs $dbh->{'mysql_enable_utf8'}=1; #enable
# spent 2µs making 1 call to DBI::common::STORE
82511.02ms $dbh->do("set NAMES 'utf8'");
# spent 1.02ms making 1 call to DBI::db::do
826 ($tz) and $dbh->do(qq(SET time_zone = "$tz"));
827 }
828 elsif ( $db_driver eq 'Pg' ) {
829 $dbh->do( "set client_encoding = 'UTF8';" );
830 ($tz) and $dbh->do(qq(SET TIME ZONE = "$tz"));
831 }
832 return $dbh;
833}
834
835=head2 dbh
836
- -
850#'
851sub dbh
852
# spent 1.46s (31.2ms+1.43) within C4::Context::dbh which was called 1423 times, avg 1.03ms/call: # 295 times (6.17ms+285ms) by C4::Biblio::GetAuthorisedValueDesc at line 1573 of /usr/share/koha/lib/C4/Biblio.pm, avg 987µs/call # 161 times (3.36ms+232ms) by C4::Context::preference at line 549, avg 1.46ms/call # 148 times (3.19ms+138ms) by C4::Koha::GetAuthValCode at line 998 of /usr/share/koha/lib/C4/Koha.pm, avg 953µs/call # 143 times (2.94ms+136ms) by C4::Koha::GetKohaAuthorisedValueLib at line 1245 of /usr/share/koha/lib/C4/Koha.pm, avg 971µs/call # 100 times (2.58ms+94.6ms) by C4::Biblio::GetFrameworkCode at line 2084 of /usr/share/koha/lib/C4/Biblio.pm, avg 972µs/call # 75 times (1.68ms+72.3ms) by C4::Biblio::GetRecordValue at line 676 of /usr/share/koha/lib/C4/Biblio.pm, avg 987µs/call # 64 times (1.24ms+62.3ms) by C4::Branch::GetBranchName at line 180 of /usr/share/koha/lib/C4/Branch.pm, avg 993µs/call # 64 times (1.31ms+59.7ms) by C4::Reserves::GetReserveStatus at line 750 of /usr/share/koha/lib/C4/Reserves.pm, avg 954µs/call # 64 times (1.43ms+58.4ms) by C4::Circulation::GetTransfers at line 2775 of /usr/share/koha/lib/C4/Circulation.pm, avg 935µs/call # 57 times (1.26ms+52.8ms) by C4::Koha::getitemtypeinfo at line 440 of /usr/share/koha/lib/C4/Koha.pm, avg 949µs/call # 51 times (1.09ms+48.9ms) by C4::Koha::GetKohaAuthorisedValues at line 1168 of /usr/share/koha/lib/C4/Koha.pm, avg 980µs/call # 32 times (1.09ms+31.8ms) by C4::Items::GetHiddenItemnumbers at line 1650 of /usr/share/koha/lib/C4/Items.pm, avg 1.03ms/call # 27 times (599µs+25.3ms) by C4::Branch::GetBranches at line 108 of /usr/share/koha/lib/C4/Branch.pm, avg 958µs/call # 26 times (688µs+23.7ms) by C4::Koha::GetItemTypes at line 248 of /usr/share/koha/lib/C4/Koha.pm, avg 939µs/call # 25 times (481µs+26.4ms) by C4::Biblio::CountItemsIssued at line 2624 of /usr/share/koha/lib/C4/Biblio.pm, avg 1.07ms/call # 25 times (571µs+24.2ms) by C4::Biblio::GetMarcBiblio at line 1254 of /usr/share/koha/lib/C4/Biblio.pm, avg 993µs/call # 25 times (493µs+23.4ms) by C4::Items::GetItemsInfo at line 1204 of /usr/share/koha/lib/C4/Items.pm, avg 957µs/call # 25 times (533µs+21.1ms) by C4::Tags::get_tags at line 283 of /usr/share/koha/lib/C4/Tags.pm, avg 866µs/call # 3 times (88µs+3.01ms) by C4::XSLT::getAuthorisedValues4MARCSubfields at line 121 of /usr/share/koha/lib/C4/XSLT.pm, avg 1.03ms/call # 3 times (88µs+2.77ms) by C4::Auth::get_session at line 1520 of /usr/share/koha/lib/C4/Auth.pm, avg 951µs/call # 2 times (44µs+1.93ms) by C4::Koha::GetAuthorisedValues at line 1046 of /usr/share/koha/lib/C4/Koha.pm, avg 988µs/call # 2 times (41µs+1.67ms) by C4::VirtualShelves::GetSomeShelfNames at line 187 of /usr/share/koha/lib/C4/VirtualShelves.pm, avg 853µs/call # 2 times (125µs+1.32ms) by C4::Branch::GetBranchCategories at line 342 of /usr/share/koha/lib/C4/Branch.pm, avg 722µs/call # once (28µs+1.06ms) by C4::Search::searchResults at line 1630 of /usr/share/koha/lib/C4/Search.pm # once (34µs+1.01ms) by C4::Auth::checkauth at line 614 of /usr/share/koha/lib/C4/Auth.pm # once (19µs+954µs) by C4::Branch::GetBranchesCount at line 602 of /usr/share/koha/lib/C4/Branch.pm # once (16µs+735µs) by C4::Context::_new_marcfromkohafield at line 1020
{
85342711.39s my $self = shift;
854 my $sth;
855
85614221.36s if (defined($context->{"dbh"}) && $context->{"dbh"}->ping()) {
# spent 1.36s making 1422 calls to DBI::db::ping, avg 955µs/call
857 return $context->{"dbh"};
858 }
859
860 # No database handle or it died . Create one.
861173.2ms $context->{"dbh"} = &_new_dbh();
# spent 73.2ms making 1 call to C4::Context::_new_dbh
862
863 return $context->{"dbh"};
864}
865
866=head2 new_dbh
867
- -
879#'
880sub new_dbh
881{
882 my $self = shift;
883
884 return &_new_dbh();
885}
886
887=head2 set_dbh
888
- -
904#'
905sub set_dbh
906{
907 my $self = shift;
908 my $new_dbh = shift;
909
910 # Save the current database handle on the handle stack.
911 # We assume that $new_dbh is all good: if the caller wants to
912 # screw himself by passing an invalid handle, that's fine by
913 # us.
914 push @{$context->{"dbh_stack"}}, $context->{"dbh"};
915 $context->{"dbh"} = $new_dbh;
916}
917
918=head2 restore_dbh
919
- -
927#'
928sub restore_dbh
929{
930 my $self = shift;
931
932 if ($#{$context->{"dbh_stack"}} < 0)
933 {
934 # Stack underflow
935 die "DBH stack underflow";
936 }
937
938 # Pop the old database handle and set it.
939 $context->{"dbh"} = pop @{$context->{"dbh_stack"}};
940
941 # FIXME - If it is determined that restore_context should
942 # return something, then this function should, too.
943}
944
945=head2 queryparser
946
- -
953sub queryparser {
954 my $self = shift;
955 unless (defined $context->{"queryparser"}) {
956 $context->{"queryparser"} = &_new_queryparser();
957 }
958
959 return
960 defined( $context->{"queryparser"} )
961 ? $context->{"queryparser"}->new
962 : undef;
963}
964
965=head2 _new_queryparser
966
- -
973sub _new_queryparser {
974 my $qpmodules = {
975 'OpenILS::QueryParser' => undef,
976 'Koha::QueryParser::Driver::PQF' => undef
977 };
978 if ( can_load( 'modules' => $qpmodules ) ) {
979 my $QParser = Koha::QueryParser::Driver::PQF->new();
980 my $config_file = $context->config('queryparser_config');
981 $config_file ||= '/etc/koha/searchengine/queryparser.yaml';
982 if ( $QParser->load_config($config_file) ) {
983 # TODO: allow indexes to be configured in the database
984 return $QParser;
985 }
986 }
987 return;
988}
989
990=head2 marcfromkohafield
991
- -
1001#'
1002sub marcfromkohafield
1003
# spent 13.2ms (432µs+12.8) within C4::Context::marcfromkohafield which was called 93 times, avg 142µs/call: # 92 times (427µs+12.8ms) by C4::Biblio::GetMarcFromKohaField at line 1201 of /usr/share/koha/lib/C4/Biblio.pm, avg 144µs/call # once (4µs+0s) by C4::Biblio::_get_inverted_marc_field_map at line 2578 of /usr/share/koha/lib/C4/Biblio.pm
{
1004188558µs my $retval = {};
1005
1006 # If the hash already exists, return it.
1007 return $context->{"marcfromkohafield"} if defined($context->{"marcfromkohafield"});
1008
1009 # No hash. Create one.
1010412.8ms $context->{"marcfromkohafield"} = &_new_marcfromkohafield();
# spent 12.8ms making 1 call to C4::Context::_new_marcfromkohafield # spent 7µs making 2 calls to DBI::common::DESTROY, avg 3µs/call # spent 3µs making 1 call to DBD::_mem::common::DESTROY
1011
1012 return $context->{"marcfromkohafield"};
1013}
1014
1015# _new_marcfromkohafield
1016# Internal helper function (not a method!). This creates a new
1017# hash with stopwords
1018sub _new_marcfromkohafield
1019
# spent 12.8ms (1.58+11.2) within C4::Context::_new_marcfromkohafield which was called: # once (1.58ms+11.2ms) by C4::Context::marcfromkohafield at line 1010
{
102061212.0ms1750µs my $dbh = C4::Context->dbh;
# spent 750µs making 1 call to C4::Context::dbh
1021 my $marcfromkohafield;
102214µs295µs my $sth = $dbh->prepare("select frameworkcode,kohafield,tagfield,tagsubfield from marc_subfield_structure where kohafield > ''");
# spent 52µs making 1 call to DBI::db::prepare # spent 42µs making 1 call to DBD::mysql::db::prepare
102319.36ms $sth->execute;
# spent 9.36ms making 1 call to DBI::st::execute
10243041.04ms while (my ($frameworkcode,$kohafield,$tagfield,$tagsubfield) = $sth->fetchrow) {
# spent 1.04ms making 304 calls to DBI::st::fetchrow, avg 3µs/call
1025 my $retval = {};
1026 $marcfromkohafield->{$frameworkcode}->{$kohafield} = [$tagfield,$tagsubfield];
1027 }
1028 return $marcfromkohafield;
1029}
1030
1031=head2 stopwords
1032
- -
1042#'
1043sub stopwords
1044{
1045 my $retval = {};
1046
1047 # If the hash already exists, return it.
1048 return $context->{"stopwords"} if defined($context->{"stopwords"});
1049
1050 # No hash. Create one.
1051 $context->{"stopwords"} = &_new_stopwords();
1052
1053 return $context->{"stopwords"};
1054}
1055
1056# _new_stopwords
1057# Internal helper function (not a method!). This creates a new
1058# hash with stopwords
1059sub _new_stopwords
1060{
1061 my $dbh = C4::Context->dbh;
1062 my $stopwordlist;
1063 my $sth = $dbh->prepare("select word from stopwords");
1064 $sth->execute;
1065 while (my $stopword = $sth->fetchrow_array) {
1066 $stopwordlist->{$stopword} = uc($stopword);
1067 }
1068 $stopwordlist->{A} = "A" unless $stopwordlist;
1069 return $stopwordlist;
1070}
1071
1072=head2 userenv
1073
- -
1083#'
1084
# spent 364µs within C4::Context::userenv which was called 41 times, avg 9µs/call: # 32 times (302µs+0s) by C4::Search::searchResults at line 1872 of /usr/share/koha/lib/C4/Search.pm, avg 9µs/call # 5 times (17µs+0s) by C4::Auth::get_template_and_user at line 303 of /usr/share/koha/lib/C4/Auth.pm, avg 3µs/call # 2 times (20µs+0s) by C4::Koha::GetAuthorisedValues at line 1044 of /usr/share/koha/lib/C4/Koha.pm, avg 10µs/call # once (17µs+0s) by C4::Auth::get_template_and_user at line 381 of /usr/share/koha/lib/C4/Auth.pm # once (8µs+0s) by main::RUNTIME at line 715 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
sub userenv {
1085123428µs my $var = $context->{"activeuser"};
1086 if (defined $var and defined $context->{"userenv"}->{$var}) {
1087 return $context->{"userenv"}->{$var};
1088 } else {
1089 return;
1090 }
1091}
1092
1093=head2 set_userenv
1094
- -
1105#'
1106sub set_userenv {
1107 my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona)= @_;
1108 my $var=$context->{"activeuser"} || '';
1109 my $cell = {
1110 "number" => $usernum,
1111 "id" => $userid,
1112 "cardnumber" => $usercnum,
1113 "firstname" => $userfirstname,
1114 "surname" => $usersurname,
1115 #possibly a law problem
1116 "branch" => $userbranch,
1117 "branchname" => $branchname,
1118 "flags" => $userflags,
1119 "emailaddress" => $emailaddress,
1120 "branchprinter" => $branchprinter,
1121 "persona" => $persona,
1122 };
1123 $context->{userenv}->{$var} = $cell;
1124 return $cell;
1125}
1126
1127sub set_shelves_userenv {
1128 my ($type, $shelves) = @_ or return;
1129 my $activeuser = $context->{activeuser} or return;
1130 $context->{userenv}->{$activeuser}->{barshelves} = $shelves if $type eq 'bar';
1131 $context->{userenv}->{$activeuser}->{pubshelves} = $shelves if $type eq 'pub';
1132 $context->{userenv}->{$activeuser}->{totshelves} = $shelves if $type eq 'tot';
1133}
1134
1135sub get_shelves_userenv {
1136 my $active;
1137 unless ($active = $context->{userenv}->{$context->{activeuser}}) {
1138 $debug and warn "get_shelves_userenv cannot retrieve context->{userenv}->{context->{activeuser}}";
1139 return;
1140 }
1141 my $totshelves = $active->{totshelves} or undef;
1142 my $pubshelves = $active->{pubshelves} or undef;
1143 my $barshelves = $active->{barshelves} or undef;
1144 return ($totshelves, $pubshelves, $barshelves);
1145}
1146
1147=head2 _new_userenv
1148
- -
1160#'
1161sub _new_userenv
1162
# spent 12µs within C4::Context::_new_userenv which was called: # once (12µs+0s) by C4::Auth::checkauth at line 810 of /usr/share/koha/lib/C4/Auth.pm
{
1163319µs shift; # Useless except it compensates for bad calling style
1164 my ($sessionID)= @_;
1165 $context->{"activeuser"}=$sessionID;
1166}
1167
1168=head2 _unset_userenv
1169
- -
1176#'
1177
1178sub _unset_userenv
1179{
1180 my ($sessionID)= @_;
1181 undef $context->{"activeuser"} if ($context->{"activeuser"} eq $sessionID);
1182}
1183
1184
1185=head2 get_versions
1186
- -
1193#'
1194
1195# A little example sub to show more debugging info for CGI::Carp
1196sub get_versions {
1197 my %versions;
1198 $versions{kohaVersion} = KOHAVERSION();
1199 $versions{kohaDbVersion} = C4::Context->preference('version');
1200 $versions{osVersion} = join(" ", POSIX::uname());
1201 $versions{perlVersion} = $];
1202 {
12033262µs287µs
# spent 54µs (21+33) within C4::Context::BEGIN@1203 which was called: # once (21µs+33µs) by main::BEGIN@31 at line 1203
no warnings qw(exec); # suppress warnings if unable to find a program in $PATH
# spent 54µs making 1 call to C4::Context::BEGIN@1203 # spent 33µs making 1 call to warnings::unimport
1204 $versions{mysqlVersion} = `mysql -V`;
1205 $versions{apacheVersion} = `httpd -v`;
1206 $versions{apacheVersion} = `httpd2 -v` unless $versions{apacheVersion} ;
1207 $versions{apacheVersion} = `apache2 -v` unless $versions{apacheVersion} ;
1208 $versions{apacheVersion} = `/usr/sbin/apache2 -v` unless $versions{apacheVersion} ;
1209 }
1210 return %versions;
1211}
1212
1213
1214=head2 tz
1215
- -
1222sub tz {
1223 my $self = shift;
1224 if (!defined $context->{tz}) {
1225 $context->{tz} = DateTime::TimeZone->new(name => 'local');
1226 }
1227 return $context->{tz};
1228}
1229
- -
123218µs1;
1233__END__