summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Object.pm
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-02-11 01:46:59 +0100
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-02-11 01:46:59 +0100
commitaca53c540c69496390b172a55a46b817d2828d0f (patch)
tree6d300d90bfb2ac744b192a074428e8ef0b81e1e6 /Bugzilla/Object.pm
parentd4f7ab1e416445c9a56a9da93eddc536099d22c2 (diff)
downloadbugzilla-aca53c540c69496390b172a55a46b817d2828d0f.tar.gz
bugzilla-aca53c540c69496390b172a55a46b817d2828d0f.tar.xz
Bug 545541: New Hook: object_columns
r=mkanat, a=mkanat (module owner)
Diffstat (limited to 'Bugzilla/Object.pm')
-rw-r--r--Bugzilla/Object.pm43
1 files changed, 35 insertions, 8 deletions
diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm
index bf8d69d5a..e7763157a 100644
--- a/Bugzilla/Object.pm
+++ b/Bugzilla/Object.pm
@@ -59,7 +59,7 @@ sub _init {
my $class = shift;
my ($param) = @_;
my $dbh = Bugzilla->dbh;
- my $columns = join(',', $class->DB_COLUMNS);
+ my $columns = join(',', $class->_get_db_columns);
my $table = $class->DB_TABLE;
my $name_field = $class->NAME_FIELD;
my $id_field = $class->ID_FIELD;
@@ -241,7 +241,7 @@ sub match {
sub _do_list_select {
my ($class, $where, $values, $postamble) = @_;
my $table = $class->DB_TABLE;
- my $cols = join(',', $class->DB_COLUMNS);
+ my $cols = join(',', $class->_get_db_columns);
my $order = $class->LIST_ORDER;
my $sql = "SELECT $cols FROM $table";
@@ -487,12 +487,33 @@ sub get_all {
sub check_boolean { return $_[1] ? 1 : 0 }
-# For some classes, VALIDATORS takes time to generate, so we cache it. Also,
-# this allows the object_validators hook to only run once per request,
-# instead of every time we call set() on a class of objects.
-#
-# This method is intentionally private and should only be called by
-# Bugzilla::Object.
+####################
+# Constant Helpers #
+####################
+
+# For some classes, some constants take time to generate, so we cache them
+# and only access them through the below methods. This also allows certain
+# hooks to only run once per request instead of multiple times on each
+# page.
+
+sub _get_db_columns {
+ my $invocant = shift;
+ my $class = ref($invocant) || $invocant;
+ 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);
+ $cache->{$cache_key} = \@columns;
+ return @{ $cache->{$cache_key} };
+}
+
+# This method is private and should only be called by Bugzilla::Object.
sub _get_validators {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
@@ -554,6 +575,12 @@ for C<Bugzilla::Keyword> this would be C<keyworddefs>.
The names of the columns that you want to read out of the database
and into this object. This should be an array.
+I<Note>: Though normally you will never need to access this constant's data
+directly in your subclass, if you do, you should access it by calling the
+C<_get_db_columns> method instead of accessing the constant directly. (The
+only exception to this rule is calling C<SUPER::DB_COLUMNS> from within
+your own C<DB_COLUMNS> subroutine in a subclass.)
+
=item C<NAME_FIELD>
The name of the column that should be considered to be the unique