]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
remove subclass loading and driver delegation from Schema->new.
authorDylan William Hardison <dylan@hardison.net>
Sun, 15 Dec 2019 17:13:34 +0000 (12:13 -0500)
committerDylan William Hardison <dylan@hardison.net>
Sun, 15 Dec 2019 17:13:34 +0000 (12:13 -0500)
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.

Bugzilla/DB.pm
Bugzilla/DB/Schema.pm
t/013dbschema.t

index 0fa9bf50386c2333ccf191f6e1985553eb1db731..7262cf888c59dd330bc4f433ce4add8ebb88e2b8 100644 (file)
@@ -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};
 }
 
index 2ab8a983a3a10dfc4ab6aeea011231b3a7838b8e..23d2cf0625eb38f11e1e910bf63a06e80877a0f1 100644 (file)
@@ -1758,9 +1758,7 @@ 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.
+              class.
  Parameters:  $driver (optional) - Used to specify the type of database.
               This routine C<die>s if no subclass is found for the specified
               driver.
@@ -1772,15 +1770,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 +2973,7 @@ sub deserialize_abstract {
     }
   }
 
-  return $class->new(undef, $thawed_hash);
+  return $class->new($thawed_hash);
 }
 
 #####################################################################
index 062a22992e7b56537d51067c5546b70ea056fadd..c2d827e4d322f3f2daab4827c3d2d3287e0b58d8 100644 (file)
@@ -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();
 }