diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-06-25 23:28:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-25 23:28:13 +0200 |
commit | 7094db8e78304f4f76d48ba230f07fab5c9d0daf (patch) | |
tree | e9a0466731955c2b74e1ac1d1743e86e264b1b74 | |
parent | e83b95790d29393e9711aedeccfd63353bbc3cde (diff) | |
download | bugzilla-7094db8e78304f4f76d48ba230f07fab5c9d0daf.tar.gz bugzilla-7094db8e78304f4f76d48ba230f07fab5c9d0daf.tar.xz |
Bug 1471044 - Allow some model classes to have dynamic column names with class method DYNAMIC_COLUMNS
When working on bug 1253535 I kept encountering the fragility of our model system.
This fragility involves two things:
1) Extensions adding new columns to model objects
2) The use of those model objects in checksetup.
In particular, the SecureMail extension causes this problem because (at checksetup-time) we need to lookup certain Group objects.
Thus I propose to
1) allow model classes to take their list of columns from the informations schema (exposed via `bz_table_columns_real`)
2) Have Bugzilla::Group do this when being used in a commandline (e.g. checksetup) context.
-rw-r--r-- | Bugzilla/Group.pm | 5 | ||||
-rw-r--r-- | Bugzilla/Object.pm | 23 |
2 files changed, 21 insertions, 7 deletions
diff --git a/Bugzilla/Group.pm b/Bugzilla/Group.pm index fe2a90c05..c941482f0 100644 --- a/Bugzilla/Group.pm +++ b/Bugzilla/Group.pm @@ -67,6 +67,11 @@ use constant UPDATE_COLUMNS => qw( use constant GROUP_PARAMS => qw(chartgroup insidergroup timetrackinggroup querysharegroup); + +sub DYNAMIC_COLUMNS { + return Bugzilla->usage_mode == USAGE_MODE_CMDLINE; +} + ############################### #### Accessors ###### ############################### diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index 00afbe19f..eaafca219 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -44,6 +44,9 @@ use constant USE_MEMCACHED => 1; # values, keywords, products, classifications, priorities, severities, etc. use constant IS_CONFIG => 0; +# When DYNAMIC_COLUMNS is true, _get_db_columns() will use the information schema. +use constant DYNAMIC_COLUMNS => 0; + # This allows the JSON-RPC interface to return Bugzilla::Object instances # as though they were hashes. In the future, this may be modified to return # less information. @@ -888,13 +891,19 @@ sub _get_db_columns { my $cache = Bugzilla->request_cache; my $cache_key = "object_${class}_db_columns"; return @{ $cache->{$cache_key} } if $cache->{$cache_key}; - # Currently you can only add new columns using object_columns, not - # remove or modify existing columns, because removing columns would - # almost certainly cause Bugzilla to function improperly. - my @add_columns; - Bugzilla::Hook::process('object_columns', - { class => $class, columns => \@add_columns }); - my @columns = ($invocant->DB_COLUMNS, @add_columns); + my @columns; + if ($class->DYNAMIC_COLUMNS) { + @columns = Bugzilla->dbh->bz_table_columns_real($class->DB_TABLE); + } + else { + # Currently you can only add new columns using object_columns, not + # remove or modify existing columns, because removing columns would + # almost certainly cause Bugzilla to function improperly. + my @add_columns; + Bugzilla::Hook::process('object_columns', + { class => $class, columns => \@add_columns }); + @columns = ($invocant->DB_COLUMNS, @add_columns); + } $cache->{$cache_key} = \@columns; return @{ $cache->{$cache_key} }; } |