Commit 0fccdb26 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 352235: Use Bugzilla->localconfig everywhere instead of :localconfig from Bugzilla::Config

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=myk
parent e1cdcb29
...@@ -19,7 +19,6 @@ use strict; ...@@ -19,7 +19,6 @@ use strict;
package Bugzilla::Attachment::PatchReader; package Bugzilla::Attachment::PatchReader;
use Bugzilla::Config qw(:localconfig);
use Bugzilla::Error; use Bugzilla::Error;
...@@ -27,6 +26,7 @@ sub process_diff { ...@@ -27,6 +26,7 @@ sub process_diff {
my ($attachment, $format, $context) = @_; my ($attachment, $format, $context) = @_;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $lc = Bugzilla->localconfig;
my $vars = {}; my $vars = {};
my ($reader, $last_reader) = setup_patch_readers(undef, $context); my ($reader, $last_reader) = setup_patch_readers(undef, $context);
...@@ -42,7 +42,7 @@ sub process_diff { ...@@ -42,7 +42,7 @@ sub process_diff {
} }
else { else {
$vars->{'other_patches'} = []; $vars->{'other_patches'} = [];
if ($interdiffbin && $diffpath) { if ($lc->{interdiffbin} && $lc->{diffpath}) {
# Get list of attachments on this bug. # Get list of attachments on this bug.
# Ignore the current patch, but select the one right before it # Ignore the current patch, but select the one right before it
# chronologically. # chronologically.
...@@ -84,6 +84,7 @@ sub process_diff { ...@@ -84,6 +84,7 @@ sub process_diff {
sub process_interdiff { sub process_interdiff {
my ($old_attachment, $new_attachment, $format, $context) = @_; my ($old_attachment, $new_attachment, $format, $context) = @_;
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $lc = Bugzilla->localconfig;
my $vars = {}; my $vars = {};
# Get old patch data. # Get old patch data.
...@@ -95,8 +96,8 @@ sub process_interdiff { ...@@ -95,8 +96,8 @@ sub process_interdiff {
# Send through interdiff, send output directly to template. # Send through interdiff, send output directly to template.
# Must hack path so that interdiff will work. # Must hack path so that interdiff will work.
$ENV{'PATH'} = $diffpath; $ENV{'PATH'} = $lc->{diffpath};
open my $interdiff_fh, "$interdiffbin $old_filename $new_filename|"; open my $interdiff_fh, "$lc->{interdiffbin} $old_filename $new_filename|";
binmode $interdiff_fh; binmode $interdiff_fh;
my ($reader, $last_reader) = setup_patch_readers("", $context); my ($reader, $last_reader) = setup_patch_readers("", $context);
...@@ -219,7 +220,9 @@ sub setup_patch_readers { ...@@ -219,7 +220,9 @@ sub setup_patch_readers {
} }
# Add in cvs context if we have the necessary info to do it # Add in cvs context if we have the necessary info to do it
if ($context ne 'patch' && $cvsbin && Bugzilla->params->{'cvsroot_get'}) { if ($context ne 'patch' && Bugzilla->localconfig->{cvsbin}
&& Bugzilla->params->{'cvsroot_get'})
{
require PatchReader::AddCVSContext; require PatchReader::AddCVSContext;
$last_reader->sends_data_to( $last_reader->sends_data_to(
new PatchReader::AddCVSContext($context, Bugzilla->params->{'cvsroot_get'})); new PatchReader::AddCVSContext($context, Bugzilla->params->{'cvsroot_get'}));
...@@ -246,7 +249,8 @@ sub setup_template_patch_reader { ...@@ -246,7 +249,8 @@ sub setup_template_patch_reader {
$vars->{'collapsed'} = $cgi->param('collapsed'); $vars->{'collapsed'} = $cgi->param('collapsed');
$vars->{'context'} = $context; $vars->{'context'} = $context;
$vars->{'do_context'} = $cvsbin && Bugzilla->params->{'cvsroot_get'} && !$vars->{'newid'}; $vars->{'do_context'} = Bugzilla->localconfig->{cvsbin}
&& Bugzilla->params->{'cvsroot_get'} && !$vars->{'newid'};
# Print everything out. # Print everything out.
print $cgi->header(-type => 'text/html', print $cgi->header(-type => 'text/html',
......
...@@ -43,18 +43,13 @@ use File::Temp; ...@@ -43,18 +43,13 @@ use File::Temp;
%Bugzilla::Config::EXPORT_TAGS = %Bugzilla::Config::EXPORT_TAGS =
( (
admin => [qw(update_params SetParam write_params)], admin => [qw(update_params SetParam write_params)],
db => [qw($db_driver $db_host $db_port $db_name $db_user $db_pass $db_sock
$db_check)],
localconfig => [qw($cvsbin $interdiffbin $diffpath $webservergroup)],
); );
Exporter::export_ok_tags('admin', 'db', 'localconfig'); Exporter::export_ok_tags('admin');
use vars qw(@param_list); use vars qw(@param_list);
# INITIALISATION CODE # INITIALISATION CODE
# Perl throws a warning if we use bz_locations() directly after do. # Perl throws a warning if we use bz_locations() directly after do.
our $localconfig = bz_locations()->{'localconfig'};
do $localconfig;
our %params; our %params;
# Load in the param definitions # Load in the param definitions
sub _load_params { sub _load_params {
...@@ -327,10 +322,6 @@ Bugzilla::Config - Configuration parameters for Bugzilla ...@@ -327,10 +322,6 @@ Bugzilla::Config - Configuration parameters for Bugzilla
SetParam($param, $value); SetParam($param, $value);
write_params(); write_params();
# Localconfig variables may also be imported
use Bugzilla::Config qw(:db);
print "Connecting to $db_name as $db_user with $db_pass\n";
=head1 DESCRIPTION =head1 DESCRIPTION
This package contains ways to access Bugzilla configuration parameters. This package contains ways to access Bugzilla configuration parameters.
......
...@@ -35,7 +35,6 @@ use DBI; ...@@ -35,7 +35,6 @@ use DBI;
# Inherit the DB class from DBI::db. # Inherit the DB class from DBI::db.
use base qw(DBI::db); use base qw(DBI::db);
use Bugzilla::Config qw(:db);
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Install::Requirements; use Bugzilla::Install::Requirements;
use Bugzilla::Install::Localconfig; use Bugzilla::Install::Localconfig;
...@@ -81,14 +80,17 @@ sub connect_shadow { ...@@ -81,14 +80,17 @@ sub connect_shadow {
die "Tried to connect to non-existent shadowdb" die "Tried to connect to non-existent shadowdb"
unless $params->{'shadowdb'}; unless $params->{'shadowdb'};
return _connect($db_driver, $params->{"shadowdbhost"}, my $lc = Bugzilla->localconfig;
return _connect($lc->{db_driver}, $params->{"shadowdbhost"},
$params->{'shadowdb'}, $params->{"shadowdbport"}, $params->{'shadowdb'}, $params->{"shadowdbport"},
$params->{"shadowdbsock"}, $db_user, $db_pass); $params->{"shadowdbsock"}, $lc->{db_user}, $lc->{db_pass});
} }
sub connect_main { sub connect_main {
return _connect($db_driver, $db_host, $db_name, $db_port, my $lc = Bugzilla->localconfig;
$db_sock, $db_user, $db_pass); return _connect($lc->{db_driver}, $lc->{db_host}, $lc->{db_name}, $lc->{db_port},
$lc->{db_sock}, $lc->{db_user}, $lc->{db_pass});
} }
sub _connect { sub _connect {
...@@ -120,10 +122,11 @@ sub _handle_error { ...@@ -120,10 +122,11 @@ sub _handle_error {
sub bz_check_requirements { sub bz_check_requirements {
my ($output) = @_; my ($output) = @_;
my $db = DB_MODULE->{lc($db_driver)}; my $lc = Bugzilla->localconfig;
my $db = DB_MODULE->{lc($lc->{db_driver})};
# Only certain values are allowed for $db_driver. # Only certain values are allowed for $db_driver.
if (!defined $db) { if (!defined $db) {
die "$db_driver is not a valid choice for \$db_driver in" die "$lc->{db_driver} is not a valid choice for \$db_driver in"
. bz_locations()->{'localconfig'}; . bz_locations()->{'localconfig'};
} }
...@@ -149,7 +152,7 @@ EOT ...@@ -149,7 +152,7 @@ EOT
# We don't try to connect to the actual database if $db_check is # We don't try to connect to the actual database if $db_check is
# disabled. # disabled.
unless ($db_check) { unless ($lc->{db_check}) {
print "\n" if $output; print "\n" if $output;
return; return;
} }
...@@ -186,6 +189,7 @@ sub bz_create_database { ...@@ -186,6 +189,7 @@ sub bz_create_database {
my $dbh; my $dbh;
# See if we can connect to the actual Bugzilla database. # See if we can connect to the actual Bugzilla database.
my $conn_success = eval { $dbh = connect_main(); }; my $conn_success = eval { $dbh = connect_main(); };
my $db_name = Bugzilla->localconfig->{db_name};
if (!$conn_success) { if (!$conn_success) {
$dbh = _get_no_db_connection(); $dbh = _get_no_db_connection();
...@@ -209,12 +213,13 @@ sub bz_create_database { ...@@ -209,12 +213,13 @@ sub bz_create_database {
sub _get_no_db_connection { sub _get_no_db_connection {
my ($sql_server) = @_; my ($sql_server) = @_;
my $dbh; my $dbh;
my $lc = Bugzilla->localconfig;
my $conn_success = eval { my $conn_success = eval {
$dbh = _connect($db_driver, $db_host, '', $db_port, $dbh = _connect($lc->{db_driver}, $lc->{db_host}, '', $lc->{db_port},
$db_sock, $db_user, $db_pass); $lc->{db_sock}, $lc->{db_user}, $lc->{db_pass});
}; };
if (!$conn_success) { if (!$conn_success) {
my $sql_server = DB_MODULE->{lc($db_driver)}->{name}; my $sql_server = DB_MODULE->{lc($lc->{db_driver})}->{name};
# Can't use $dbh->errstr because $dbh is undef. # Can't use $dbh->errstr because $dbh is undef.
my $error = $DBI::errstr; my $error = $DBI::errstr;
chomp($error); chomp($error);
...@@ -230,7 +235,8 @@ sub _get_no_db_connection { ...@@ -230,7 +235,8 @@ sub _get_no_db_connection {
# username, and db_new errors can show up on CGIs. # username, and db_new errors can show up on CGIs.
sub _bz_connect_error_reasons { sub _bz_connect_error_reasons {
my $lc_file = bz_locations()->{'localconfig'}; my $lc_file = bz_locations()->{'localconfig'};
my $db = DB_MODULE->{lc($db_driver)}; my $lc = Bugzilla->localconfig;
my $db = DB_MODULE->{lc($lc->{db_driver})};
my $server = $db->{name}; my $server = $db->{name};
return <<EOT; return <<EOT;
...@@ -241,7 +247,7 @@ This might have several reasons: ...@@ -241,7 +247,7 @@ This might have several reasons:
server configuration or the database access rights. Read the Bugzilla server configuration or the database access rights. Read the Bugzilla
Guide in the doc directory. The section about database configuration Guide in the doc directory. The section about database configuration
should help. should help.
* Your password for the '$db_user' user, specified in \$db_pass, is * Your password for the '$lc->{db_user}' user, specified in \$db_pass, is
incorrect, in '$lc_file'. incorrect, in '$lc_file'.
* There is a subtle problem with Perl, DBI, or $server. Make * There is a subtle problem with Perl, DBI, or $server. Make
sure all settings in '$lc_file' are correct. If all else fails, set sure all settings in '$lc_file' are correct. If all else fails, set
...@@ -355,7 +361,8 @@ sub bz_server_version { ...@@ -355,7 +361,8 @@ sub bz_server_version {
sub bz_last_key { sub bz_last_key {
my ($self, $table, $column) = @_; my ($self, $table, $column) = @_;
return $self->last_insert_id($db_name, undef, $table, $column); return $self->last_insert_id(Bugzilla->localconfig->{db_name}, undef,
$table, $column);
} }
sub bz_get_field_defs { sub bz_get_field_defs {
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
# implied. See the License for the specific language governing # implied. See the License for the specific language governing
# rights and limitations under the License. # rights and limitations under the License.
# #
# The Initial Developer of the Original Code is Everything Solved.
# Portions created by Everything Solved are Copyright (C) 2006
# Everything Solved. All Rights Reserved.
#
# The Original Code is the Bugzilla Bug Tracking System. # The Original Code is the Bugzilla Bug Tracking System.
# #
# Contributor(s): Max Kanat-Alexander <mkanat@bugzilla.org> # Contributor(s): Max Kanat-Alexander <mkanat@bugzilla.org>
...@@ -39,10 +43,7 @@ our @EXPORT_OK = qw( ...@@ -39,10 +43,7 @@ our @EXPORT_OK = qw(
update_localconfig update_localconfig
); );
# We write this constant as a sub because it has to call other use constant LOCALCONFIG_VARS => (
# subroutines.
sub LOCALCONFIG_VARS {
return (
{ {
name => 'create_htaccess', name => 'create_htaccess',
default => 1, default => 1,
...@@ -156,7 +157,7 @@ EOT ...@@ -156,7 +157,7 @@ EOT
}, },
{ {
name => 'cvsbin', name => 'cvsbin',
default => &_get_default_cvsbin, default => \&_get_default_cvsbin,
desc => <<EOT desc => <<EOT
# For some optional functions of Bugzilla (such as the pretty-print patch # For some optional functions of Bugzilla (such as the pretty-print patch
# viewer), we need the cvs binary to access files and revisions. # viewer), we need the cvs binary to access files and revisions.
...@@ -166,7 +167,7 @@ EOT ...@@ -166,7 +167,7 @@ EOT
}, },
{ {
name => 'interdiffbin', name => 'interdiffbin',
default => &_get_default_interdiffbin, default => \&_get_default_interdiffbin,
desc => <<EOT desc => <<EOT
# For some optional functions of Bugzilla (such as the pretty-print patch # For some optional functions of Bugzilla (such as the pretty-print patch
# viewer), we need the interdiff binary to make diffs between two patches. # viewer), we need the interdiff binary to make diffs between two patches.
...@@ -176,14 +177,13 @@ EOT ...@@ -176,14 +177,13 @@ EOT
}, },
{ {
name => 'diffpath', name => 'diffpath',
default => &_get_default_diffpath, default => \&_get_default_diffpath,
desc => <<EOT desc => <<EOT
# The interdiff feature needs diff, so we have to have that path. # The interdiff feature needs diff, so we have to have that path.
# Please specify the directory name only; do not use trailing slash. # Please specify the directory name only; do not use trailing slash.
EOT EOT
}, },
); );
}
use constant OLD_LOCALCONFIG_VARS => qw( use constant OLD_LOCALCONFIG_VARS => qw(
mysqlpath mysqlpath
...@@ -280,6 +280,7 @@ sub update_localconfig { ...@@ -280,6 +280,7 @@ sub update_localconfig {
my $name = $var->{name}; my $name = $var->{name};
if (!defined $localconfig->{$name}) { if (!defined $localconfig->{$name}) {
push(@new_vars, $name); push(@new_vars, $name);
$var->{default} = &{$var->{default}} if ref($var->{default}) eq 'CODE';
$localconfig->{$name} = $answer->{$name} || $var->{default}; $localconfig->{$name} = $answer->{$name} || $var->{default};
} }
} }
......
...@@ -21,14 +21,8 @@ ...@@ -21,14 +21,8 @@
use strict; use strict;
use lib "."; use lib ".";
BEGIN { use Bugzilla;
my $envpath = $ENV{'PATH'};
require Bugzilla;
$ENV{'PATH'} = $envpath;
}
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Config qw(:localconfig);
use Socket; use Socket;
...@@ -62,6 +56,7 @@ if ($^O !~ /MSWin32/i) { ...@@ -62,6 +56,7 @@ if ($^O !~ /MSWin32/i) {
# Determine the numeric GID of $webservergroup # Determine the numeric GID of $webservergroup
my $webgroupnum = 0; my $webgroupnum = 0;
my $webservergroup = Bugzilla->localconfig->{webservergroup};
if ($webservergroup =~ /^(\d+)$/) { if ($webservergroup =~ /^(\d+)$/) {
$webgroupnum = $1; $webgroupnum = $1;
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment