summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-06-21 16:28:53 +0200
committerGitHub <noreply@github.com>2018-06-21 16:28:53 +0200
commit454a5dcf66f9b3eafb61badc6ce61c8ebe52dd96 (patch)
treef376f31bbd2da14bbbbdd2f221aa5da01bf1af38 /Bugzilla/DB.pm
parent52100a9f4f2e5b5d3249934143fb9a7097f156f9 (diff)
downloadbugzilla-454a5dcf66f9b3eafb61badc6ce61c8ebe52dd96.tar.gz
bugzilla-454a5dcf66f9b3eafb61badc6ce61c8ebe52dd96.tar.xz
Bug 1461379 - refactor Bugzilla::DB to not subclass DBI
Diffstat (limited to 'Bugzilla/DB.pm')
-rw-r--r--Bugzilla/DB.pm49
1 files changed, 29 insertions, 20 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index 0dfa47c23..893c9235e 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -8,13 +8,20 @@
package Bugzilla::DB;
use 5.10.1;
-use strict;
-use warnings;
+use Moo;
use DBI;
-# Inherit the DB class from DBI::db.
-use base qw(DBI::db);
+has 'dbh' => (
+ is => 'lazy',
+ handles => [
+ qw[
+ begin_work column_info commit disconnect do errstr get_info last_insert_id ping prepare
+ primary_key quote_identifier rollback selectall_arrayref selectall_hashref
+ selectcol_arrayref selectrow_array selectrow_arrayref selectrow_hashref table_info
+ ]
+ ],
+);
use Bugzilla::Constants;
use Bugzilla::Install::Requirements;
@@ -27,11 +34,14 @@ use Bugzilla::Error;
use Bugzilla::DB::Schema;
use Bugzilla::Version;
-use Bugzilla::Metrics::Mysql;
-
use List::Util qw(max);
use Storable qw(dclone);
+has [qw(dsn user pass attrs)] => (
+ is => 'ro',
+ required => 1,
+);
+
#####################################################################
# Constants
#####################################################################
@@ -91,7 +101,7 @@ use constant INDEX_DROPS_REQUIRE_FK_DROPS => 1;
sub quote {
my $self = shift;
- my $retval = $self->SUPER::quote(@_);
+ my $retval = $self->dbh->quote(@_);
trick_taint($retval) if defined $retval;
return $retval;
}
@@ -140,11 +150,6 @@ sub _connect {
# instantiate the correct DB specific module
- # BMO - enable instrumentation of db calls
- if (Bugzilla->metrics_enabled) {
- $pkg_module = 'Bugzilla::Metrics::Mysql';
- }
-
my $dbh = $pkg_module->new($params);
return $dbh;
@@ -1249,10 +1254,10 @@ sub bz_rollback_transaction {
# Subclass Helpers
#####################################################################
-sub db_new {
- my ($class, $params) = @_;
+sub _build_dbh {
+ my ($self) = @_;
my ($dsn, $user, $pass, $override_attrs) =
- @$params{qw(dsn user pass attrs)};
+ map { $self->$_ } qw(dsn user pass attrs);
# set up default attributes used to connect to the database
# (may be overridden by DB driver implementations)
@@ -1274,20 +1279,24 @@ sub db_new {
$attributes->{$key} = $override_attrs->{$key};
}
}
+ my $class = ref $self;
+ if ($class->can('on_dbi_connected')) {
+ $attributes->{Callbacks} = {
+ connected => sub { $class->on_dbi_connected(@_); return },
+ }
+ }
# connect using our known info to the specified db
- my $self = DBI->connect($dsn, $user, $pass, $attributes)
+ 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";
# RaiseError was only set to 0 so that we could catch the
# above "die" condition.
- $self->{RaiseError} = 1;
+ $dbh->{RaiseError} = 1;
- bless ($self, $class);
-
- return $self;
+ return $dbh;
}
#####################################################################