From da857afa089e79ad16fb833dd1ffe397055fd892 Mon Sep 17 00:00:00 2001 From: "bbaetz%acm.org" <> Date: Sat, 22 Nov 2003 11:50:36 +0000 Subject: Bug 208604 - Make data/template dir locations configurable --- Bugzilla/BugMail.pm | 4 +- Bugzilla/Config.pm | 54 +++++++---- Bugzilla/DB.pm | 4 +- Bugzilla/Template.pm | 15 ++- Bugzilla/Util.pm | 2 + checksetup.pl | 201 +++++++++++++++++++++------------------ collectstats.pl | 17 ++-- contrib/bug_email.pl | 25 ++--- contrib/bugzilla_email_append.pl | 18 ++-- defparams.pl | 16 ++-- doeditparams.cgi | 4 +- duplicates.cgi | 7 +- editcomponents.cgi | 7 +- editkeywords.cgi | 8 +- editmilestones.cgi | 11 +-- editproducts.cgi | 8 +- editversions.cgi | 9 +- globals.pl | 20 ++-- importxml.pl | 7 +- move.pl | 7 +- page.cgi | 2 +- reports.cgi | 4 +- showdependencygraph.cgi | 16 ++-- 23 files changed, 264 insertions(+), 202 deletions(-) diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm index 7937fe176..7fdf44980 100644 --- a/Bugzilla/BugMail.pm +++ b/Bugzilla/BugMail.pm @@ -32,6 +32,8 @@ package Bugzilla::BugMail; use RelationSet; +use Bugzilla::Config qw(:DEFAULT $datadir); + # This code is really ugly. It was a commandline interface, then it was moved # There are package-global variables which we rely on ProcessOneBug to clean # up each time, and other sorts of fun. @@ -66,7 +68,7 @@ sub AUTOLOAD { } # This is run when we load the package -if (open(NOMAIL, ") { $nomail{trim($_)} = 1; } diff --git a/Bugzilla/Config.pm b/Bugzilla/Config.pm index f0d64e5ac..f639b4a44 100644 --- a/Bugzilla/Config.pm +++ b/Bugzilla/Config.pm @@ -34,6 +34,29 @@ use base qw(Exporter); use Bugzilla::Util; +# 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 showdependancygraph.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 dependancy +# graphs (since the path will be wrong in the HTML). This will be fixed at +# some point. + +our $libpath = '.'; +our $localconfig = "$libpath/localconfig"; +our $datadir = "$libpath/data"; +our $templatedir = "$libpath/template"; +our $webdotdir = "$datadir/webdot"; + # Module stuff @Bugzilla::Config::EXPORT = qw(Param); @@ -42,13 +65,15 @@ use Bugzilla::Util; # when it shouldn't # ChmodDataFile is here until that stuff all moves out of globals.pl # into this file -@Bugzilla::Config::EXPORT_OK = qw($contenttypes ChmodDataFile); +@Bugzilla::Config::EXPORT_OK = qw(ChmodDataFile); + %Bugzilla::Config::EXPORT_TAGS = ( admin => [qw(GetParamList UpdateParams SetParam WriteParams)], db => [qw($db_host $db_port $db_name $db_user $db_pass $db_sock)], + locations => [qw($libpath $localconfig $datadir $templatedir $webdotdir)], ); -Exporter::export_ok_tags('admin', 'db'); +Exporter::export_ok_tags('admin', 'db', 'locations'); # Bugzilla version $Bugzilla::Config::VERSION = "2.17.6"; @@ -74,23 +99,24 @@ my %param; # XXX - mod_perl - need to register Apache init handler for params sub _load_datafiles { # read in localconfig variables - do 'localconfig'; + do $localconfig; - if (-e 'data/params') { + if (-e "$datadir/params") { # Handle reading old param files by munging the symbol table # Don't have to do this if we use safe mode, since its evaled # in a sandbox where $foo is in the same module as $::foo #local *::param = \%param; - # Note that checksetup.pl sets file permissions on 'data/params' + # Note that checksetup.pl sets file permissions on '$datadir/params' # Using Safe mode is _not_ a guarantee of safety if someone does # manage to write to the file. However, it won't hurt... # See bug 165144 for not needing to eval this at all my $s = new Safe; - $s->rdo('data/params'); - die "Error evaluating data/params: $@" if $@; + $s->rdo("$datadir/params"); + die "Error reading $datadir/params: $!" if $!; + die "Error evaluating $datadir/params: $@" if $@; # Now read the param back out from the sandbox %param = %{$s->varglob('param')}; @@ -226,17 +252,17 @@ sub WriteParams { require File::Temp; my ($fh, $tmpname) = File::Temp::tempfile('params.XXXXX', - DIR => 'data' ); + DIR => $datadir ); print $fh (Data::Dumper->Dump([ \%param ], [ '*param' ])) || die "Can't write param file: $!"; close $fh; - rename $tmpname, "data/params" - || die "Can't rename $tmpname to data/params: $!"; + rename $tmpname, "$datadir/params" + || die "Can't rename $tmpname to $datadir/params: $!"; - ChmodDataFile('data/params', 0666); + ChmodDataFile("$datadir/params", 0666); } # Some files in the data directory must be world readable iff we don't have @@ -248,7 +274,7 @@ sub WriteParams { sub ChmodDataFile { my ($file, $mask) = @_; my $perm = 0770; - if ((stat('data'))[2] & 0002) { + if ((stat($datadir))[2] & 0002) { $perm = 0777; } $perm = $perm & $mask; @@ -321,10 +347,6 @@ Bugzilla::Config - Configuration parameters for Bugzilla use Bugzilla::Config qw(:db); print "Connecting to $db_name as $db_user with $db_pass\n"; - # This variable does not belong in localconfig, and needs to go - # somewhere better - use Bugzilla::Config($contenttypes) - =head1 DESCRIPTION This package contains ways to access Bugzilla configuration parameters. diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index 1d2e96614..a747aebd6 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -135,9 +135,9 @@ sub connect_shadow { } sub connect_main { - my $dsn = "DBI:mysql:host=$::db_host;database=$::db_name;port=$::db_port"; + my $dsn = "DBI:mysql:host=$db_host;database=$db_name;port=$db_port"; - $dsn .= ";mysql_socket=$::db_sock" if $::db_sock; + $dsn .= ";mysql_socket=$db_sock" if $db_sock; return _connect($dsn); } diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index f9342e11f..d981c7a59 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -29,7 +29,7 @@ package Bugzilla::Template; use strict; -use Bugzilla::Config; +use Bugzilla::Config qw(:DEFAULT $templatedir $datadir); use Bugzilla::Util; # for time2str - replace by TT Date plugin?? @@ -37,6 +37,7 @@ use Date::Format (); use base qw(Template); +# XXX - mod_perl my $template_include_path; # Make an ordered list out of a HTTP Accept-Language header see RFC 2616, 14.4 @@ -69,13 +70,16 @@ sub sortAcceptLanguage { # If no Accept-Language is present it uses the defined default sub getTemplateIncludePath () { # Return cached value if available + + # XXXX - mod_perl! if ($template_include_path) { return $template_include_path; } my $languages = trim(Param('languages')); if (not ($languages =~ /,/)) { return $template_include_path = - ["template/$languages/custom", "template/$languages/default"]; + ["$templatedir/$languages/custom", + "$templatedir/$languages/default"]; } my @languages = sortAcceptLanguage($languages); my @accept_language = sortAcceptLanguage($ENV{'HTTP_ACCEPT_LANGUAGE'} || "" ); @@ -92,7 +96,9 @@ sub getTemplateIncludePath () { } push(@usedlanguages, Param('defaultlanguage')); return $template_include_path = - [map(("template/$_/custom", "template/$_/default"), @usedlanguages)]; + [map(("$templatedir/$_/custom", + "$templatedir/$_/default"), + @usedlanguages)]; } @@ -177,7 +183,7 @@ sub create { PRE_CHOMP => 1, TRIM => 1, - COMPILE_DIR => 'data/', + COMPILE_DIR => "$datadir/template", # Functions for processing text within templates in various ways. # IMPORTANT! When adding a filter here that does not override a @@ -321,4 +327,3 @@ Cinstance-Etemplate> to get an already created module. =head1 SEE ALSO L, L