summaryrefslogtreecommitdiffstats
path: root/Bugzilla.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla.pm')
-rw-r--r--Bugzilla.pm114
1 files changed, 68 insertions, 46 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm
index 5b39e4c81..a998de902 100644
--- a/Bugzilla.pm
+++ b/Bugzilla.pm
@@ -42,9 +42,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;
@@ -84,7 +85,7 @@ use constant SHUTDOWNHTML_RETRY_AFTER => 3600;
# Global Code
#####################################################################
-# $::SIG{__DIE__} = i_am_cgi() ? \&CGI::Carp::confess : \&Carp::confess;
+#$::SIG{__DIE__} = i_am_cgi() ? \&CGI::Carp::confess : \&Carp::confess;
# Note that this is a raw subroutine, not a method, so $class isn't available.
sub init_page {
@@ -193,9 +194,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 +202,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 +261,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 +281,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 +298,7 @@ sub set_user {
}
sub sudoer {
- my $class = shift;
- return $class->request_cache->{sudoer};
+ return $_[0]->request_cache->{sudoer};
}
sub sudo_request {
@@ -388,6 +376,12 @@ sub login {
$class->set_user($authenticated_user);
}
+ if (Bugzilla->sudoer) {
+ Bugzilla->sudoer->update_last_seen_date();
+ } else {
+ $class->user->update_last_seen_date();
+ }
+
return $class->user;
}
@@ -426,31 +420,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) {
@@ -490,6 +480,9 @@ sub usage_mode {
elsif ($newval == USAGE_MODE_TEST) {
$class->error_mode(ERROR_MODE_TEST);
}
+ elsif ($newval == USAGE_MODE_REST) {
+ $class->error_mode(ERROR_MODE_REST);
+ }
else {
ThrowCodeError('usage_mode_invalid',
{'invalid_usage_mode', $newval});
@@ -597,12 +590,21 @@ 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} : '');
}
- return @{$class->request_cache->{active_custom_fields}};
+ if (!exists $class->request_cache->{$cache_id}) {
+ my $fields = Bugzilla::Field->match({ custom => 1, obsolete => 0});
+ @$fields = grep($_->type ne FIELD_TYPE_EXTENSION, @$fields);
+ Bugzilla::Hook::process('active_custom_fields',
+ { fields => \$fields, params => $params });
+ $class->request_cache->{$cache_id} = $fields;
+ }
+ return @{$class->request_cache->{$cache_id}};
}
sub has_flags {
@@ -615,13 +617,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 +639,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 +672,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 +933,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.