diff options
Diffstat (limited to 'Bugzilla.pm')
-rw-r--r-- | Bugzilla.pm | 104 |
1 files changed, 59 insertions, 45 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm index 5b39e4c81..5773eee63 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -26,6 +26,8 @@ package Bugzilla; use strict; +# FIXME : Line to be removed + # We want any compile errors to get to the browser, if possible. BEGIN { # This makes sure we're in a CGI. @@ -42,9 +44,10 @@ use Bugzilla::Auth::Persist::Cookie; use Bugzilla::CGI; use Bugzilla::Extension; use Bugzilla::DB; +use Bugzilla::Hook; use Bugzilla::Install::Localconfig qw(read_localconfig); use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES); -use Bugzilla::Install::Util qw(init_console); +use Bugzilla::Install::Util qw(init_console include_languages); use Bugzilla::Template; use Bugzilla::User; use Bugzilla::Error; @@ -193,9 +196,7 @@ sub init_page { ##################################################################### sub template { - my $class = shift; - $class->request_cache->{template} ||= Bugzilla::Template->create(); - return $class->request_cache->{template}; + return $_[0]->request_cache->{template} ||= Bugzilla::Template->create(); } sub template_inner { @@ -203,9 +204,7 @@ sub template_inner { my $cache = $class->request_cache; my $current_lang = $cache->{template_current_lang}->[0]; $lang ||= $current_lang || ''; - $class->request_cache->{"template_inner_$lang"} - ||= Bugzilla::Template->create(language => $lang); - return $class->request_cache->{"template_inner_$lang"}; + return $cache->{"template_inner_$lang"} ||= Bugzilla::Template->create(language => $lang); } our $extension_packages; @@ -264,9 +263,7 @@ sub feature { } sub cgi { - my $class = shift; - $class->request_cache->{cgi} ||= new Bugzilla::CGI(); - return $class->request_cache->{cgi}; + return $_[0]->request_cache->{cgi} ||= new Bugzilla::CGI(); } sub input_params { @@ -286,21 +283,15 @@ sub input_params { } sub localconfig { - my $class = shift; - $class->request_cache->{localconfig} ||= read_localconfig(); - return $class->request_cache->{localconfig}; + return $_[0]->process_cache->{localconfig} ||= read_localconfig(); } sub params { - my $class = shift; - $class->request_cache->{params} ||= Bugzilla::Config::read_param_file(); - return $class->request_cache->{params}; + return $_[0]->request_cache->{params} ||= Bugzilla::Config::read_param_file(); } sub user { - my $class = shift; - $class->request_cache->{user} ||= new Bugzilla::User; - return $class->request_cache->{user}; + return $_[0]->request_cache->{user} ||= new Bugzilla::User; } sub set_user { @@ -309,8 +300,7 @@ sub set_user { } sub sudoer { - my $class = shift; - return $class->request_cache->{sudoer}; + return $_[0]->request_cache->{sudoer}; } sub sudo_request { @@ -426,31 +416,27 @@ sub logout_request { } sub job_queue { - my $class = shift; require Bugzilla::JobQueue; - $class->request_cache->{job_queue} ||= Bugzilla::JobQueue->new(); - return $class->request_cache->{job_queue}; + return $_[0]->request_cache->{job_queue} ||= Bugzilla::JobQueue->new(); } sub dbh { - my $class = shift; # If we're not connected, then we must want the main db - $class->request_cache->{dbh} ||= $class->dbh_main; - - return $class->request_cache->{dbh}; + return $_[0]->request_cache->{dbh} ||= $_[0]->dbh_main; } sub dbh_main { - my $class = shift; - $class->request_cache->{dbh_main} ||= Bugzilla::DB::connect_main(); - return $class->request_cache->{dbh_main}; + return $_[0]->request_cache->{dbh_main} ||= Bugzilla::DB::connect_main(); } sub languages { - my $class = shift; return Bugzilla::Install::Util::supported_languages(); } +sub current_language { + return $_[0]->request_cache->{current_language} ||= (include_languages())[0]; +} + sub error_mode { my ($class, $newval) = @_; if (defined $newval) { @@ -597,12 +583,20 @@ sub fields { } sub active_custom_fields { - my $class = shift; - if (!exists $class->request_cache->{active_custom_fields}) { - $class->request_cache->{active_custom_fields} = - Bugzilla::Field->match({ custom => 1, obsolete => 0 }); + my ($class, $params) = @_; + my $cache_id = 'active_custom_fields'; + if ($params) { + $cache_id .= ($params->{product} ? '_p' . $params->{product}->id : '') . + ($params->{component} ? '_c' . $params->{component}->id : '') . + ($params->{type} ? '_t' . $params->{type} : ''); + } + if (!exists $class->request_cache->{$cache_id}) { + my $fields = Bugzilla::Field->match({ custom => 1, obsolete => 0}); + Bugzilla::Hook::process('active_custom_fields', + { fields => \$fields, params => $params }); + $class->request_cache->{$cache_id} = $fields; } - return @{$class->request_cache->{active_custom_fields}}; + return @{$class->request_cache->{$cache_id}}; } sub has_flags { @@ -615,13 +609,8 @@ sub has_flags { } sub local_timezone { - my $class = shift; - - if (!defined $class->request_cache->{local_timezone}) { - $class->request_cache->{local_timezone} = - DateTime::TimeZone->new(name => 'local'); - } - return $class->request_cache->{local_timezone}; + return $_[0]->process_cache->{local_timezone} + ||= DateTime::TimeZone->new(name => 'local'); } # This creates the request cache for non-mod_perl installations. @@ -642,6 +631,27 @@ sub request_cache { return $_request_cache; } +sub clear_request_cache { + $_request_cache = {}; + if ($ENV{MOD_PERL}) { + require Apache2::RequestUtil; + my $request = eval { Apache2::RequestUtil->request }; + if ($request) { + my $pnotes = $request->pnotes; + delete @$pnotes{(keys %$pnotes)}; + } + } +} + +# This is a per-process cache. Under mod_cgi it's identical to the +# request_cache. When using mod_perl, items in this cache live until the +# worker process is terminated. +our $_process_cache = {}; + +sub process_cache { + return $_process_cache; +} + # Private methods # Per-process cleanup. Note that this is a plain subroutine, not a method, @@ -654,7 +664,7 @@ sub _cleanup { $dbh->bz_rollback_transaction() if $dbh->bz_in_transaction; $dbh->disconnect; } - undef $_request_cache; + clear_request_cache(); # These are both set by CGI.pm but need to be undone so that # Apache can actually shut down its children if it needs to. @@ -915,6 +925,10 @@ The main database handle. See L<DBI>. Currently installed languages. Returns a reference to a list of RFC 1766 language tags of installed languages. +=item C<current_language> + +The currently active language. + =item C<switch_to_shadow_db> Switch from using the main database to using the shadow database. |