use Bugzilla::Logging;
-# We want any compile errors to get to the browser, if possible.
-BEGIN {
- # This makes sure we're in a CGI.
- if ($ENV{SERVER_SOFTWARE} && !$ENV{MOD_PERL}) {
- require CGI::Carp;
- CGI::Carp->import('fatalsToBrowser');
- }
-}
-
our $VERSION = '20180717.2';
use Bugzilla::Auth;
# Subroutines and Methods
#####################################################################
+my $preload_templates = 0;
+sub preload_templates {
+ $preload_templates = 1;
+
+ delete request_cache->{template};
+ template();
+ return 1;
+}
+
sub template {
- request_cache->{template} ||= Bugzilla::Template->create();
+ request_cache->{template} //= Bugzilla::Template->create(preload => $preload_templates);
request_cache->{template}->{_is_main} = 1;
return request_cache->{template};
my $cache = request_cache;
my $current_lang = $cache->{template_current_lang}->[0];
$lang ||= $current_lang || '';
- return $cache->{"template_inner_$lang"} ||= Bugzilla::Template->create(language => $lang);
+ my %options = (language => $lang, preload => $preload_templates);
+ return $cache->{"template_inner_$lang"} ||= Bugzilla::Template->create(%options);
}
sub extensions {
}
sub cgi {
- return request_cache->{cgi} ||= new Bugzilla::CGI();
+ return request_cache->{cgi} ||= Bugzilla::CGI->new;
}
sub input_params {
return $class->user if $class->user->id;
- # Load all extensions here if not running under mod_perl
- $class->extensions unless $ENV{MOD_PERL};
-
my $authorizer = new Bugzilla::Auth();
$type = LOGIN_REQUIRED if $class->cgi->param('GoAheadAndLogIn');
my $meta = $class->cpan_meta;
my $feature = $meta->feature($feature_name);
my @modules = $feature->prereqs->merged_requirements(['runtime'], ['requires'])->required_modules;
- Module::Runtime::require_module($_) foreach @modules;
+ Module::Runtime::require_module($_) foreach grep { !/^Test::Taint$/ } @modules;
return $FEATURE_LOADED{$feature_name} = 1;
}
# For bz_locations
use File::Basename;
+use Cwd qw(realpath);
use Memoize;
@Bugzilla::Constants::EXPORT = qw(
# directory under both mod_cgi and mod_perl. We call dirname twice
# to get the name of the directory above the "Bugzilla/" directory.
#
- # Calling dirname twice like that won't work on VMS or AmigaOS
- # but I doubt anybody runs Bugzilla on those.
- #
- # On mod_cgi this will be a relative path. On mod_perl it will be an
- # absolute path.
- my $libpath = dirname(dirname($INC{'Bugzilla/Constants.pm'}));
+ # Always use an absolute path, based on the location of this file.
+ my $libpath = realpath(dirname(dirname(__FILE__)));
# We have to detaint $libpath, but we can't use Bugzilla::Util here.
$libpath =~ /(.*)/;
$libpath = $1;
use Bugzilla::Constants qw(bz_locations);
use Cwd qw(realpath);
use English qw(-no_match_vars $PROGRAM_NAME);
-use File::Spec::Functions qw(catfile);
+use File::Spec::Functions qw(catfile catdir);
use Future::Utils qw(repeat try_repeat);
use Future;
use IO::Async::Loop;
utils => [qw(catch_signal on_exception on_finish)],
);
-use constant {
- JOBQUEUE_BIN => realpath( catfile( bz_locations->{cgi_path}, 'jobqueue.pl' ) ),
- CEREAL_BIN => realpath( catfile( bz_locations->{cgi_path}, 'scripts', 'cereal.pl' ) ),
- HTTPD_BIN => '/usr/sbin/httpd',
- HTTPD_CONFIG => realpath( catfile( bz_locations->{confdir}, 'httpd.conf' ) ),
-};
+my $BUGZILLA_DIR = bz_locations->{cgi_path};
+my $JOBQUEUE_BIN = catfile( $BUGZILLA_DIR, 'jobqueue.pl' );
+my $CEREAL_BIN = catfile( $BUGZILLA_DIR, 'scripts', 'cereal.pl' );
+my $HTTPD_BIN = '/usr/sbin/httpd';
+my $HTTPD_CONFIG = catfile( bz_locations->{confdir}, 'httpd.conf' );
sub catch_signal {
my ($name, @done) = @_;
my $loop = IO::Async::Loop->new;
my $exit_f = $loop->new_future;
my $cereal = IO::Async::Process->new(
- command => [CEREAL_BIN],
+ command => [$CEREAL_BIN],
on_finish => on_finish($exit_f),
on_exception => on_exception( 'cereal', $exit_f ),
);
# we have to setsid() to make a new process group
# or else apache will kill its parent.
setsid();
- my @command = ( HTTPD_BIN, '-DFOREGROUND', '-f' => HTTPD_CONFIG, @args );
+ my @command = ( $HTTPD_BIN, '-DFOREGROUND', '-f' => $HTTPD_CONFIG, @args );
exec @command
or die "failed to exec $command[0] $!";
},
my $loop = IO::Async::Loop->new;
my $exit_f = $loop->new_future;
my $jobqueue = IO::Async::Process->new(
- command => [ JOBQUEUE_BIN, 'start', '-f', '-d', @args ],
+ command => [ $JOBQUEUE_BIN, 'start', '-f', '-d', @args ],
on_finish => on_finish($exit_f),
on_exception => on_exception( 'httpd', $exit_f ),
);
PRE_CHOMP => 1,
TRIM => 1,
- # Bugzilla::Template::Plugin::Hook uses the absolute (in mod_perl)
- # or relative (in mod_cgi) paths of hook files to explicitly compile
- # a specific file. Also, these paths may be absolute at any time
- # if a packager has modified bz_locations() to contain absolute
- # paths.
ABSOLUTE => 1,
- RELATIVE => $ENV{MOD_PERL} ? 0 : 1,
+ RELATIVE => 0,
# Only use an on-disk template cache if we're running as the web
# server. This ensures the permissions of the cache remain correct.
# Initialize templates (f.e. by loading plugins like Hook).
PRE_PROCESS => ["global/initialize.none.tmpl"],
- ENCODING => Bugzilla->params->{'utf8'} ? 'UTF-8' : undef,
+ ENCODING => 'UTF-8',
# Functions for processing text within templates in various ways.
# IMPORTANT! When adding a filter here that does not override a
# under mod_perl, use a provider (template loader) that preloads all templates into memory
my $provider_class
- = $ENV{MOD_PERL}
+ = $opts{preload}
? 'Bugzilla::Template::PreloadProvider'
: 'Template::Provider';
use Bugzilla::Group;
use Bugzilla::Token;
-my $user = Bugzilla->login(LOGIN_REQUIRED);
+local our $user = Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template;
Bugzilla->preload_features();
# Force instantiation of template so Bugzilla::Template::PreloadProvider can do its magic.
-Bugzilla->template;
+Bugzilla->preload_templates;
# Have ModPerl::RegistryLoader pre-compile all CGI scripts.
my $rl = new ModPerl::RegistryLoader();
use constant SESSION_MAX => 20;
-my $template = Bugzilla->template;
+local our $template = Bugzilla->template;
local our $vars = {};
###############################################################################