]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1476841 - Various code cleanups ahead of the Mojolicious patch
authorDylan William Hardison <dylan@hardison.net>
Mon, 23 Jul 2018 15:25:43 +0000 (11:25 -0400)
committerGitHub <noreply@github.com>
Mon, 23 Jul 2018 15:25:43 +0000 (11:25 -0400)
Bugzilla.pm
Bugzilla/CPAN.pm
Bugzilla/Constants.pm
Bugzilla/DaemonControl.pm
Bugzilla/Template.pm
editusers.cgi
mod_perl.pl
userprefs.cgi

index 29675865b00475ceca696efb76c3a0e155f10b4d..73d080395e9d74c2c6071831610f4875b7456029 100644 (file)
@@ -13,15 +13,6 @@ use warnings;
 
 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;
@@ -202,8 +193,17 @@ sub init_page {
 # 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};
@@ -214,7 +214,8 @@ sub template_inner {
     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 {
@@ -234,7 +235,7 @@ sub extensions {
 }
 
 sub cgi {
-    return request_cache->{cgi} ||= new Bugzilla::CGI();
+    return request_cache->{cgi} ||= Bugzilla::CGI->new;
 }
 
 sub input_params {
@@ -340,9 +341,6 @@ sub login {
 
     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');
 
index d765d29018b2bce37d72df2f8b595e2633473342..1b6fb93b97229592a2d5323edee70e6c5687c97f 100644 (file)
@@ -103,7 +103,7 @@ sub feature {
     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;
 }
 
index 3aa7b0fa499c5a4f5b254bc1620c28f3bc63de34..185a303900ea2406f854c637eec8aa1756d008c3 100644 (file)
@@ -15,6 +15,7 @@ use base qw(Exporter);
 
 # For bz_locations
 use File::Basename;
+use Cwd qw(realpath);
 use Memoize;
 
 @Bugzilla::Constants::EXPORT = qw(
@@ -644,12 +645,8 @@ sub _bz_locations {
     # 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;
index 2c6df1b87a5d961da1cf4ba42692e4bce31c3365..6ff883af01b3d6550185d2aa250b5c2b8572c951 100644 (file)
@@ -14,7 +14,7 @@ use Bugzilla::Logging;
 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;
@@ -40,12 +40,11 @@ our %EXPORT_TAGS = (
     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)   = @_;
@@ -76,7 +75,7 @@ sub run_cereal {
     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 ),
     );
@@ -103,7 +102,7 @@ sub run_httpd {
             # 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] $!";
         },
@@ -122,7 +121,7 @@ sub run_jobqueue {
     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 ),
     );
index 8cf91052e55e2bc1931a5d3c6fc6b01075ab30e8..299734d64a995a60e0bb1436c808a70a94066155 100644 (file)
@@ -565,13 +565,8 @@ sub create {
         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.
@@ -584,7 +579,7 @@ sub create {
         # 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
@@ -1042,7 +1037,7 @@ sub create {
 
     # 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';
 
index 9fbd550fedde722d0bdc8ed69f99be5a5bf8d352..d2ad3a82f34ab121f2830477c2608adf5120c68a 100755 (executable)
@@ -24,7 +24,7 @@ use Bugzilla::Field;
 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;
index ff84e523e4086ebba2661057efddc70a72f10752..aeadd6f3556e99851f894ac7843a5a282d3b81a4 100644 (file)
@@ -104,7 +104,7 @@ Bugzilla::Extension->load_all();
 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();
index e70b9780a98f2d057d34cbf35eaacbdc2a872e98..830c49eed431e3101cb8a2db3cdcdd625df514e2 100755 (executable)
@@ -29,7 +29,7 @@ use DateTime;
 
 use constant SESSION_MAX => 20;
 
-my $template = Bugzilla->template;
+local our $template = Bugzilla->template;
 local our $vars = {};
 
 ###############################################################################