]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1471044 - Allow some model classes to have dynamic column names with class metho...
authorDylan William Hardison <dylan@hardison.net>
Mon, 25 Jun 2018 21:28:13 +0000 (17:28 -0400)
committerGitHub <noreply@github.com>
Mon, 25 Jun 2018 21:28:13 +0000 (17:28 -0400)
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.

Bugzilla/Group.pm
Bugzilla/Object.pm

index fe2a90c05a3172b936fc189183eca62014151f39..c941482f01fa488debc2d4a2db4ad4f83f07e2e4 100644 (file)
@@ -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      ######
 ###############################
index 00afbe19f8883a3c4ee1bfb82988d3194a4e9bfe..eaafca21915d7864cbaa272e7544d873912bee39 100644 (file)
@@ -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} };
 }