]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 556695: New Hook: object_end_of_set
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Fri, 2 Apr 2010 05:43:34 +0000 (22:43 -0700)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Fri, 2 Apr 2010 05:43:34 +0000 (22:43 -0700)
r=mkanat, a=mkanat (module owner)

Bugzilla/Hook.pm
Bugzilla/Object.pm
extensions/Example/Extension.pm

index 4ba1bae625e662488d4ee265a5a4b8d6ad90089f..a3a1752238f8f0045efbfdd364e48c7cb2ab63df 100644 (file)
@@ -672,6 +672,34 @@ validated by the C<VALIDATORS> specified for the object.
 
 =back
 
+
+=head2 object_end_of_set
+
+Called during L<Bugzilla::Object/set>, 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<object>
+
+The object that C<set> 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<field>
+
+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<Bugzilla::Object/set_all>. This is a
index 27098806e5509742302082ce8ba10856e69000e4..3d92b19a7618504467f54dc5d51eb127652904d1 100644 (file)
@@ -305,6 +305,9 @@ sub set {
     }
 
     $self->{$field} = $value;
+
+    Bugzilla::Hook::process('object_end_of_set',
+                            { object => $self, field => $field });
 }
 
 sub set_all {
index 8ce2ece6acc09c4b7eeed8641f43a158da6693bc..9de0a65bf44e43c6f3d8f831ead8097029560ecd 100644 (file)
@@ -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) = @_;