]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 342121: Remove usage of Config qw(:locations) in favor of Constants::bz_locations()
authormkanat%bugzilla.org <>
Thu, 29 Jun 2006 23:49:55 +0000 (23:49 +0000)
committermkanat%bugzilla.org <>
Thu, 29 Jun 2006 23:49:55 +0000 (23:49 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=justdave

Bugzilla/Attachment.pm
Bugzilla/BugMail.pm
Bugzilla/Config.pm
Bugzilla/Hook.pm
Bugzilla/Mailer.pm
Bugzilla/Template.pm
Bugzilla/Template/Plugin/Hook.pm
Bugzilla/Update.pm
checksetup.pl

index a7961d764874eb2c6eaac8956776d767bbc7c8e6..78d3260494dcce2b97d8314a08b0e4224c383e5b 100644 (file)
@@ -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/;
index ef432c1e63ee32f19f494ab6d272790a679b2a59..7c8aee1baed47df2b4e224137c162981fdf2de46 100644 (file)
@@ -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>) {
         $nomail{trim($_)} = 1;
     }
index cb20fad242a794501b95b4ef299bf528bc2dedaa..a1c4b1f2551fd429f97a13d0333124b8583d987b 100644 (file)
@@ -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;
index 9d8059478bcdad520f9ca81995eb22a1e2d5005e..8ce1482c1466b9b99520ece045096ffd9f49e7fe 100644 (file)
@@ -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:
index 05ef82149d587b5842bfa2cec575aedbcf17a8fb..ce35653681c846914987a1ef1507a6668a102e23 100644 (file)
@@ -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);
index 1fcc867b5ef24dfe8fc4a4583da5563e4b29bf16..59cf02dc479affb96a37fe90371eb36a5e10e9de 100644 (file)
@@ -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",
index 7ff707fc1f3af76cadc33c6b8e5c3bee8ea35480..c2e1626efd2d50310d5f1c87982c78de806b4ed4 100644 (file)
@@ -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) {
index a672bd8bb0419f3fa9d8d454813f0feeb5048486..1aef2bf17711431b98c0d78d0c36cc0caa6b2a50 100644 (file)
@@ -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);
index d6064729519528ece84a9e54e818c697c6ea1bf4..349ac0b461f91d9fb4c0858a8ee391c53bde9292 100755 (executable)
@@ -510,7 +510,7 @@ BEGIN {
     $::ENV{'PATH'} = $env;
 
     require Bugzilla::Config;
-    import Bugzilla::Config qw(:DEFAULT :admin :locations);
+    import Bugzilla::Config qw(:DEFAULT :admin);
 }
 
 # 12/17/00 justdave@syndicomm.com - removed declarations of the localconfig
