summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Object.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-06-25 23:28:13 +0200
committerGitHub <noreply@github.com>2018-06-25 23:28:13 +0200
commit7094db8e78304f4f76d48ba230f07fab5c9d0daf (patch)
treee9a0466731955c2b74e1ac1d1743e86e264b1b74 /Bugzilla/Object.pm
parente83b95790d29393e9711aedeccfd63353bbc3cde (diff)
downloadbugzilla-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.
Diffstat (limited to 'Bugzilla/Object.pm')
-rw-r--r--Bugzilla/Object.pm23
1 files changed, 16 insertions, 7 deletions
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} };
}