Skip to content

Commit 78a61d2

Browse files
committed
Bug 1446236 - Add simpler method to check if an extension is present
1 parent 40fee14 commit 78a61d2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Bugzilla.pm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,19 @@ sub template_inner {
123123
||= Bugzilla::Template->create(%options);
124124
}
125125

126+
our $in_extensions = 0;
127+
126128
sub extensions {
127129
state $extensions;
128130
return $extensions if $extensions;
131+
132+
# Guard against extensions querying the extension list during initialization
133+
# (through this method or has_extension).
134+
# The extension list is not fully populated at that point,
135+
# so the results would not be meaningful.
136+
die "Recursive attempt to load/query extensions" if $in_extensions > 0;
137+
local $in_extensions = $in_extensions + 1;
138+
129139
my $extension_packages = Bugzilla::Extension->load_all();
130140
$extensions = [];
131141
foreach my $package (@$extension_packages) {
@@ -136,6 +146,16 @@ sub extensions {
136146
return $extensions;
137147
}
138148

149+
sub has_extension {
150+
my ($class, $name) = @_;
151+
my $cache = $class->request_cache;
152+
if (!$cache->{extensions_hash}) {
153+
my %extensions = map { $_->NAME => 1 } @{Bugzilla->extensions};
154+
$cache->{extensions_hash} = \%extensions;
155+
}
156+
return exists $cache->{extensions_hash}{$name};
157+
}
158+
139159
sub cgi {
140160
return request_cache->{cgi} ||= Bugzilla::CGI->new;
141161
}

0 commit comments

Comments
 (0)