From a0196b5d1ed38b7bf7f0783c1c865d6642f2e2b2 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Thu, 29 Jun 2006 23:49:55 +0000 Subject: Bug 342121: Remove usage of Config qw(:locations) in favor of Constants::bz_locations() Patch By Max Kanat-Alexander r=LpSolit, a=justdave --- Bugzilla/Attachment.pm | 6 +++-- Bugzilla/BugMail.pm | 4 ++-- Bugzilla/Config.pm | 48 ++++++---------------------------------- Bugzilla/Hook.pm | 3 ++- Bugzilla/Mailer.pm | 5 +++-- Bugzilla/Template.pm | 9 +++++--- Bugzilla/Template/Plugin/Hook.pm | 3 ++- Bugzilla/Update.pm | 8 +++---- 8 files changed, 30 insertions(+), 56 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm index a7961d764..78d326049 100644 --- a/Bugzilla/Attachment.pm +++ b/Bugzilla/Attachment.pm @@ -47,9 +47,10 @@ that users upload to the Bugzilla server. =cut +use Bugzilla::Constants; use Bugzilla::Error; use Bugzilla::Flag; -use Bugzilla::Config qw(:locations Param); +use Bugzilla::Config; use Bugzilla::User; use Bugzilla::Util qw(trick_taint); @@ -384,7 +385,7 @@ sub _get_local_filename { my $self = shift; my $hash = ($self->id % 100) + 100; $hash =~ s/.*(\d\d)$/group.$1/; - return "$attachdir/$hash/attachment." . $self->id; + return bz_locations()->{'attachdir'} . "/$hash/attachment." . $self->id; } sub _validate_filename { @@ -700,6 +701,7 @@ sub insert_attachment_for_bug { # If the file is to be stored locally, stream the file from the webserver # to the local file without reading it into a local variable. if ($cgi->param('bigfile')) { + my $attachdir = bz_locations()->{'attachdir'}; my $fh = $cgi->upload('data'); my $hash = ($attachid % 100) + 100; $hash =~ s/.*(\d\d)$/group.$1/; diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm index ef432c1e6..7c8aee1ba 100644 --- a/Bugzilla/BugMail.pm +++ b/Bugzilla/BugMail.pm @@ -35,7 +35,7 @@ package Bugzilla::BugMail; use Bugzilla::Error; use Bugzilla::User; use Bugzilla::Constants; -use Bugzilla::Config qw(:DEFAULT $datadir); +use Bugzilla::Config; use Bugzilla::Util; use Bugzilla::Bug; use Bugzilla::Product; @@ -62,7 +62,7 @@ my %rel_names = (REL_ASSIGNEE , "AssignedTo", my %nomail; # This is run when we load the package -if (open(NOMAIL, '<', "$datadir/nomail")) { +if (open(NOMAIL, '<', bz_locations->{'datadir'} . "/nomail")) { while () { $nomail{trim($_)} = 1; } diff --git a/Bugzilla/Config.pm b/Bugzilla/Config.pm index cb20fad24..a1c4b1f25 100644 --- a/Bugzilla/Config.pm +++ b/Bugzilla/Config.pm @@ -33,43 +33,7 @@ package Bugzilla::Config; use strict; use base qw(Exporter); - -# Under mod_perl, get this from a .htaccess config variable, -# and/or default from the current 'real' dir -# At some stage after this, it may be possible for these dir locations -# to go into localconfig. localconfig can't be specified in a config file, -# except possibly with mod_perl. If you move localconfig, you need to change -# the define here. -# $libpath is really only for mod_perl; its not yet possible to move the -# .pms elsewhere. -# $webdotdir must be in the webtree somewhere. Even if you use a local dot, -# we output images to there. Also, if $webdot dir is not relative to the -# bugzilla root directory, you'll need to change showdependencygraph.cgi to -# set image_url to the correct location. -# The script should really generate these graphs directly... -# Note that if $libpath is changed, some stuff will break, notably dependency -# graphs (since the path will be wrong in the HTML). This will be fixed at -# some point. - -# constant paths -our $libpath = '.'; -our $templatedir = "$libpath/template"; - -# variable paths -our $project; -our $localconfig; -our $datadir; -if ($ENV{'PROJECT'} && $ENV{'PROJECT'} =~ /^(\w+)$/) { - $project = $1; - $localconfig = "$libpath/localconfig.$project"; - $datadir = "$libpath/data/$project"; -} else { - $localconfig = "$libpath/localconfig"; - $datadir = "$libpath/data"; -} -our $attachdir = "$datadir/attachments"; -our $webdotdir = "$datadir/webdot"; -our $extensionsdir = "$libpath/extensions"; +use Bugzilla::Constants; our @parampanels = (); @@ -84,11 +48,9 @@ our @parampanels = (); admin => [qw(UpdateParams SetParam WriteParams)], db => [qw($db_driver $db_host $db_port $db_name $db_user $db_pass $db_sock)], localconfig => [qw($cvsbin $interdiffbin $diffpath $webservergroup)], - locations => [qw($libpath $localconfig $attachdir $datadir $templatedir - $webdotdir $project $extensionsdir)], params => [qw(@parampanels)], ); -Exporter::export_ok_tags('admin', 'db', 'localconfig', 'locations', 'params'); +Exporter::export_ok_tags('admin', 'db', 'localconfig', 'params'); # Bugzilla version $Bugzilla::Config::VERSION = "2.23.1+"; @@ -106,10 +68,13 @@ use vars qw(@param_list); } # INITIALISATION CODE +# Perl throws a warning if we use bz_locations() directly after do. +my $localconfig = bz_locations()->{'localconfig'}; do $localconfig; my %params; # Load in the param definitions sub _load_params { + my $libpath = bz_locations()->{'libpath'}; foreach my $item ((glob "$libpath/Bugzilla/Config/*.pm")) { $item =~ m#/([^/]+)\.pm$#; my $module = $1; @@ -265,6 +230,7 @@ sub UpdateParams { sub WriteParams { require Data::Dumper; + my $datadir = bz_locations()->{'datadir'}; # This only has an affect for Data::Dumper >= 2.12 (ie perl >= 5.8.0) # Its just cosmetic, though, so that doesn't matter @@ -294,7 +260,7 @@ sub WriteParams { sub ChmodDataFile { my ($file, $mask) = @_; my $perm = 0770; - if ((stat($datadir))[2] & 0002) { + if ((stat(bz_locations()->{'datadir'}))[2] & 0002) { $perm = 0777; } $perm = $perm & $mask; diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 9d8059478..8ce1482c1 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -22,6 +22,7 @@ package Bugzilla::Hook; +use Bugzilla::Constants; use Bugzilla::Util; use Bugzilla::Error; @@ -32,7 +33,7 @@ sub process { trick_taint($name); # get a list of all extensions - my @extensions = glob($Bugzilla::Config::extensionsdir."/*"); + my @extensions = glob(bz_locations()->{'extensionsdir'} . "/*"); # check each extension to see if it uses the hook # if so, invoke the extension source file: diff --git a/Bugzilla/Mailer.pm b/Bugzilla/Mailer.pm index 05ef82149..ce3565368 100644 --- a/Bugzilla/Mailer.pm +++ b/Bugzilla/Mailer.pm @@ -37,7 +37,7 @@ use base qw(Exporter); @Bugzilla::Mailer::EXPORT = qw(MessageToMTA); use Bugzilla::Constants; -use Bugzilla::Config qw(:DEFAULT $datadir); +use Bugzilla::Config; use Bugzilla::Util; use Mail::Header; @@ -99,7 +99,8 @@ sub MessageToMTA { } my $mailer = new Mail::Mailer Param("mail_delivery_method"), @args; if (Param("mail_delivery_method") eq "testfile") { - $Mail::Mailer::testfile::config{outfile} = "$datadir/mailer.testfile"; + $Mail::Mailer::testfile::config{outfile} = + bz_locations()->{'datadir'} . '/mailer.testfile'; } $mailer->open($headers->header_hashref); diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 1fcc867b5..59cf02dc4 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -35,7 +35,7 @@ package Bugzilla::Template; use strict; use Bugzilla::Constants; -use Bugzilla::Config qw(:DEFAULT $templatedir $datadir $project); +use Bugzilla::Config; use Bugzilla::Util; use Bugzilla::User; use Bugzilla::Error; @@ -110,6 +110,9 @@ sub getTemplateIncludePath { if ($template_include_path) { return $template_include_path; } + my $templatedir = bz_locations()->{'templatedir'}; + my $project = bz_locations()->{'project'}; + my $languages = trim(Param('languages')); if (not ($languages =~ /,/)) { if ($project) { @@ -159,7 +162,7 @@ sub getTemplateIncludePath { } # add in extension template directories: - my @extensions = glob($Bugzilla::Config::extensionsdir."/*"); + my @extensions = glob(bz_locations()->{'extensionsdir'} . "/*"); foreach my $extension (@extensions) { trick_taint($extension); # since this comes right from the filesystem # we have bigger issues if it is insecure @@ -533,7 +536,7 @@ sub create { PRE_CHOMP => 1, TRIM => 1, - COMPILE_DIR => "$datadir/template", + COMPILE_DIR => bz_locations()->{'datadir'} . "/template", # Initialize templates (f.e. by loading plugins like Hook). PRE_PROCESS => "global/initialize.none.tmpl", diff --git a/Bugzilla/Template/Plugin/Hook.pm b/Bugzilla/Template/Plugin/Hook.pm index 7ff707fc1..c2e1626ef 100644 --- a/Bugzilla/Template/Plugin/Hook.pm +++ b/Bugzilla/Template/Plugin/Hook.pm @@ -26,6 +26,7 @@ package Bugzilla::Template::Plugin::Hook; use strict; use Bugzilla::Config; +use Bugzilla::Constants; use Bugzilla::Template; use Bugzilla::Util; use Bugzilla::Error; @@ -64,7 +65,7 @@ sub process { my $type = $2; # munge the filename to create the extension hook filename: my $extensiontemplate = $subpath.'/'.$templatename.'-'.$hook_name.'.'.$type.'.tmpl'; - my @extensions = glob($Bugzilla::Config::extensionsdir."/*"); + my @extensions = glob(bz_locations()->{'extensionsdir'} . "/*"); my @usedlanguages = getLanguages(); foreach my $extension (@extensions) { foreach my $language (@usedlanguages) { diff --git a/Bugzilla/Update.pm b/Bugzilla/Update.pm index a672bd8bb..1aef2bf17 100644 --- a/Bugzilla/Update.pm +++ b/Bugzilla/Update.pm @@ -18,10 +18,10 @@ package Bugzilla::Update; use strict; -use Bugzilla::Config qw($datadir); +use Bugzilla::Constants; use constant REMOTE_FILE => 'http://updates.bugzilla.org/bugzilla-update.xml'; -use constant LOCAL_FILE => "/bugzilla-update.xml"; # Relative to $datadir. +use constant LOCAL_FILE => "/bugzilla-update.xml"; # Relative to datadir. use constant TIME_INTERVAL => 604800; # Default is one week, in seconds. use constant TIMEOUT => 5; # Number of seconds before timeout. @@ -34,7 +34,7 @@ sub get_notifications { eval("require XML::Twig"); return if $@; - my $local_file = $datadir . LOCAL_FILE; + 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. if (!-e $local_file || (time() - (stat($local_file))[9] > TIME_INTERVAL)) { @@ -127,7 +127,7 @@ sub _synchronize_data { eval("require LWP::UserAgent"); return if $@; - my $local_file = $datadir . LOCAL_FILE; + my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE; my $ua = LWP::UserAgent->new(); $ua->timeout(TIMEOUT); -- cgit v1.2.3-24-g4f1b