From 5fc80f94271780b6ff6d1dbba554df35e803ac51 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Tue, 24 Nov 2009 06:09:41 +0000 Subject: Bug 430014: Re-write the code hooks system so that it uses modules instead of individual .pl files Patch by Max Kanat-Alexander (module owner) a=mkanat --- Bugzilla.pm | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'Bugzilla.pm') diff --git a/Bugzilla.pm b/Bugzilla.pm index b85186e6e..9f4e81cb6 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -40,9 +40,11 @@ use Bugzilla::Constants; use Bugzilla::Auth; use Bugzilla::Auth::Persist::Cookie; use Bugzilla::CGI; +use Bugzilla::Extension; use Bugzilla::DB; use Bugzilla::Install::Localconfig qw(read_localconfig); use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES); +use Bugzilla::Install::Util; use Bugzilla::Template; use Bugzilla::User; use Bugzilla::Error; @@ -55,9 +57,6 @@ use File::Spec::Functions; use DateTime::TimeZone; use Safe; -# This creates the request cache for non-mod_perl installations. -our $_request_cache = {}; - ##################################################################### # Constants ##################################################################### @@ -171,8 +170,6 @@ sub init_page { } } -init_page() if !$ENV{MOD_PERL}; - ##################################################################### # Subroutines and Methods ##################################################################### @@ -193,6 +190,27 @@ sub template_inner { return $class->request_cache->{"template_inner_$lang"}; } +our $extension_packages; +sub extensions { + my ($class) = @_; + my $cache = $class->request_cache; + if (!$cache->{extensions}) { + # Under mod_perl, mod_perl.pl populates $extension_packages for us. + if (!$extension_packages) { + $extension_packages = Bugzilla::Extension->load_all(); + } + my @extensions; + foreach my $package (@$extension_packages) { + my $extension = $package->new(); + if ($extension->enabled) { + push(@extensions, $extension); + } + } + $cache->{extensions} = \@extensions; + } + return $cache->{extensions}; +} + sub feature { my ($class, $feature) = @_; my $cache = $class->request_cache; @@ -538,12 +556,6 @@ sub has_flags { return $class->request_cache->{has_flags}; } -sub hook_args { - my ($class, $args) = @_; - $class->request_cache->{hook_args} = $args if $args; - return $class->request_cache->{hook_args}; -} - sub local_timezone { my $class = shift; @@ -554,6 +566,12 @@ sub local_timezone { return $class->request_cache->{local_timezone}; } +# This creates the request cache for non-mod_perl installations. +# This is identical to Install::Util::_cache so that things loaded +# into Install::Util::_cache during installation can be read out +# of request_cache later in installation. +our $_request_cache = $Bugzilla::Install::Util::_cache; + sub request_cache { if ($ENV{MOD_PERL}) { require Apache2::RequestUtil; @@ -586,6 +604,8 @@ sub END { _cleanup() unless $ENV{MOD_PERL}; } +init_page() if !$ENV{MOD_PERL}; + 1; __END__ @@ -821,11 +841,6 @@ The current Parameters of Bugzilla, as a hashref. If C does not exist, then we return an empty hashref. If C is unreadable or is not valid perl, we C. -=item C - -If you are running inside a code hook (see L) this -is how you get the arguments passed to the hook. - =item C Returns the local timezone of the Bugzilla installation, -- cgit v1.2.3-24-g4f1b