Skip to content

Commit b0935c1

Browse files
CyberShadowdylanwh
authored andcommitted
Bug 1446236 - Add & use simpler method to check if an extension is present (#35)
1 parent 2d80cea commit b0935c1

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

Bugzilla.pm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ sub template_inner {
233233

234234
sub extensions {
235235
my ($class) = @_;
236+
237+
# Guard against extensions querying the extension list during initialization
238+
# (through this method or has_extension).
239+
# The extension list is not fully populated at that point,
240+
# so the results would not be meaningful.
241+
state $recursive = 0;
242+
die "Recursive attempt to load/query extensions" if $recursive;
243+
$recursive = 1;
244+
236245
my $cache = $class->request_cache;
237246
if (!$cache->{extensions}) {
238247
my $extension_packages = Bugzilla::Extension->load_all();
@@ -245,9 +254,20 @@ sub extensions {
245254
}
246255
$cache->{extensions} = \@extensions;
247256
}
257+
$recursive = 0;
248258
return $cache->{extensions};
249259
}
250260

261+
sub has_extension {
262+
my ($class, $name) = @_;
263+
my $cache = $class->request_cache;
264+
if (!$cache->{extensions_hash}) {
265+
my %extensions = map { $_->NAME => 1 } @{ Bugzilla->extensions };
266+
$cache->{extensions_hash} = \%extensions;
267+
}
268+
return exists $cache->{extensions_hash}{$name};
269+
}
270+
251271
sub cgi {
252272
return $_[0]->request_cache->{cgi} ||= new Bugzilla::CGI();
253273
}

Bugzilla/Search.pm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use Date::Format;
3434
use Date::Parse;
3535
use Scalar::Util qw(blessed);
3636
use List::MoreUtils qw(all firstidx part uniq);
37-
use List::Util qw(any);
3837
use POSIX qw(INT_MAX);
3938
use Storable qw(dclone);
4039
use Time::HiRes qw(gettimeofday tv_interval);
@@ -803,8 +802,7 @@ sub data {
803802
# BMO - to avoid massive amounts of joins, if we're selecting a lot of
804803
# tracking flags, replace them with placeholders. the values will be
805804
# retrieved later and injected into the result.
806-
state $have_tracking_flags = any { $_->NAME eq 'TrackingFlags' } @{ Bugzilla->extensions };
807-
if ($have_tracking_flags) {
805+
if (Bugzilla->has_extension('TrackingFlags')) {
808806
my %tf_map = map { $_ => 1 } Bugzilla::Extension::TrackingFlags::Flag->get_all_names();
809807
my @tf_selected = grep { exists $tf_map{$_} } @orig_fields;
810808
# mysql has a limit of 61 joins, and we want to avoid massive amounts of joins
@@ -867,7 +865,7 @@ sub data {
867865
$self->{data} = [map { $data{$_} } @$bug_ids];
868866

869867
# BMO - get tracking flags values, and insert into result
870-
if ($have_tracking_flags && @{ $self->{tracking_flags} }) {
868+
if (Bugzilla->has_extension('TrackingFlags') && @{ $self->{tracking_flags} }) {
871869
# read values
872870
my $values;
873871
$sql = "

extensions/BugModal/Extension.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ sub template_before_process {
188188
return if exists $bug->{error};
189189

190190
# trigger loading of tracking flags
191-
state $have_tracking_flags = any { $_->NAME eq 'TrackingFlags' } @{ Bugzilla->extensions };
192-
if ($have_tracking_flags) {
191+
if (Bugzilla->has_extension('TrackingFlags')) {
193192
Bugzilla::Extension::TrackingFlags->template_before_process({
194193
file => 'bug/edit.html.tmpl',
195194
vars => $vars,

votes.cgi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use lib qw(. lib local/lib/perl5);
3030
use Bugzilla;
3131
use Bugzilla::Error;
3232

33-
my $is_enabled = grep { $_->NAME eq 'Voting' } @{ Bugzilla->extensions };
34-
$is_enabled || ThrowCodeError('extension_disabled', { name => 'Voting' });
33+
Bugzilla->has_extension('Voting') || ThrowCodeError('extension_disabled', { name => 'Voting' });
3534

3635
my $cgi = Bugzilla->cgi;
3736
my $action = $cgi->param('action') || 'show_user';

0 commit comments

Comments
 (0)