From: mkanat%bugzilla.org <> Date: Sat, 26 May 2007 01:19:05 +0000 (+0000) Subject: Bug 381640: abstract_schema hook is broken--it prevents modification of the extension... X-Git-Tag: bugzilla-3.0.1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c922389b32c555842ff8e81fcafc62df771dbb8a;p=thirdparty%2Fbugzilla.git Bug 381640: abstract_schema hook is broken--it prevents modification of the extension's own tables Patch By Max Kanat-Alexander r=LpSolit, a=mkanat --- diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index ff81d9c626..f4c1c30439 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -1211,22 +1211,26 @@ sub _initialize { my $self = shift; my $abstract_schema = shift; - $abstract_schema ||= ABSTRACT_SCHEMA; - - # Let extensions add tables, but make sure they can't modify existing - # tables. If we don't lock/unlock keys, lock_value complains. - lock_keys(%$abstract_schema); - lock_value(%$abstract_schema, $_) foreach (keys %$abstract_schema); - unlock_keys(%$abstract_schema); - Bugzilla::Hook::process('db_schema-abstract_schema', - { schema => $abstract_schema }); - unlock_hash(%$abstract_schema); + if (!$abstract_schema) { + # While ABSTRACT_SCHEMA cannot be modified, $abstract_schema can be. + # So, we dclone it to prevent anything from mucking with the constant. + $abstract_schema = dclone(ABSTRACT_SCHEMA); + + # Let extensions add tables, but make sure they can't modify existing + # tables. If we don't lock/unlock keys, lock_value complains. + lock_keys(%$abstract_schema); + foreach my $table (keys %{ABSTRACT_SCHEMA()}) { + lock_value(%$abstract_schema, $table) + if exists $abstract_schema->{$table}; + } + unlock_keys(%$abstract_schema); + Bugzilla::Hook::process('db_schema-abstract_schema', + { schema => $abstract_schema }); + unlock_hash(%$abstract_schema); + } $self->{schema} = dclone($abstract_schema); - # While ABSTRACT_SCHEMA cannot be modified, - # $self->{abstract_schema} can be. So, we dclone it to prevent - # anything from mucking with the constant. - $self->{abstract_schema} = dclone($abstract_schema); + $self->{abstract_schema} = $abstract_schema; return $self;