From b0935c1e52eea1dfc70652bf6fcb7c8b856a8826 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sun, 8 Apr 2018 06:57:06 +0300 Subject: Bug 1446236 - Add & use simpler method to check if an extension is present (#35) --- Bugzilla.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Bugzilla.pm') 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(); } -- cgit v1.2.3-24-g4f1b