@@ -550,6 +550,7 @@ BEGIN {
 
 print "Checking user setup ...\n" unless $silent;
 $@ = undef;
+my $localconfig = bz_locations()->{'localconfig'};
 do $localconfig;
 if ($@) { # capture errors in localconfig, bug 97290
    print STDERR <<EOT;
@@ -582,7 +583,7 @@ sub LocalVar
     my ($name, $definition) = @_;
     return if LocalVarExists($name); # if localconfig declared it, we're done.
     $newstuff .= " " . $name;
-    open FILE, '>>', $localconfig;
+    open FILE, '>>', bz_locations()->{'localconfig'};
     print FILE ($answer{$name} or $definition), "\n\n";
     close FILE;
 }
@@ -803,7 +804,8 @@ if (LocalVarExists('mysqlpath')) {
 if ($newstuff ne "") {
     print "\nThis version of Bugzilla contains some variables that you may \n",
           "want to change and adapt to your local settings. Please edit the\n",
-          "file '$localconfig' and rerun checksetup.pl\n\n",
+          "file " . bz_locations()->{'localconfig'} ." and rerun ",
+          "checksetup.pl\n\n",
           "The following variables are new to localconfig since you last ran\n",
           "checksetup.pl:  $newstuff\n\n";
     exit;
@@ -938,6 +940,7 @@ if ($my_db_check) {
        # Try to create the DB, and if we fail print an error.
        if (!eval { $dbh->do("CREATE DATABASE $my_db_name") }) {
             my $error = $dbh->errstr;
+            my $localconfig = bz_locations()->{'localconfig'};
             die <<"EOF"
 
 The '$my_db_name' database could not be created.  The error returned was:
@@ -1048,7 +1051,7 @@ while (my ($table, $values) = each %$enum_values) {
 #
 # Create initial --DATA-- directory and make the initial empty files there:
 #
-
+my $datadir = bz_locations()->{'datadir'};
 unless (-d $datadir && -e "$datadir/nomail") {
     print "Creating data directory ($datadir) ...\n";
     # permissions for non-webservergroup are fixed later on
@@ -1058,13 +1061,14 @@ unless (-d $datadir && -e "$datadir/nomail") {
     open FILE, '>>', "$datadir/mail"; close FILE;
 }
 
-
+my $attachdir = bz_locations->{'attachdir'};
 unless (-d $attachdir) {
     print "Creating local attachments directory ...\n";
     # permissions for non-webservergroup are fixed later on
     mkdir $attachdir, 0770;
 }
 
+my $extensionsdir = bz_locations->{'extensionsdir'};
 # ZLL: 2005-08-20 Create extensions/ if it does not already exist:
 unless (-d $extensionsdir) {
     print "Creating extensions directory ($extensionsdir) ...\n";
@@ -1161,6 +1165,7 @@ unless (-d "$datadir/mining") {
     mkdir "$datadir/mining", 0700;
 }
 
+my $webdotdir = bz_locations()->{'webdotdir'};
 unless (-d "$webdotdir") {
     # perms/ownership are fixed up later
     mkdir "$webdotdir", 0700;
@@ -1277,6 +1282,7 @@ END
     chmod $fileperm, "$datadir/.htaccess";
   }
   # Ditto for the template dir
+  my $templatedir = bz_locations()->{'templatedir'};
   if (!-e "$templatedir/.htaccess") {
     print "Creating $templatedir/.htaccess...\n";
     open HTACCESS, '>', "$templatedir/.htaccess";
@@ -1344,11 +1350,7 @@ END
     }
 }
 
-# Just to be sure ...
-unlink "$datadir/versioncache";
-
 # Check for a new install
-
 my $newinstall = !-e "$datadir/params";
 
 # Remove parameters from the params file that no longer exist in Bugzilla,
@@ -1405,6 +1407,7 @@ if ($newinstall) {
 # WriteParams will only write out still-valid entries
 WriteParams();
 
+my $templatedir = bz_locations()->{'templatedir'};
 unless ($switch{'no_templates'}) {
     if (-e "$datadir/template") {
         print "Removing existing compiled templates ...\n" unless $silent;
@@ -1579,7 +1582,8 @@ if ($^O !~ /MSWin32/i) {
         fixPerms("$datadir/duplicates", $<, $webservergid, 027, 1);
         fixPerms("$datadir/mining", $<, $webservergid, 027, 1);
         fixPerms("$datadir/template", $<, $webservergid, 007, 1); # webserver will write to these
-        fixPerms($attachdir, $<, $webservergid, 007, 1); # webserver will write to these
+        # webserver will write to attachdir.
+        fixPerms(bz_locations()->{'attachdir'}, $<, $webservergid, 007, 1);
         fixPerms($webdotdir, $<, $webservergid, 007, 1);
         fixPerms("$webdotdir/.htaccess", $<, $webservergid, 027);
         fixPerms("$datadir/params", $<, $webservergid, 017);
@@ -4352,6 +4356,11 @@ EOF
                                                  NOTNULL => 1});
 }
 
+if (-e "$datadir/versioncache") {
+    print "Removing versioncache...\n";
+    unlink "$datadir/versioncache";
+}
+
 
 # If you had to change the --TABLE-- definition in any way, then add your
 # differential change code *** A B O V E *** this comment.
@@ -4778,8 +4787,6 @@ $dbh->do("UPDATE components " .
             "SET initialowner = $adminuid " .
           "WHERE initialowner = 0");
 
-unlink "$datadir/versioncache";
-
 # Check if the default parameter for urlbase is still set, and if so, give
 # notification that they should go and visit editparams.cgi