From 1024d9b797217682cba6d89e484620782a7bb327 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Thu, 21 Jun 2018 11:07:50 -0400 Subject: Bug 1461379 - use DBIx::Connector to manage database connections --- Bugzilla/DB.pm | 19 ++++++------------- Bugzilla/ModPerl.pm | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index 893c9235e..33801e989 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -11,6 +11,8 @@ use 5.10.1; use Moo; use DBI; +use DBIx::Connector; +our %Connector; has 'dbh' => ( is => 'lazy', @@ -213,7 +215,6 @@ sub bz_check_server_version { my ($self, $db, $output) = @_; my $sql_vers = $self->bz_server_version; - $self->disconnect; my $sql_want = $db->{db_version}; my $version_ok = vers_cmp($sql_vers, $sql_want) > -1 ? 1 : 0; @@ -269,7 +270,6 @@ sub bz_create_database { } } - $dbh->disconnect; } # A helper for bz_create_database and bz_check_requirements. @@ -278,6 +278,7 @@ sub _get_no_db_connection { my $dbh; my %connect_params = %{ Bugzilla->localconfig }; $connect_params{db_name} = ''; + local %Connector = (); my $conn_success = eval { $dbh = _connect(\%connect_params); }; @@ -1261,7 +1262,7 @@ sub _build_dbh { # set up default attributes used to connect to the database # (may be overridden by DB driver implementations) - my $attributes = { RaiseError => 0, + my $attributes = { RaiseError => 1, AutoCommit => 1, PrintError => 0, ShowErrorStatement => 1, @@ -1286,17 +1287,9 @@ sub _build_dbh { } } - # connect using our known info to the specified db - my $dbh = DBI->connect($dsn, $user, $pass, $attributes) - or die "\nCan't connect to the database.\nError: $DBI::errstr\n" - . " Is your database installed and up and running?\n Do you have" - . " the correct username and password selected in localconfig?\n\n"; + my $connector = $Connector{"$user.$dsn"} //= DBIx::Connector->new($dsn, $user, $pass, $attributes); - # RaiseError was only set to 0 so that we could catch the - # above "die" condition. - $dbh->{RaiseError} = 1; - - return $dbh; + return $connector->dbh; } ##################################################################### diff --git a/Bugzilla/ModPerl.pm b/Bugzilla/ModPerl.pm index 89eca9585..19cd1128f 100644 --- a/Bugzilla/ModPerl.pm +++ b/Bugzilla/ModPerl.pm @@ -74,7 +74,7 @@ __DATA__ # every process, and Perl has another. (Various Perl modules still use # the built-in rand(), even though we never use it in Bugzilla itself, # so we need to srand() both of them.) -PerlChildInitHandler "sub { Bugzilla::RNG::srand(); srand(); }" +PerlChildInitHandler "sub { Bugzilla::RNG::srand(); srand(); eval { Bugzilla->dbh->ping } }" PerlInitHandler Bugzilla::ModPerl::Hostage PerlAccessHandler Bugzilla::ModPerl::BlockIP -- cgit v1.2.3-24-g4f1b