File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -122,9 +122,19 @@ sub template_inner {
122122 ||= Bugzilla::Template-> create(%options );
123123}
124124
125+ our $in_extensions = 0;
126+
125127sub extensions {
126128 state $extensions ;
127129 return $extensions if $extensions ;
130+
131+ # Guard against extensions querying the extension list during initialization
132+ # (through this method or has_extension).
133+ # The extension list is not fully populated at that point,
134+ # so the results would not be meaningful.
135+ die " Recursive attempt to load/query extensions" if $in_extensions > 0;
136+ local $in_extensions = $in_extensions + 1;
137+
128138 my $extension_packages = Bugzilla::Extension-> load_all();
129139 $extensions = [];
130140 foreach my $package (@$extension_packages ) {
@@ -135,6 +145,16 @@ sub extensions {
135145 return $extensions ;
136146}
137147
148+ sub has_extension {
149+ my ($class , $name ) = @_ ;
150+ my $cache = $class -> request_cache;
151+ if (!$cache -> {extensions_hash }) {
152+ my %extensions = map { $_ -> NAME => 1 } @{Bugzilla-> extensions};
153+ $cache -> {extensions_hash } = \%extensions ;
154+ }
155+ return exists $cache -> {extensions_hash }{$name };
156+ }
157+
138158sub cgi {
139159 return request_cache-> {cgi } ||= Bugzilla::CGI-> new;
140160}
Original file line number Diff line number Diff line change @@ -30,8 +30,8 @@ use lib qw(. lib local/lib/perl5);
3030use Bugzilla;
3131use 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' )
34+ || ThrowCodeError(' extension_disabled' , {name => ' Voting' });
3535
3636my $cgi = Bugzilla-> cgi;
3737my $action = $cgi -> param(' action' ) || ' show_user' ;
You can’t perform that action at this time.
0 commit comments