From 6b4e9edae6b5accf757097a5e7af97c2fba8f0ff Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Wed, 10 Feb 2010 17:39:05 -0800 Subject: Bug 545551: Hook: object_update_columns r=mkanat, a=mkanat (module owner) --- Bugzilla/Hook.pm | 29 +++++++++++++++++++++++++++++ Bugzilla/Object.pm | 10 ++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 2f4d2a7ff..1f92f332d 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -715,6 +715,35 @@ L returns. =back +=head2 object_update_columns + +If you've added fields to bugs via L, then this +hook allows you to say which of those columns should be updated in the +database when L is called on the object. + +If you don't use this hook, then your custom columns won't be modified in +the database by Bugzilla. + +Params: + +=over + +=item C + +The object that is about to be updated. You should check this +like C<< if ($object->isa('Some::Class')) >> in your code, to modify +the "update columns" only for certain classes. + +=item C + +An arrayref. Add the string names of columns to this array to allow +that column to be updated when C is called on the object. + +This arrayref does not contain the standard column names--you cannot stop +standard columns from being updated by using this hook. + +=back + =head2 object_validators Allows you to add new items to L for diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index e7763157a..dac8962ff 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -322,11 +322,17 @@ sub update { $dbh->bz_start_transaction(); my $old_self = $self->new($self->id); - + + my @all_columns = $self->UPDATE_COLUMNS; + my @hook_columns; + Bugzilla::Hook::process('object_update_columns', + { object => $self, columns => \@hook_columns }); + push(@all_columns, @hook_columns); + my %numeric = map { $_ => 1 } $self->NUMERIC_COLUMNS; my %date = map { $_ => 1 } $self->DATE_COLUMNS; my (@update_columns, @values, %changes); - foreach my $column ($self->UPDATE_COLUMNS) { + foreach my $column (@all_columns) { my ($old, $new) = ($old_self->{$column}, $self->{$column}); # This has to be written this way in order to allow us to set a field # from undef or to undef, and avoid warnings about comparing an undef -- cgit v1.2.1