summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Panteleev <github.private@thecybershadow.net>2018-04-08 05:57:06 +0200
committerDylan William Hardison <dylan@hardison.net>2018-04-08 05:57:06 +0200
commitb0935c1e52eea1dfc70652bf6fcb7c8b856a8826 (patch)
tree2400c507178262779288c10ccdfc773d858da098
parent2d80cea9010f694524f5d165a19697c47535d779 (diff)
downloadbugzilla-b0935c1e52eea1dfc70652bf6fcb7c8b856a8826.tar.gz
bugzilla-b0935c1e52eea1dfc70652bf6fcb7c8b856a8826.tar.xz
Bug 1446236 - Add & use simpler method to check if an extension is present (#35)
-rw-r--r--Bugzilla.pm20
-rw-r--r--Bugzilla/Search.pm6
-rw-r--r--extensions/BugModal/Extension.pm3
-rwxr-xr-xvotes.cgi3
4 files changed, 24 insertions, 8 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm
index e43110389..f5e64c371 100644
--- a/Bugzilla.pm
+++ b/Bugzilla.pm
@@ -233,6 +233,15 @@ sub template_inner {
sub extensions {
my ($class) = @_;
+
+ # Guard against extensions querying the extension list during initialization
+ # (through this method or has_extension).
+ # The extension list is not fully populated at that point,
+ # so the results would not be meaningful.
+ state $recursive = 0;
+ die "Recursive attempt to load/query extensions" if $recursive;
+ $recursive = 1;
+
my $cache = $class->request_cache;
if (!$cache->{extensions}) {
my $extension_packages = Bugzilla::Extension->load_all();
@@ -245,9 +254,20 @@ sub extensions {
}
$cache->{extensions} = \@extensions;
}
+ $recursive = 0;
return $cache->{extensions};
}
+sub has_extension {
+ my ($class, $name) = @_;
+ my $cache = $class->request_cache;
+ if (!$cache->{extensions_hash}) {
+ my %extensions = map { $_->NAME => 1 } @{ Bugzilla->extensions };
+ $cache->{extensions_hash} = \%extensions;
+ }
+ return exists $cache->{extensions_hash}{$name};
+}
+
sub cgi {
return $_[0]->request_cache->{cgi} ||= new Bugzilla::CGI();
}
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm
index 643d591ca..e15c60f7f 100644
--- a/Bugzilla/Search.pm
+++ b/Bugzilla/Search.pm
@@ -34,7 +34,6 @@ use Date::Format;
use Date::Parse;
use Scalar::Util qw(blessed);
use List::MoreUtils qw(all firstidx part uniq);
-use List::Util qw(any);
use POSIX qw(INT_MAX);
use Storable qw(dclone);
use Time::HiRes qw(gettimeofday tv_interval);
@@ -803,8 +802,7 @@ sub data {
# BMO - to avoid massive amounts of joins, if we're selecting a lot of
# tracking flags, replace them with placeholders. the values will be
# retrieved later and injected into the result.
- state $have_tracking_flags = any { $_->NAME eq 'TrackingFlags' } @{ Bugzilla->extensions };
- if ($have_tracking_flags) {
+ if (Bugzilla->has_extension('TrackingFlags')) {
my %tf_map = map { $_ => 1 } Bugzilla::Extension::TrackingFlags::Flag->get_all_names();
my @tf_selected = grep { exists $tf_map{$_} } @orig_fields;
# mysql has a limit of 61 joins, and we want to avoid massive amounts of joins
@@ -867,7 +865,7 @@ sub data {
$self->{data} = [map { $data{$_} } @$bug_ids];
# BMO - get tracking flags values, and insert into result
- if ($have_tracking_flags && @{ $self->{tracking_flags} }) {
+ if (Bugzilla->has_extension('TrackingFlags') && @{ $self->{tracking_flags} }) {
# read values
my $values;
$sql = "
diff --git a/extensions/BugModal/Extension.pm b/extensions/BugModal/Extension.pm
index 46ec20510..ef9c93a37 100644
--- a/extensions/BugModal/Extension.pm
+++ b/extensions/BugModal/Extension.pm
@@ -188,8 +188,7 @@ sub template_before_process {
return if exists $bug->{error};
# trigger loading of tracking flags
- state $have_tracking_flags = any { $_->NAME eq 'TrackingFlags' } @{ Bugzilla->extensions };
- if ($have_tracking_flags) {
+ if (Bugzilla->has_extension('TrackingFlags')) {
Bugzilla::Extension::TrackingFlags->template_before_process({
file => 'bug/edit.html.tmpl',
vars => $vars,
diff --git a/votes.cgi b/votes.cgi
index d9dba1541..7c1fff67a 100755
--- a/votes.cgi
+++ b/votes.cgi
@@ -30,8 +30,7 @@ use lib qw(. lib local/lib/perl5);
use Bugzilla;
use Bugzilla::Error;
-my $is_enabled = grep { $_->NAME eq 'Voting' } @{ Bugzilla->extensions };
-$is_enabled || ThrowCodeError('extension_disabled', { name => 'Voting' });
+Bugzilla->has_extension('Voting') || ThrowCodeError('extension_disabled', { name => 'Voting' });
my $cgi = Bugzilla->cgi;
my $action = $cgi->param('action') || 'show_user';