summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-04-02 07:42:42 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-04-02 07:42:42 +0200
commit2a444f9d50535445a84367a9833bd87a07752d0a (patch)
tree15d89acf5beac987d45b39f4f1ae7010062cc6c6
parent11e17befd5f484859eea97b5bf831d220ce2b2a8 (diff)
downloadbugzilla-2a444f9d50535445a84367a9833bd87a07752d0a.tar.gz
bugzilla-2a444f9d50535445a84367a9833bd87a07752d0a.tar.xz
Bug 556695: New Hook: object_end_of_set
r=mkanat, a=mkanat (module owner)
-rw-r--r--Bugzilla/Hook.pm28
-rw-r--r--Bugzilla/Object.pm3
-rw-r--r--extensions/Example/Extension.pm11
3 files changed, 42 insertions, 0 deletions
diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm
index af73814ce..556fda894 100644
--- a/Bugzilla/Hook.pm
+++ b/Bugzilla/Hook.pm
@@ -784,6 +784,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
diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm
index a54cf7caa..e50be1fbf 100644
--- a/Bugzilla/Object.pm
+++ b/Bugzilla/Object.pm
@@ -306,6 +306,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 398ddbd56..52ac66231 100644
--- a/extensions/Example/Extension.pm
+++ b/extensions/Example/Extension.pm
@@ -386,6 +386,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) = @_;