Filename | /usr/share/koha/lib/C4/Context.pm |
Statements | Executed 10554 statements in 1.63s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1482 | 30 | 13 | 36.5ms | 1.49s | dbh | C4::Context::
1355 | 102 | 13 | 16.3ms | 394ms | preference | C4::Context::
1 | 1 | 1 | 15.0ms | 29.4ms | BEGIN@101 | C4::Context::
1 | 1 | 1 | 13.8ms | 14.8ms | BEGIN@103 | C4::Context::
1 | 1 | 1 | 10.5ms | 30.3ms | BEGIN@102 | C4::Context::
1 | 1 | 1 | 3.53ms | 18.2ms | BEGIN@107 | C4::Context::
1 | 1 | 1 | 2.17ms | 15.1ms | BEGIN@108 | C4::Context::
1 | 1 | 1 | 2.16ms | 5.87ms | _new_marcfromkohafield | C4::Context::
1 | 1 | 1 | 1.38ms | 6.39ms | BEGIN@106 | C4::Context::
1 | 1 | 1 | 714µs | 5.25ms | BEGIN@104 | C4::Context::
1 | 1 | 1 | 712µs | 1.52ms | BEGIN@21 | C4::Context::
1 | 1 | 1 | 689µs | 1.25ms | BEGIN@105 | C4::Context::
45 | 1 | 1 | 532µs | 532µs | _common_config | C4::Context::
93 | 2 | 1 | 496µs | 6.36ms | marcfromkohafield | C4::Context::
41 | 5 | 4 | 486µs | 486µs | userenv | C4::Context::
45 | 18 | 8 | 468µs | 1000µs | config | C4::Context::
1 | 1 | 1 | 356µs | 517µs | KOHAVERSION | C4::Context::
1 | 1 | 1 | 256µs | 54.6ms | _new_dbh | C4::Context::
3 | 3 | 3 | 201µs | 189ms | new | C4::Context::
41 | 41 | 41 | 156µs | 106ms | import | C4::Context::
1 | 1 | 1 | 131µs | 800µs | _new_Zconn | C4::Context::
3 | 3 | 2 | 79µs | 175µs | AUTOLOAD | C4::Context::
3 | 1 | 1 | 53µs | 188ms | read_config_file | C4::Context::
1 | 1 | 1 | 36µs | 889µs | Zconn | C4::Context::
1 | 1 | 1 | 33µs | 71µs | BEGIN@1203 | C4::Context::
1 | 1 | 1 | 24µs | 30µs | BEGIN@19 | C4::Context::
1 | 1 | 1 | 20µs | 39µs | BEGIN@20 | C4::Context::
2 | 2 | 2 | 14µs | 14µs | ismemcached | C4::Context::
1 | 1 | 1 | 13µs | 72µs | BEGIN@191 | C4::Context::
1 | 1 | 1 | 13µs | 13µs | BEGIN@23 | C4::Context::
1 | 1 | 1 | 12µs | 12µs | _new_userenv | C4::Context::
1 | 1 | 1 | 11µs | 11µs | BEGIN@1023 | XML::Simple::
1 | 1 | 1 | 6µs | 6µs | set_context | C4::Context::
1 | 1 | 1 | 5µs | 5µs | db_scheme2dbi | C4::Context::
0 | 0 | 0 | 0s | 0s | ModZebrations | C4::Context::
0 | 0 | 0 | 0s | 0s | _new_queryparser | C4::Context::
0 | 0 | 0 | 0s | 0s | _new_stopwords | C4::Context::
0 | 0 | 0 | 0s | 0s | _unset_userenv | C4::Context::
0 | 0 | 0 | 0s | 0s | boolean_preference | C4::Context::
0 | 0 | 0 | 0s | 0s | clear_syspref_cache | C4::Context::
0 | 0 | 0 | 0s | 0s | disable_syspref_cache | C4::Context::
0 | 0 | 0 | 0s | 0s | enable_syspref_cache | C4::Context::
0 | 0 | 0 | 0s | 0s | final_linear_version | C4::Context::
0 | 0 | 0 | 0s | 0s | get_shelves_userenv | C4::Context::
0 | 0 | 0 | 0s | 0s | get_versions | C4::Context::
0 | 0 | 0 | 0s | 0s | handle_errors | C4::Context::
0 | 0 | 0 | 0s | 0s | memcached | C4::Context::
0 | 0 | 0 | 0s | 0s | new_dbh | C4::Context::
0 | 0 | 0 | 0s | 0s | queryparser | C4::Context::
0 | 0 | 0 | 0s | 0s | restore_context | C4::Context::
0 | 0 | 0 | 0s | 0s | restore_dbh | C4::Context::
0 | 0 | 0 | 0s | 0s | set_dbh | C4::Context::
0 | 0 | 0 | 0s | 0s | set_preference | C4::Context::
0 | 0 | 0 | 0s | 0s | set_shelves_userenv | C4::Context::
0 | 0 | 0 | 0s | 0s | set_userenv | C4::Context::
0 | 0 | 0 | 0s | 0s | stopwords | C4::Context::
0 | 0 | 0 | 0s | 0s | tz | C4::Context::
0 | 0 | 0 | 0s | 0s | zebraconfig | C4::Context::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package 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 | |||||
19 | 3 | 44µs | 2 | 36µs | # spent 30µs (24+6) within C4::Context::BEGIN@19 which was called:
# once (24µs+6µs) by main::BEGIN@31 at line 19 # spent 30µs making 1 call to C4::Context::BEGIN@19
# spent 6µs making 1 call to strict::import |
20 | 3 | 53µs | 2 | 58µs | # spent 39µs (20+19) within C4::Context::BEGIN@20 which was called:
# once (20µs+19µs) by main::BEGIN@31 at line 20 # spent 39µs making 1 call to C4::Context::BEGIN@20
# spent 19µs making 1 call to warnings::import |
21 | 3 | 727µs | 2 | 1.71ms | # spent 1.52ms (712µs+808µs) within C4::Context::BEGIN@21 which was called:
# once (712µs+808µs) by main::BEGIN@31 at line 21 # spent 1.52ms making 1 call to C4::Context::BEGIN@21
# spent 193µs making 1 call to vars::import |
22 | |||||
23 | # spent 13µs within C4::Context::BEGIN@23 which was called:
# once (13µs+0s) by main::BEGIN@31 at line 99 | ||||
24 | 4 | 12µ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 | 1 | 18µs | 1 | 11µs | my $debug_level; # spent 11µs making 1 call to XML::Simple::BEGIN@1023 |
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; | ||||
87 | $memcached = 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) | ||||
95 | $ismemcached = $memcached->set('ismemcached','1'); | ||||
96 | } | ||||
97 | |||||
98 | $VERSION = '3.07.00.049'; | ||||
99 | 1 | 44µs | 1 | 13µs | } # spent 13µs making 1 call to C4::Context::BEGIN@23 |
100 | |||||
101 | 3 | 211µs | 2 | 29.4ms | # spent 29.4ms (15.0+14.4) within C4::Context::BEGIN@101 which was called:
# once (15.0ms+14.4ms) by main::BEGIN@31 at line 101 # spent 29.4ms making 1 call to C4::Context::BEGIN@101
# spent 63µs making 1 call to Exporter::import |
102 | 3 | 277µs | 1 | 30.3ms | # spent 30.3ms (10.5+19.8) within C4::Context::BEGIN@102 which was called:
# once (10.5ms+19.8ms) by main::BEGIN@31 at line 102 # spent 30.3ms making 1 call to C4::Context::BEGIN@102 |
103 | 3 | 252µs | 2 | 14.9ms | # spent 14.8ms (13.8+977µs) within C4::Context::BEGIN@103 which was called:
# once (13.8ms+977µs) by main::BEGIN@31 at line 103 # spent 14.8ms making 1 call to C4::Context::BEGIN@103
# spent 42µs making 1 call to XML::Simple::import |
104 | 3 | 218µs | 2 | 5.32ms | # spent 5.25ms (714µs+4.54) within C4::Context::BEGIN@104 which was called:
# once (714µs+4.54ms) by main::BEGIN@31 at line 104 # spent 5.25ms making 1 call to C4::Context::BEGIN@104
# spent 61µs making 1 call to Exporter::import |
105 | 3 | 199µs | 2 | 1.45ms | # spent 1.25ms (689µs+560µs) within C4::Context::BEGIN@105 which was called:
# once (689µs+560µs) by main::BEGIN@31 at line 105 # spent 1.25ms making 1 call to C4::Context::BEGIN@105
# spent 204µs making 1 call to Exporter::import |
106 | 3 | 192µs | 1 | 6.39ms | # spent 6.39ms (1.38+5.01) within C4::Context::BEGIN@106 which was called:
# once (1.38ms+5.01ms) by main::BEGIN@31 at line 106 # spent 6.39ms making 1 call to C4::Context::BEGIN@106 |
107 | 3 | 211µs | 1 | 18.2ms | # spent 18.2ms (3.53+14.7) within C4::Context::BEGIN@107 which was called:
# once (3.53ms+14.7ms) by main::BEGIN@31 at line 107 # spent 18.2ms making 1 call to C4::Context::BEGIN@107 |
108 | 3 | 226µs | 2 | 15.1ms | # spent 15.1ms (2.17+12.9) within C4::Context::BEGIN@108 which was called:
# once (2.17ms+12.9ms) by main::BEGIN@31 at line 108 # spent 15.1ms making 1 call to C4::Context::BEGIN@108
# spent 79µ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 | |||||
191 | 3 | 2.94ms | 2 | 130µs | # spent 72µs (13+59) within C4::Context::BEGIN@191 which was called:
# once (13µs+59µs) by main::BEGIN@31 at line 191 # spent 72µs making 1 call to C4::Context::BEGIN@191
# spent 59µs making 1 call to constant::import |
192 | # Default config file, if none is specified | ||||
193 | |||||
194 | 1 | 1µs | my $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 | |||||
202 | 1 | 600ns | $context = undef; # Initially, no context is set | ||
203 | 1 | 2µs | @context_stack = (); # Initially, no saved contexts | ||
204 | |||||
205 | |||||
206 | =head2 KOHAVERSION | ||||
207 | |||||
- - | |||||
212 | # spent 517µs (356+161) within C4::Context::KOHAVERSION which was called:
# once (356µs+161µs) by C4::Auth::_version_check at line 571 of /usr/share/koha/lib/C4/Auth.pm | ||||
213 | 4 | 258µs | 1 | 89µs | my $cgidir = C4::Context->intranetdir; # spent 89µ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) | ||||
217 | 1 | 24µs | if(-d $cgidir . "/cgi-bin"){ # spent 24µ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"; | ||||
222 | 1 | 5µs | return kohaversion(); # spent 5µs making 1 call to C4::Context::kohaversion | ||
223 | } | ||||
224 | |||||
225 | =head2 final_linear_version | ||||
226 | |||||
- - | |||||
232 | sub final_linear_version { | ||||
233 | return KOHAVERSION; | ||||
234 | } | ||||
235 | |||||
236 | =head2 read_config_file | ||||
237 | |||||
- - | |||||
261 | # spent 188ms (53µs+188) within C4::Context::read_config_file which was called 3 times, avg 62.8ms/call:
# 3 times (53µs+188ms) by C4::Context::new at line 387, avg 62.8ms/call | ||||
262 | 9 | 59µs | 3 | 188ms | my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => ''); # spent 188ms making 3 calls to XML::Simple::XMLin, avg 62.7ms/call |
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 14µs within C4::Context::ismemcached which was called 2 times, avg 7µs/call:
# once (9µ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 | ||||
278 | 2 | 32µs | return $ismemcached; | ||
279 | } | ||||
280 | |||||
281 | =head2 memcached | ||||
282 | |||||
- - | |||||
288 | sub memcached { | ||||
289 | 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 5µs within C4::Context::db_scheme2dbi which was called:
# once (5µs+0s) by C4::Context::_new_dbh at line 792 | ||||
300 | 2 | 5µ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 106ms (156µs+105) within C4::Context::import which was called 41 times, avg 2.57ms/call:
# once (15µs+105ms) by main::BEGIN@31 at line 31 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (7µs+0s) by C4::Accounts::BEGIN@23 at line 23 of /usr/share/koha/lib/C4/Accounts.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::Tags::BEGIN@26 at line 26 of /usr/share/koha/lib/C4/Tags.pm
# once (5µs+0s) by C4::XSLT::BEGIN@26 at line 26 of /usr/share/koha/lib/C4/XSLT.pm
# once (5µs+0s) by Koha::Calendar::BEGIN@9 at line 9 of /usr/share/koha/lib/Koha/Calendar.pm
# once (5µs+0s) by C4::Members::Attributes::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/Members/Attributes.pm
# once (5µs+0s) by C4::Budgets::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/Budgets.pm
# once (4µs+0s) by C4::Auth::BEGIN@28 at line 28 of /usr/share/koha/lib/C4/Auth.pm
# once (4µs+0s) by C4::Overdues::BEGIN@27 at line 27 of /usr/share/koha/lib/C4/Overdues.pm
# once (4µs+0s) by C4::ItemCirculationAlertPreference::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/ItemCirculationAlertPreference.pm
# once (4µs+0s) by C4::Circulation::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Circulation.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::VirtualShelves::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/VirtualShelves.pm
# once (4µs+0s) by C4::Search::BEGIN@21 at line 21 of /usr/share/koha/lib/C4/Search.pm
# once (4µs+0s) by C4::Branch::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/Branch.pm
# once (4µs+0s) by C4::Auth_with_cas::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/Auth_with_cas.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::SocialData::BEGIN@20 at line 20 of /usr/share/koha/lib/C4/SocialData.pm
# once (4µs+0s) by C4::Linker::BEGIN@48 at line 48 of /usr/share/koha/lib/C4/Linker.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 Koha::DateUtils::BEGIN@24 at line 24 of /usr/share/koha/lib/Koha/DateUtils.pm
# once (3µs+0s) by C4::Auth_with_ldap::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Auth_with_ldap.pm
# once (3µs+0s) by C4::Output::BEGIN@33 at line 33 of /usr/share/koha/lib/C4/Output.pm
# once (3µs+0s) by C4::Templates::BEGIN@37 at line 37 of /usr/share/koha/lib/C4/Templates.pm
# once (3µs+0s) by C4::NewsChannels::BEGIN@23 at line 23 of /usr/share/koha/lib/C4/NewsChannels.pm
# once (3µs+0s) by C4::Log::BEGIN@27 at line 27 of /usr/share/koha/lib/C4/Log.pm
# once (2µs+0s) by C4::Ratings::BEGIN@27 at line 27 of /usr/share/koha/lib/C4/Ratings.pm
# once (2µs+0s) by C4::SMS::BEGIN@38 at line 38 of /usr/share/koha/lib/C4/SMS.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::Message::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/Message.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::OAI::Sets::BEGIN@33 at line 33 of /usr/share/koha/lib/C4/OAI/Sets.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::Category::BEGIN@23 at line 23 of /usr/share/koha/lib/C4/Category.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::SQLHelper::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/SQLHelper.pm
# once (2µs+0s) by C4::Stats::BEGIN@24 at line 24 of /usr/share/koha/lib/C4/Stats.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::Members::BEGIN@25 at line 25 of /usr/share/koha/lib/C4/Members.pm
# once (2µs+0s) by C4::Members::AttributeTypes::BEGIN@22 at line 22 of /usr/share/koha/lib/C4/Members/AttributeTypes.pm | ||||
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? | ||||
318 | 46 | 279µs | return if $context; | ||
319 | |||||
320 | # no ? so load it! | ||||
321 | my ($pkg,$config_file) = @_ ; | ||||
322 | 1 | 105ms | my $new_ctx = __PACKAGE__->new($config_file); # spent 105ms making 1 call to C4::Context::new | ||
323 | return unless $new_ctx; | ||||
324 | |||||
325 | # if successfully loaded, use it by default | ||||
326 | 1 | 6µs | $new_ctx->set_context; # spent 6µ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 189ms (201µs+188) within C4::Context::new which was called 3 times, avg 62.8ms/call:
# once (53µs+105ms) by C4::Context::import at line 322
# once (74µs+43.2ms) by C4::Auth::BEGIN@39 at line 40 of /usr/share/koha/lib/C4/Auth_with_cas.pm
# once (74µs+39.7ms) by C4::Auth::BEGIN@39 at line 55 of /usr/share/koha/lib/C4/Auth_with_ldap.pm | ||||
352 | 63 | 243µ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. | ||||
364 | 3 | 42µs | if (exists $ENV{"KOHA_CONF"} and $ENV{'KOHA_CONF'} and -s $ENV{"KOHA_CONF"}) { # spent 42µs making 3 calls to C4::Context::CORE:ftsize, avg 14µ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 | ||||
380 | $self = $memcached->get('kohaconf'); | ||||
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 | 3 | 188ms | $self = read_config_file($conf_fname); # spent 188ms making 3 calls to C4::Context::read_config_file, avg 62.8ms/call | ||
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 | #' | ||||
425 | sub set_context | ||||
426 | # spent 6µs within C4::Context::set_context which was called:
# once (6µs+0s) by C4::Context::import at line 326 | ||||
427 | 6 | 8µ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 | #' | ||||
464 | sub 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 532µs within C4::Context::_common_config which was called 45 times, avg 12µs/call:
# 45 times (532µs+0s) by C4::Context::config at line 510, avg 12µs/call | ||||
497 | 180 | 728µ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 1000µs (468+532) within C4::Context::config which was called 45 times, avg 22µs/call:
# 25 times (317µs+388µs) by C4::XSLT::XSLTParse4Display at line 183 of /usr/share/koha/lib/C4/XSLT.pm, avg 28µs/call
# 3 times (38µs+29µs) by C4::Context::AUTOLOAD at line 660, avg 22µs/call
# 2 times (7µs+7µs) by C4::Templates::new at line 62 of /usr/share/koha/lib/C4/Templates.pm, avg 7µs/call
# once (15µs+18µs) by C4::Languages::getTranslatedLanguages at line 127 of /usr/share/koha/lib/C4/Languages.pm
# once (14µs+9µs) by main::BEGIN@45 at line 72 of /usr/share/koha/lib/C4/Output.pm
# once (11µs+11µs) by C4::Auth::BEGIN@39 at line 53 of /usr/share/koha/lib/C4/Auth.pm
# once (11µs+11µs) by C4::Budgets::BEGIN@24 at line 31 of /usr/share/koha/lib/C4/SQLHelper.pm
# once (9µs+10µs) by C4::Templates::_get_template_file at line 217 of /usr/share/koha/lib/C4/Templates.pm
# once (11µs+9µs) by C4::Auth::BEGIN@39 at line 56 of /usr/share/koha/lib/C4/Auth_with_ldap.pm
# once (8µs+11µs) by C4::Output::BEGIN@36 at line 208 of /usr/share/koha/lib/C4/Templates.pm
# once (5µs+9µs) by C4::Templates::new at line 50 of /usr/share/koha/lib/C4/Templates.pm
# once (3µs+3µs) by C4::Context::_new_dbh at line 791
# once (3µs+3µs) by C4::Context::_new_dbh at line 798
# once (3µs+3µs) by C4::Context::_new_dbh at line 797
# once (3µs+3µs) by C4::Context::_new_dbh at line 792
# once (3µs+3µs) by C4::Context::_new_dbh at line 800
# once (3µs+3µs) by C4::Context::_new_dbh at line 799
# once (3µs+3µs) by C4::Context::_new_dbh at line 801 | ||||
510 | 45 | 378µs | 45 | 532µs | return _common_config($_[1],'config'); # spent 532µs making 45 calls to C4::Context::_common_config, avg 12µs/call |
511 | } | ||||
512 | sub zebraconfig { | ||||
513 | return _common_config($_[1],'server'); | ||||
514 | } | ||||
515 | sub 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 | |||||
538 | 1 | 400ns | my %sysprefs; | ||
539 | 1 | 300ns | my $use_syspref_cache = 1; | ||
540 | |||||
541 | # spent 394ms (16.3+378) within C4::Context::preference which was called 1355 times, avg 291µs/call:
# 550 times (3.17ms+38.7ms) by C4::XSLT::XSLTParse4Display at line 212 of /usr/share/koha/lib/C4/XSLT.pm, avg 76µs/call
# 80 times (956µs+0s) by C4::Koha::getitemtypeimagesrc at line 474 of /usr/share/koha/lib/C4/Koha.pm, avg 12µs/call
# 69 times (3.11ms+129ms) by C4::Auth::get_template_and_user at line 381 of /usr/share/koha/lib/C4/Auth.pm, avg 1.92ms/call
# 57 times (622µs+2.01ms) by C4::Koha::getitemtypeimagesrc at line 471 of /usr/share/koha/lib/C4/Koha.pm, avg 46µs/call
# 32 times (317µs+2.16ms) by C4::Items::GetHiddenItemnumbers at line 1640 of /usr/share/koha/lib/C4/Items.pm, avg 77µs/call
# 32 times (412µs+2.05ms) by C4::Search::searchResults at line 1859 of /usr/share/koha/lib/C4/Search.pm, avg 77µs/call
# 32 times (104µs+0s) by C4::Search::searchResults at line 1860 of /usr/share/koha/lib/C4/Search.pm, avg 3µs/call
# 25 times (220µs+2.58ms) by main::RUNTIME at line 590 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 112µs/call
# 25 times (236µs+1.93ms) by C4::Search::searchResults at line 1829 of /usr/share/koha/lib/C4/Search.pm, avg 87µs/call
# 25 times (343µs+0s) by C4::XSLT::XSLTParse4Display at line 200 of /usr/share/koha/lib/C4/XSLT.pm, avg 14µs/call
# 25 times (338µs+0s) by C4::Search::searchResults at line 2014 of /usr/share/koha/lib/C4/Search.pm, avg 14µs/call
# 25 times (262µs+0s) by C4::Items::GetItemsInfo at line 1206 of /usr/share/koha/lib/C4/Items.pm, avg 10µs/call
# 25 times (232µs+0s) by C4::Biblio::GetCOinSBiblio at line 1371 of /usr/share/koha/lib/C4/Biblio.pm, avg 9µs/call
# 25 times (225µs+0s) by C4::Search::searchResults at line 2020 of /usr/share/koha/lib/C4/Search.pm, avg 9µs/call
# 25 times (213µs+0s) by C4::Biblio::GetMarcBiblio at line 1259 of /usr/share/koha/lib/C4/Biblio.pm, avg 9µs/call
# 25 times (200µs+0s) by C4::Search::searchResults at line 1778 of /usr/share/koha/lib/C4/Search.pm, avg 8µs/call
# 25 times (135µs+0s) by C4::XSLT::XSLTParse4Display at line 184 of /usr/share/koha/lib/C4/XSLT.pm, avg 5µs/call
# 25 times (134µs+0s) by C4::Search::searchResults at line 1716 of /usr/share/koha/lib/C4/Search.pm, avg 5µs/call
# 25 times (128µs+0s) by C4::XSLT::XSLTParse4Display at line 185 of /usr/share/koha/lib/C4/XSLT.pm, avg 5µs/call
# 25 times (118µs+0s) by C4::Search::searchResults at line 2044 of /usr/share/koha/lib/C4/Search.pm, avg 5µs/call
# 25 times (102µs+0s) by C4::Biblio::GetMarcBiblio at line 1263 of /usr/share/koha/lib/C4/Biblio.pm, avg 4µs/call
# 25 times (76µs+0s) by C4::XSLT::XSLTParse4Display at line 161 of /usr/share/koha/lib/C4/XSLT.pm, avg 3µs/call
# 23 times (206µs+2.18ms) by C4::Search::__ANON__[/usr/share/koha/lib/C4/Search.pm:670] at line 582 of /usr/share/koha/lib/C4/Search.pm, avg 104µs/call
# 15 times (701µs+32.3ms) by C4::Auth::get_template_and_user at line 303 of /usr/share/koha/lib/C4/Auth.pm, avg 2.20ms/call
# 4 times (129µs+4.31ms) by main::RUNTIME at line 353 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 1.11ms/call
# 3 times (48µs+2.08ms) by C4::Templates::getlanguage at line 326 of /usr/share/koha/lib/C4/Templates.pm, avg 708µs/call
# 3 times (83µs+2.01ms) by C4::Auth::get_session at line 1520 of /usr/share/koha/lib/C4/Auth.pm, avg 698µs/call
# 2 times (95µs+3.11ms) by main::RUNTIME at line 165 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 1.60ms/call
# 2 times (38µs+2.10ms) by C4::Templates::themelanguage at line 289 of /usr/share/koha/lib/C4/Templates.pm, avg 1.07ms/call
# 2 times (73µs+1.97ms) by C4::Auth::get_template_and_user at line 297 of /usr/share/koha/lib/C4/Auth.pm, avg 1.02ms/call
# 2 times (11µs+0s) by main::RUNTIME at line 576 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 6µs/call
# 2 times (7µs+0s) by main::RUNTIME at line 141 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl, avg 3µs/call
# once (57µs+55.7ms) by C4::Auth::BEGIN@39 at line 54 of /usr/share/koha/lib/C4/Auth.pm
# once (63µs+3.29ms) by C4::Search::parseQuery at line 1178 of /usr/share/koha/lib/C4/Search.pm
# once (80µs+2.59ms) by main::RUNTIME at line 885 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (114µs+2.47ms) by main::RUNTIME at line 888 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (139µs+2.29ms) by main::RUNTIME at line 751 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (45µs+2.30ms) by main::RUNTIME at line 210 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (37µs+2.30ms) by C4::Auth::BEGIN@39 at line 55 of /usr/share/koha/lib/C4/Auth.pm
# once (92µs+2.24ms) by main::RUNTIME at line 857 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (58µs+2.26ms) by C4::Auth::get_template_and_user at line 373 of /usr/share/koha/lib/C4/Auth.pm
# once (60µs+2.26ms) by C4::Auth::checkauth at line 818 of /usr/share/koha/lib/C4/Auth.pm
# once (73µs+2.18ms) by C4::Auth::checkauth at line 625 of /usr/share/koha/lib/C4/Auth.pm
# once (63µs+2.19ms) by C4::Auth::get_template_and_user at line 290 of /usr/share/koha/lib/C4/Auth.pm
# once (45µs+2.18ms) by main::RUNTIME at line 438 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (64µs+2.16ms) by C4::Search::buildQuery at line 1262 of /usr/share/koha/lib/C4/Search.pm
# once (36µs+2.18ms) by main::RUNTIME at line 116 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (57µs+2.11ms) by main::RUNTIME at line 479 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (36µs+2.13ms) by C4::Templates::gettemplate at line 233 of /usr/share/koha/lib/C4/Templates.pm
# once (234µs+1.91ms) by main::RUNTIME at line 895 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (48µs+2.04ms) by main::RUNTIME at line 439 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (53µs+2.00ms) by main::RUNTIME at line 33 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (43µs+2.01ms) by C4::Auth::BEGIN@39 at line 53 of /usr/share/koha/lib/C4/Auth_with_cas.pm
# once (46µs+1.99ms) by C4::Search::buildQuery at line 1264 of /usr/share/koha/lib/C4/Search.pm
# once (40µs+1.98ms) by main::RUNTIME at line 101 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (46µs+1.96ms) by C4::Search::buildQuery at line 1263 of /usr/share/koha/lib/C4/Search.pm
# once (47µs+1.94ms) by C4::Auth::_version_check at line 556 of /usr/share/koha/lib/C4/Auth.pm
# once (52µs+1.93ms) by main::RUNTIME at line 148 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (93µs+1.88ms) by main::RUNTIME at line 718 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (54µs+1.91ms) by C4::Auth::_timeout_syspref at line 596 of /usr/share/koha/lib/C4/Auth.pm
# once (42µs+1.91ms) by C4::Auth::get_template_and_user at line 361 of /usr/share/koha/lib/C4/Auth.pm
# once (64µs+1.86ms) by main::RUNTIME at line 890 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (33µs+1.87ms) by main::RUNTIME at line 61 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (70µs+1.83ms) by main::RUNTIME at line 893 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (44µs+1.83ms) by C4::Search::buildQuery at line 1265 of /usr/share/koha/lib/C4/Search.pm
# once (84µs+1.79ms) by main::RUNTIME at line 757 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (57µs+1.81ms) by C4::Auth::get_template_and_user at line 365 of /usr/share/koha/lib/C4/Auth.pm
# once (45µs+1.81ms) by main::BEGIN@85 at line 86 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (77µs+1.78ms) by C4::Templates::output at line 103 of /usr/share/koha/lib/C4/Templates.pm
# once (40µs+1.81ms) by main::RUNTIME at line 481 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (83µs+1.76ms) by main::RUNTIME at line 894 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (39µs+1.79ms) by C4::Auth::_version_check at line 551 of /usr/share/koha/lib/C4/Auth.pm
# once (71µs+1.72ms) by main::RUNTIME at line 123 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (56µs+1.73ms) by main::RUNTIME at line 494 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (137µs+1.64ms) by main::RUNTIME at line 150 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (48µs+1.72ms) by C4::Branch::onlymine at line 146 of /usr/share/koha/lib/C4/Branch.pm
# once (48µs+1.70ms) by C4::Tags::BEGIN@35 at line 54 of /usr/share/koha/lib/C4/Tags.pm
# once (35µs+1.65ms) by C4::Search::getRecords at line 343 of /usr/share/koha/lib/C4/Search.pm
# once (50µs+1.63ms) by C4::Search::buildQuery at line 1266 of /usr/share/koha/lib/C4/Search.pm
# once (43µs+1.63ms) by main::RUNTIME at line 147 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (69µs+0s) by main::RUNTIME at line 586 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (14µs+0s) by main::RUNTIME at line 712 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (11µs+0s) by C4::Search::searchResults at line 1638 of /usr/share/koha/lib/C4/Search.pm
# once (11µs+0s) by main::RUNTIME at line 207 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (11µs+0s) by C4::Auth::get_template_and_user at line 461 of /usr/share/koha/lib/C4/Auth.pm
# once (11µs+0s) by C4::Search::searchResults at line 1695 of /usr/share/koha/lib/C4/Search.pm
# once (10µs+0s) by main::RUNTIME at line 755 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (9µs+0s) by main::RUNTIME at line 153 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (9µs+0s) by C4::Languages::getTranslatedLanguages at line 126 of /usr/share/koha/lib/C4/Languages.pm
# once (8µs+0s) by main::RUNTIME at line 608 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µs+0s) by main::RUNTIME at line 624 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µ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 (7µs+0s) by C4::Templates::output at line 110 of /usr/share/koha/lib/C4/Templates.pm
# once (6µs+0s) by C4::Koha::getFacets at line 689 of /usr/share/koha/lib/C4/Koha.pm
# once (6µs+0s) by C4::Search::_build_weighted_query at line 847 of /usr/share/koha/lib/C4/Search.pm
# once (6µs+0s) by main::RUNTIME at line 162 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by C4::Context::Zconn at line 702
# once (3µs+0s) by C4::Koha::getFacets at line 786 of /usr/share/koha/lib/C4/Koha.pm
# once (3µs+0s) by C4::Templates::output at line 112 of /usr/share/koha/lib/C4/Templates.pm
# once (3µs+0s) by C4::Templates::output at line 113 of /usr/share/koha/lib/C4/Templates.pm
# once (3µs+0s) by C4::Search::_build_weighted_query at line 848 of /usr/share/koha/lib/C4/Search.pm
# once (2µs+0s) by C4::Search::_build_weighted_query at line 849 of /usr/share/koha/lib/C4/Search.pm | ||||
542 | 4709 | 15.6ms | 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 | |||||
549 | 161 | 206ms | my $dbh = C4::Context->dbh or return 0; # spent 206ms making 161 calls to C4::Context::dbh, avg 1.28ms/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 | ||||
557 | END_SQL | ||||
558 | 1 | 161ms | 483 | 198ms | $sysprefs{$var} = $dbh->selectrow_array( $sql, {}, $var ); # spent 170ms making 161 calls to DBI::db::selectrow_array, avg 1.06ms/call
# spent 14.6ms making 161 calls to DBI::db::prepare, avg 91µs/call
# spent 13.1ms making 161 calls to DBD::mysql::db::prepare, avg 82µs/call |
559 | 483 | 2.33ms | return $sysprefs{$var}; # spent 1.81ms making 322 calls to DBI::common::DESTROY, avg 6µs/call
# spent 516µs making 161 calls to DBD::_mem::common::DESTROY, avg 3µs/call | ||
560 | } | ||||
561 | |||||
562 | sub 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 | |||||
- - | |||||
578 | sub enable_syspref_cache { | ||||
579 | my ($self) = @_; | ||||
580 | $use_syspref_cache = 1; | ||||
581 | } | ||||
582 | |||||
583 | =head2 disable_syspref_cache | ||||
584 | |||||
- - | |||||
592 | sub disable_syspref_cache { | ||||
593 | my ($self) = @_; | ||||
594 | $use_syspref_cache = 0; | ||||
595 | $self->clear_syspref_cache(); | ||||
596 | } | ||||
597 | |||||
598 | =head2 clear_syspref_cache | ||||
599 | |||||
- - | |||||
608 | sub clear_syspref_cache { | ||||
609 | %sysprefs = (); | ||||
610 | } | ||||
611 | |||||
612 | =head2 set_preference | ||||
613 | |||||
- - | |||||
621 | sub 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. | ||||
654 | sub AUTOLOAD | ||||
655 | # spent 175µs (79+96) within C4::Context::AUTOLOAD which was called 3 times, avg 58µs/call:
# once (43µs+46µs) by C4::Context::KOHAVERSION at line 213
# once (17µs+27µs) by C4::Auth::BEGIN@39 at line 56 of /usr/share/koha/lib/C4/Auth.pm
# once (19µs+23µs) by C4::Auth::BEGIN@39 at line 58 of /usr/share/koha/lib/C4/Auth.pm | ||||
656 | 9 | 100µs | my $self = shift; | ||
657 | |||||
658 | 3 | 29µs | $AUTOLOAD =~ s/.*:://; # Chop off the package name, # spent 29µs making 3 calls to C4::Context::CORE:subst, avg 10µs/call | ||
659 | # leaving only the function name. | ||||
660 | 3 | 67µs | return $self->config($AUTOLOAD); # spent 67µs making 3 calls to C4::Context::config, avg 22µs/call | ||
661 | } | ||||
662 | |||||
663 | =head2 Zconn | ||||
664 | |||||
- - | |||||
682 | # spent 889µs (36+854) within C4::Context::Zconn which was called:
# once (36µs+854µs) by C4::Search::getRecords at line 349 of /usr/share/koha/lib/C4/Search.pm | ||||
683 | 11 | 27µ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 | |||||
701 | 1 | 800µs | $context->{"Zconn"}->{$server} = &_new_Zconn($server,$async,$auth,$piggyback,$syntax); # spent 800µs making 1 call to C4::Context::_new_Zconn | ||
702 | 2 | 54µs | $context->{ Zconn }->{ $server }->option( # spent 50µs making 1 call to ZOOM::Connection::option
# spent 5µ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 800µs (131+669) within C4::Context::_new_Zconn which was called:
# once (131µs+669µs) by C4::Context::Zconn at line 701 | ||||
723 | 25 | 95µ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 | ||||
738 | 1 | 165µs | my $o = new ZOOM::Options(); # spent 165µs making 1 call to ZOOM::Options::new | ||
739 | 1 | 85µs | $o->option(user=>$user) if $auth; # spent 85µs making 1 call to ZOOM::Options::option | ||
740 | 1 | 24µs | $o->option(password=>$password) if $auth; # spent 24µs making 1 call to ZOOM::Options::option | ||
741 | 1 | 26µs | $o->option(async => 1) if $async; # spent 26µs making 1 call to ZOOM::Options::option | ||
742 | $o->option(count => $piggyback) if $piggyback; | ||||
743 | 1 | 38µs | $o->option(cqlfile=> $context->{"server"}->{$server}->{"cql2rpn"}); # spent 38µs making 1 call to ZOOM::Options::option | ||
744 | 1 | 18µs | $o->option(cclfile=> $context->{"serverinfo"}->{$server}->{"ccl2rpn"}); # spent 18µs making 1 call to ZOOM::Options::option | ||
745 | 1 | 21µs | $o->option(preferredRecordSyntax => $syntax); # spent 21µs making 1 call to ZOOM::Options::option | ||
746 | 1 | 17µs | $o->option(elementSetName => "F"); # F for 'full' as opposed to B for 'brief' # spent 17µs making 1 call to ZOOM::Options::option | ||
747 | 1 | 16µs | $o->option(databaseName => ($servername?$servername:"biblios")); # spent 16µs making 1 call to ZOOM::Options::option | ||
748 | |||||
749 | # create a new connection object | ||||
750 | 1 | 134µs | $Zconn= create ZOOM::Connection($o); # spent 134µs making 1 call to ZOOM::Connection::create | ||
751 | |||||
752 | # forge to server | ||||
753 | 1 | 106µs | $Zconn->connect($host, 0); # spent 106µs making 1 call to ZOOM::Connection::connect | ||
754 | |||||
755 | # check for errors and warn | ||||
756 | 1 | 21µs | if ($Zconn->errcode() !=0) { # spent 21µ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. | ||||
785 | sub _new_dbh | ||||
786 | # spent 54.6ms (256µs+54.3) within C4::Context::_new_dbh which was called:
# once (256µs+54.3ms) by C4::Context::dbh at line 861 | ||||
787 | |||||
788 | ## $context | ||||
789 | ## correct name for db_schme | ||||
790 | 20 | 2.13ms | my $db_driver; | ||
791 | 1 | 6µs | if ($context->config("db_scheme")){ # spent 6µs making 1 call to C4::Context::config | ||
792 | 2 | 11µs | $db_driver=db_scheme2dbi($context->config("db_scheme")); # spent 6µs making 1 call to C4::Context::config
# spent 5µs making 1 call to C4::Context::db_scheme2dbi | ||
793 | }else{ | ||||
794 | $db_driver="mysql"; | ||||
795 | } | ||||
796 | |||||
797 | 1 | 6µs | my $db_name = $context->config("database"); # spent 6µs making 1 call to C4::Context::config | ||
798 | 1 | 6µs | my $db_host = $context->config("hostname"); # spent 6µs making 1 call to C4::Context::config | ||
799 | 1 | 6µs | my $db_port = $context->config("port") || ''; # spent 6µs making 1 call to C4::Context::config | ||
800 | 1 | 6µs | my $db_user = $context->config("user"); # spent 6µs making 1 call to C4::Context::config | ||
801 | 1 | 6µs | my $db_passwd = $context->config("pass"); # spent 6µs making 1 call to C4::Context::config | ||
802 | # MJR added or die here, as we can't work without dbh | ||||
803 | 1 | 52.4ms | my $dbh = DBI->connect("DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port", # spent 52.4ms 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 | |||||
810 | 2 | 11µs | eval { # spent 11µs making 2 calls to DBI::common::STORE, avg 6µs/call | ||
811 | 3 | 26µs | local $dbh->{PrintError} = 0; # spent 18µs making 1 call to DBI::common::FETCH
# spent 8µs making 2 calls to DBI::common::STORE, avg 4µs/call | ||
812 | 3 | 13µs | local $dbh->{RaiseError} = 1; # spent 7µs making 2 calls to DBI::common::STORE, avg 4µs/call
# spent 6µs making 1 call to DBI::common::FETCH | ||
813 | 1 | 852µs | $dbh->do(qq{SELECT * FROM systempreferences WHERE 1 = 0 }); # spent 852µs 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) | ||||
824 | 1 | 3µs | $dbh->{'mysql_enable_utf8'}=1; #enable # spent 3µs making 1 call to DBI::common::STORE | ||
825 | 1 | 979µs | $dbh->do("set NAMES 'utf8'"); # spent 979µs 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 | #' | ||||
851 | sub dbh | ||||
852 | # spent 1.49s (36.5ms+1.45) within C4::Context::dbh which was called 1482 times, avg 1.00ms/call:
# 295 times (7.29ms+282ms) by C4::Biblio::GetAuthorisedValueDesc at line 1573 of /usr/share/koha/lib/C4/Biblio.pm, avg 980µs/call
# 161 times (3.48ms+202ms) by C4::Context::preference at line 549, avg 1.28ms/call
# 148 times (3.49ms+136ms) by C4::Koha::GetAuthValCode at line 998 of /usr/share/koha/lib/C4/Koha.pm, avg 944µs/call
# 143 times (3.37ms+131ms) by C4::Koha::GetKohaAuthorisedValueLib at line 1245 of /usr/share/koha/lib/C4/Koha.pm, avg 937µs/call
# 100 times (3.09ms+97.5ms) by C4::Biblio::GetFrameworkCode at line 2084 of /usr/share/koha/lib/C4/Biblio.pm, avg 1.01ms/call
# 75 times (1.90ms+71.1ms) by C4::Biblio::GetRecordValue at line 676 of /usr/share/koha/lib/C4/Biblio.pm, avg 974µs/call
# 64 times (1.41ms+61.6ms) by C4::Reserves::GetReserveStatus at line 750 of /usr/share/koha/lib/C4/Reserves.pm, avg 984µs/call
# 64 times (1.52ms+61.2ms) by C4::Circulation::GetTransfers at line 2775 of /usr/share/koha/lib/C4/Circulation.pm, avg 980µs/call
# 64 times (1.39ms+59.3ms) by C4::Branch::GetBranchName at line 180 of /usr/share/koha/lib/C4/Branch.pm, avg 948µs/call
# 57 times (1.29ms+52.7ms) by C4::Koha::getitemtypeinfo at line 440 of /usr/share/koha/lib/C4/Koha.pm, avg 947µs/call
# 51 times (1.16ms+47.0ms) by C4::Koha::GetKohaAuthorisedValues at line 1168 of /usr/share/koha/lib/C4/Koha.pm, avg 943µs/call
# 33 times (781µs+28.3ms) by C4::Languages::language_get_description at line 350 of /usr/share/koha/lib/C4/Languages.pm, avg 880µs/call
# 32 times (1.19ms+34.0ms) by C4::Items::GetHiddenItemnumbers at line 1650 of /usr/share/koha/lib/C4/Items.pm, avg 1.10ms/call
# 27 times (697µs+24.3ms) by C4::Branch::GetBranches at line 108 of /usr/share/koha/lib/C4/Branch.pm, avg 925µs/call
# 26 times (886µs+24.0ms) by C4::Koha::GetItemTypes at line 248 of /usr/share/koha/lib/C4/Koha.pm, avg 956µs/call
# 25 times (615µs+26.5ms) by C4::Biblio::GetMarcBiblio at line 1254 of /usr/share/koha/lib/C4/Biblio.pm, avg 1.08ms/call
# 25 times (680µs+25.7ms) by C4::Tags::get_tags at line 283 of /usr/share/koha/lib/C4/Tags.pm, avg 1.05ms/call
# 25 times (502µs+24.8ms) by C4::Biblio::CountItemsIssued at line 2624 of /usr/share/koha/lib/C4/Biblio.pm, avg 1.01ms/call
# 25 times (606µs+23.8ms) by C4::Items::GetItemsInfo at line 1204 of /usr/share/koha/lib/C4/Items.pm, avg 978µs/call
# 25 times (699µs+23.5ms) by C4::Biblio::GetMarcStructure at line 1082 of /usr/share/koha/lib/C4/Biblio.pm, avg 968µs/call
# 3 times (105µs+3.25ms) by C4::XSLT::getAuthorisedValues4MARCSubfields at line 121 of /usr/share/koha/lib/C4/XSLT.pm, avg 1.12ms/call
# 3 times (98µs+3.04ms) by C4::Auth::get_session at line 1521 of /usr/share/koha/lib/C4/Auth.pm, avg 1.05ms/call
# 2 times (74µs+1.94ms) by C4::VirtualShelves::GetSomeShelfNames at line 187 of /usr/share/koha/lib/C4/VirtualShelves.pm, avg 1.01ms/call
# 2 times (33µs+1.81ms) by C4::Koha::GetAuthorisedValues at line 1046 of /usr/share/koha/lib/C4/Koha.pm, avg 920µs/call
# 2 times (49µs+1.51ms) by C4::Branch::GetBranchCategories at line 342 of /usr/share/koha/lib/C4/Branch.pm, avg 778µs/call
# once (38µs+981µs) by C4::Search::searchResults at line 1630 of /usr/share/koha/lib/C4/Search.pm
# once (26µs+858µs) by C4::Context::_new_marcfromkohafield at line 1020
# once (18µs+787µs) by C4::Auth::checkauth at line 614 of /usr/share/koha/lib/C4/Auth.pm
# once (16µs+723µs) by C4::Branch::GetBranchesCount at line 602 of /usr/share/koha/lib/C4/Branch.pm
# once (14µs+581µs) by C4::Languages::getAllLanguages at line 186 of /usr/share/koha/lib/C4/Languages.pm | ||||
853 | 4448 | 1.44s | my $self = shift; | ||
854 | my $sth; | ||||
855 | |||||
856 | 1481 | 1.40s | if (defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { # spent 1.40s making 1481 calls to DBI::db::ping, avg 943µs/call | ||
857 | return $context->{"dbh"}; | ||||
858 | } | ||||
859 | |||||
860 | # No database handle or it died . Create one. | ||||
861 | 1 | 54.6ms | $context->{"dbh"} = &_new_dbh(); # spent 54.6ms making 1 call to C4::Context::_new_dbh | ||
862 | |||||
863 | return $context->{"dbh"}; | ||||
864 | } | ||||
865 | |||||
866 | =head2 new_dbh | ||||
867 | |||||
- - | |||||
879 | #' | ||||
880 | sub new_dbh | ||||
881 | { | ||||
882 | my $self = shift; | ||||
883 | |||||
884 | return &_new_dbh(); | ||||
885 | } | ||||
886 | |||||
887 | =head2 set_dbh | ||||
888 | |||||
- - | |||||
904 | #' | ||||
905 | sub 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 | #' | ||||
928 | sub 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 | |||||
- - | |||||
953 | sub 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 | |||||
- - | |||||
973 | sub _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 | #' | ||||
1002 | sub marcfromkohafield | ||||
1003 | # spent 6.36ms (496µs+5.87) within C4::Context::marcfromkohafield which was called 93 times, avg 68µs/call:
# 92 times (484µs+5.87ms) by C4::Biblio::GetMarcFromKohaField at line 1201 of /usr/share/koha/lib/C4/Biblio.pm, avg 69µs/call
# once (12µs+0s) by C4::Biblio::_get_inverted_marc_field_map at line 2578 of /usr/share/koha/lib/C4/Biblio.pm | ||||
1004 | 188 | 659µ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. | ||||
1010 | 4 | 5.89ms | $context->{"marcfromkohafield"} = &_new_marcfromkohafield(); # spent 5.87ms making 1 call to C4::Context::_new_marcfromkohafield
# spent 17µs making 2 calls to DBI::common::DESTROY, avg 8µs/call
# spent 5µ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 | ||||
1018 | sub _new_marcfromkohafield | ||||
1019 | # spent 5.87ms (2.16+3.70) within C4::Context::_new_marcfromkohafield which was called:
# once (2.16ms+3.70ms) by C4::Context::marcfromkohafield at line 1010 | ||||
1020 | 612 | 4.91ms | 1 | 884µs | my $dbh = C4::Context->dbh; # spent 884µs making 1 call to C4::Context::dbh |
1021 | my $marcfromkohafield; | ||||
1022 | 1 | 6µs | 2 | 144µs | my $sth = $dbh->prepare("select frameworkcode,kohafield,tagfield,tagsubfield from marc_subfield_structure where kohafield > ''"); # spent 78µs making 1 call to DBI::db::prepare
# spent 66µs making 1 call to DBD::mysql::db::prepare |
1023 | 1 | 1.35ms | # spent 11µs within XML::Simple::BEGIN@1023 which was called:
# once (11µs+0s) by XML::Simple::CORE:match at line 31 # spent 1.35ms making 1 call to DBI::st::execute | ||
1024 | 304 | 1.37ms | while (my ($frameworkcode,$kohafield,$tagfield,$tagsubfield) = $sth->fetchrow) { # spent 1.37ms making 304 calls to DBI::st::fetchrow, avg 4µs/call | ||
1025 | my $retval = {}; | ||||
1026 | $marcfromkohafield->{$frameworkcode}->{$kohafield} = [$tagfield,$tagsubfield]; | ||||
1027 | } | ||||
1028 | return $marcfromkohafield; | ||||
1029 | } | ||||
1030 | |||||
1031 | =head2 stopwords | ||||
1032 | |||||
- - | |||||
1042 | #' | ||||
1043 | sub 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 | ||||
1059 | sub _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 486µs within C4::Context::userenv which was called 41 times, avg 12µs/call:
# 32 times (368µs+0s) by C4::Search::searchResults at line 1872 of /usr/share/koha/lib/C4/Search.pm, avg 11µs/call
# 5 times (31µs+0s) by C4::Auth::get_template_and_user at line 303 of /usr/share/koha/lib/C4/Auth.pm, avg 6µs/call
# 2 times (66µs+0s) by C4::Koha::GetAuthorisedValues at line 1044 of /usr/share/koha/lib/C4/Koha.pm, avg 33µs/call
# once (14µs+0s) by main::RUNTIME at line 715 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µs+0s) by C4::Auth::get_template_and_user at line 381 of /usr/share/koha/lib/C4/Auth.pm | ||||
1085 | 123 | 551µ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 | #' | ||||
1106 | sub 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 | |||||
1127 | sub 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 | |||||
1135 | sub 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 | #' | ||||
1161 | sub _new_userenv | ||||
1162 | # spent 12µs within C4::Context::_new_userenv which was called:
# once (12µs+0s) by C4::Auth::checkauth at line 811 of /usr/share/koha/lib/C4/Auth.pm | ||||
1163 | 3 | 15µ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 | |||||
1178 | sub _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 | ||||
1196 | sub 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 | { | ||||
1203 | 3 | 185µs | 2 | 110µs | # spent 71µs (33+38) within C4::Context::BEGIN@1203 which was called:
# once (33µs+38µs) by main::BEGIN@31 at line 1203 # spent 71µs making 1 call to C4::Context::BEGIN@1203
# spent 38µ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 | |||||
- - | |||||
1222 | sub 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 | |||||
- - | |||||
1232 | 1 | 10µs | 1; | ||
1233 | __END__ |