From: Max Kanat-Alexander Date: Fri, 2 Apr 2010 05:43:34 +0000 (-0700) Subject: Bug 556695: New Hook: object_end_of_set X-Git-Tag: bugzilla-3.6~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40e3faeedf5277b74573acb58343884dc456d5b6;p=thirdparty%2Fbugzilla.git Bug 556695: New Hook: object_end_of_set r=mkanat, a=mkanat (module owner) --- diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 4ba1bae625..a3a1752238 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -672,6 +672,34 @@ validated by the C specified for the object. =back + +=head2 object_end_of_set + +Called during L, after all the code of the function +has completed (so the value has been validated and the field has been set +to the new value). You can use this to perform actions after a value is +changed for specific fields on certain types of objects. + +The new value is not specifically passed to this hook because you can +get it as C<< $object->{$field} >>. + +Params: + +=over + +=item C + +The object that C was called on. You will probably want to +do something like C<< if ($object->isa('Some::Class')) >> in your code to +limit your changes to only certain subclasses of Bugzilla::Object. + +=item C + +The name of the field that was updated in the object. + +=back + + =head2 object_end_of_set_all This happens at the end of L. This is a diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index 27098806e5..3d92b19a76 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -305,6 +305,9 @@ sub set { } $self->{$field} = $value; + + Bugzilla::Hook::process('object_end_of_set', + { object => $self, field => $field }); } sub set_all { diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm index 8ce2ece6ac..9de0a65bf4 100644 --- a/extensions/Example/Extension.pm +++ b/extensions/Example/Extension.pm @@ -358,6 +358,17 @@ sub object_end_of_create_validators { } +sub object_end_of_set { + my ($self, $args) = @_; + + my ($object, $field) = @$args{qw(object field)}; + + # Note that this is a made-up class, for this example. + if ($object->isa('Bugzilla::ExampleObject')) { + warn "The field $field has changed to " . $object->{$field}; + } +} + sub object_end_of_set_all { my ($self, $args) = @_;