]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
[Bug 1592129] Pass a reference to db into Schema object
authorDylan William Hardison <dylan@hardison.net>
Sat, 1 Feb 2020 15:41:19 +0000 (16:41 +0100)
committerGitHub <noreply@github.com>
Sat, 1 Feb 2020 15:41:19 +0000 (16:41 +0100)
This change adds a 'db' attribute to the `Bugzilla::DB::Schema` class.
In two places (`get_empty_schema` and `deserialize_abstract`) the invocant
argument was called `$class` but was never actually a class. Those were renamed
to `$self`. It was fortunate that they were always objects because otherwise it
would have been more difficult to ensure a `db` is always present.

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

index c1f7461716cb5bdec8001d3f80cac32dda9e3fc6..cbef41447cebd4a7b688364e10ee258c8bd2fdc3 100644 (file)
@@ -1180,7 +1180,7 @@ sub _bz_schema {
   return $self->{private_bz_schema} if exists $self->{private_bz_schema};
   my $schema_class = $self->_bz_schema_class;
   eval "require $schema_class";
-  $self->{private_bz_schema} = $schema_class->new();
+  $self->{private_bz_schema} = $schema_class->new(db => $self);
   return $self->{private_bz_schema};
 }
 
index 053ec389af505d98a8441c21fbec54699c78a6d4..928e92ac72494b62d0b11e179a16519fe366255c 100644 (file)
@@ -1773,6 +1773,8 @@ has 'schema' => (init_arg =>undef, is => 'rw');
 
 has 'db_specific' => (init_arg => undef, is => 'rw');
 
+has 'db' => (is => 'ro', weak_ref => 1, required => 1);
+
 
 #--------------------------------------------------------------------------
 sub _initialize {
@@ -2933,7 +2935,7 @@ sub serialize_abstract {
 =cut
 
 sub deserialize_abstract {
-  my ($class, $serialized, $version) = @_;
+  my ($self, $serialized, $version) = @_;
 
   my $thawed_hash;
   if ($version < 2) {
@@ -2947,7 +2949,7 @@ sub deserialize_abstract {
 
   # Version 2 didn't have the "created" key for REFERENCES items.
   if ($version < 3) {
-    my $standard = $class->new()->{abstract_schema};
+    my $standard = $self->new(db => $self->db)->{abstract_schema};
     foreach my $table_name (keys %$thawed_hash) {
       my %standard_fields = @{$standard->{$table_name}->{FIELDS} || []};
       my $table           = $thawed_hash->{$table_name};
@@ -2960,7 +2962,7 @@ sub deserialize_abstract {
     }
   }
 
-  return $class->new(_abstract_schema => $thawed_hash);
+  return $self->new(db => $self->db, _abstract_schema => $thawed_hash);
 }
 
 #####################################################################
@@ -2988,8 +2990,8 @@ object.
 =cut
 
 sub get_empty_schema {
-  my ($class) = @_;
-  return $class->deserialize_abstract(Dumper({}), SCHEMA_VERSION);
+  my ($self) = @_;
+  return $self->deserialize_abstract(Dumper({}), SCHEMA_VERSION);
 }
 
 1;
index c2d827e4d322f3f2daab4827c3d2d3287e0b58d8..a1a4aceb273e7a0c73014f1588574bab709b0094 100644 (file)
@@ -58,7 +58,8 @@ our $schema;
 our @tables;
 
 BEGIN {
-  $schema = Bugzilla::DB::Schema::Mysql->new;
+  our $fake_db = bless {}, 'Bugzilla::DB';
+  $schema = Bugzilla::DB::Schema::Mysql->new(db => $fake_db);
   @tables = $schema->get_table_list();
 }