Commit 0310c0cb authored by Dylan William Hardison's avatar Dylan William Hardison Committed by Давид Добряков

[Bug 1592129] remove subclass loading and driver delegation from Schema->new.

Bugzilla::DB::Schema->new() was both a normal constructor and also a class-loading factory method. It is simpler to just do the class loading at the call-site (in Bugzilla::DB::_bz_schema). It's not very likely extensions relied on this behavior so this should be a good change.
parent 199611d4
......@@ -26,6 +26,7 @@ use Bugzilla::Error;
use Bugzilla::DB::Schema;
use Bugzilla::Version;
use Scalar::Util qw(blessed);
use List::Util qw(max);
use Storable qw(dclone);
......@@ -1155,12 +1156,21 @@ sub bz_set_next_serial_value {
# Schema Information Methods
#####################################################################
sub _bz_schema_class {
my ($self) = @_;
my $class = blessed($self) // $self;
my @class_parts = split(/::/, $class);
splice(@class_parts, -1, 0, 'Schema');
return join('::', @class_parts);
}
sub _bz_schema {
my ($self) = @_;
return $self->{private_bz_schema} if exists $self->{private_bz_schema};
my @module_parts = split('::', ref $self);
my $module_name = pop @module_parts;
$self->{private_bz_schema} = Bugzilla::DB::Schema->new($module_name);
my $schema_class = $self->_bz_schema_class;
eval "require $schema_class";
$self->{private_bz_schema} = $schema_class->new();
return $self->{private_bz_schema};
}
......
......@@ -1758,13 +1758,8 @@ sub new {
=item C<new>
Description: Public constructor method used to instantiate objects of this
class. However, it also can be used as a factory method to
instantiate database-specific subclasses when an optional
driver argument is supplied.
Parameters: $driver (optional) - Used to specify the type of database.
This routine C<die>s if no subclass is found for the specified
driver.
$schema (optional) - A reference to a hash. Callers external
class.
Parameters: $schema (optional) - A reference to a hash. Callers external
to this package should never use this parameter.
Returns: new instance of the Schema class or a database-specific subclass
......@@ -1772,15 +1767,7 @@ sub new {
my $this = shift;
my $class = ref($this) || $this;
my $driver = shift;
if ($driver) {
(my $subclass = $driver) =~ s/^(\S)/\U$1/;
$class .= '::' . $subclass;
eval "require $class;";
die "The $class class could not be found ($subclass " . "not supported?): $@"
if ($@);
}
die "$class is an abstract base class. Instantiate a subclass instead."
if ($class eq __PACKAGE__);
......@@ -2983,7 +2970,7 @@ sub deserialize_abstract {
}
}
return $class->new(undef, $thawed_hash);
return $class->new($thawed_hash);
}
#####################################################################
......
......@@ -19,6 +19,7 @@ use warnings;
use lib qw(. t lib);
use Bugzilla;
use Bugzilla::DB::Schema;
use Bugzilla::DB::Schema::Mysql;
# SQL reserved words
......@@ -57,7 +58,7 @@ our $schema;
our @tables;
BEGIN {
$schema = Bugzilla::DB::Schema->new("Mysql");
$schema = Bugzilla::DB::Schema::Mysql->new;
@tables = $schema->get_table_list();
}
......
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