From a2dd3b00284fd4724d3408274cb1156c7a77d187 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sat, 24 Oct 2009 05:21:06 +0000 Subject: Bug 520948: Use Bugzilla->feature and feature_enabled everywhere instead of checking if modules are installed Patch by Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Config/Common.pm | 29 ++++++++++++++++++----------- Bugzilla/Install/Requirements.pm | 4 ++-- Bugzilla/JobQueue.pm | 4 ++-- Bugzilla/Template.pm | 2 ++ Bugzilla/Update.pm | 9 +-------- Bugzilla/Util.pm | 9 ++------- 6 files changed, 27 insertions(+), 30 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Config/Common.pm b/Bugzilla/Config/Common.pm index b722795d4..95866b032 100644 --- a/Bugzilla/Config/Common.pm +++ b/Bugzilla/Config/Common.pm @@ -257,22 +257,29 @@ sub check_user_verify_class { # the login method as LDAP, we won't notice, but all logins will fail. # So don't do that. + my $params = Bugzilla->params; my ($list, $entry) = @_; $list || return 'You need to specify at least one authentication mechanism'; for my $class (split /,\s*/, $list) { my $res = check_multi($class, $entry); return $res if $res; if ($class eq 'RADIUS') { - eval "require Authen::Radius"; - return "Error requiring Authen::Radius: '$@'" if $@; - return "RADIUS servername (RADIUS_server) is missing" unless Bugzilla->params->{"RADIUS_server"}; - return "RADIUS_secret is empty" unless Bugzilla->params->{"RADIUS_secret"}; + if (!Bugzilla->feature('auth_radius')) { + return "RADIUS support is not available. Run checksetup.pl" + . " for more details"; + } + return "RADIUS servername (RADIUS_server) is missing" + if !$params->{"RADIUS_server"}; + return "RADIUS_secret is empty" if !$params->{"RADIUS_secret"}; } elsif ($class eq 'LDAP') { - eval "require Net::LDAP"; - return "Error requiring Net::LDAP: '$@'" if $@; - return "LDAP servername (LDAPserver) is missing" unless Bugzilla->params->{"LDAPserver"}; - return "LDAPBaseDN is empty" unless Bugzilla->params->{"LDAPBaseDN"}; + if (!Bugzilla->feature('auth_ldap')) { + return "LDAP support is not available. Run checksetup.pl" + . " for more details"; + } + return "LDAP servername (LDAPserver) is missing" + if !$params->{"LDAPserver"}; + return "LDAPBaseDN is empty" if !$params->{"LDAPBaseDN"}; } } return ""; @@ -323,9 +330,9 @@ sub check_notification { sub check_smtp_auth { my $username = shift; - if ($username) { - eval "require Authen::SASL"; - return "Error requiring Authen::SASL: '$@'" if $@; + if ($username and !Bugzilla->feature('smtp_auth')) { + return "SMTP Authentication is not available. Run checksetup.pl for" + . " more details"; } return ""; } diff --git a/Bugzilla/Install/Requirements.pm b/Bugzilla/Install/Requirements.pm index 70974a373..86b4813d1 100644 --- a/Bugzilla/Install/Requirements.pm +++ b/Bugzilla/Install/Requirements.pm @@ -151,7 +151,7 @@ sub OPTIONAL_MODULES { }, { package => 'Chart', - module => 'Chart::Base', + module => 'Chart::Lines', version => '1.0', feature => [qw(new_charts old_charts)], }, @@ -179,7 +179,7 @@ sub OPTIONAL_MODULES { package => 'XML-Twig', module => 'XML::Twig', version => 0, - feature => ['moving'], + feature => ['moving', 'updates'], }, { package => 'MIME-tools', diff --git a/Bugzilla/JobQueue.pm b/Bugzilla/JobQueue.pm index 102f58bc6..d10df9804 100644 --- a/Bugzilla/JobQueue.pm +++ b/Bugzilla/JobQueue.pm @@ -38,8 +38,8 @@ use constant JOB_MAP => { sub new { my $class = shift; - if (!eval { require TheSchwartz; }) { - ThrowCodeError('jobqueue_not_configured'); + if (!Bugzilla->feature('jobqueue')) { + ThrowCodeError('feature_disabled', { feature => 'jobqueue' }); } my $lc = Bugzilla->localconfig; diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 2e2ac4b08..d5e371f64 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -777,6 +777,8 @@ sub create { 'feature_enabled' => sub { return Bugzilla->feature(@_); }, + 'install_string' => \&Bugzilla::Install::Util::install_string, + # These don't work as normal constants. DB_MODULE => \&Bugzilla::Constants::DB_MODULE, REQUIRED_MODULES => diff --git a/Bugzilla/Update.pm b/Bugzilla/Update.pm index d3f780570..292ab626e 100644 --- a/Bugzilla/Update.pm +++ b/Bugzilla/Update.pm @@ -27,13 +27,9 @@ use constant TIMEOUT => 5; # Number of seconds before timeout. # Look for new releases and notify logged in administrators about them. sub get_notifications { + return if !Bugzilla->feature('updates'); return if (Bugzilla->params->{'upgrade_notification'} eq 'disabled'); - # If the XML::Twig module is missing, we won't be able to parse - # the XML file. So there is no need to go further. - eval("require XML::Twig"); - return if $@; - my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE; # Update the local XML file if this one doesn't exist or if # the last modification time (stat[9]) is older than TIME_INTERVAL. @@ -128,9 +124,6 @@ sub get_notifications { } sub _synchronize_data { - eval("require LWP::UserAgent"); - return {'error' => 'missing_package', 'package' => 'LWP::UserAgent'} if $@; - my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE; my $ua = LWP::UserAgent->new(); diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index a36b22c37..513e02857 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -124,12 +124,7 @@ sub html_light_quote { dfn samp kbd big small sub sup tt dd dt dl ul li ol fieldset legend); - # Are HTML::Scrubber and HTML::Parser installed? - eval { require HTML::Scrubber; - require HTML::Parser; - }; - - if ($@) { # Package(s) not installed. + if (!Bugzilla->feature('html_desc')) { my $safe = join('|', @allow); my $chr = chr(1); @@ -144,7 +139,7 @@ sub html_light_quote { $text =~ s#$chr($safe)$chr#<$1>#go; return $text; } - else { # Packages installed. + else { # We can be less restrictive. We can accept elements with attributes. push(@allow, qw(a blockquote q span)); -- cgit v1.2.3-24-g4f1b