From: Christian Legnitto Date: Wed, 1 Sep 2010 22:57:56 +0000 (-0700) Subject: Bug 587793: Add a new "object_end_of_create" hook so that extensions can X-Git-Tag: bugzilla-3.6.3~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e09b4ae9df06fe549da8a4a1aa7d0a73f627f7e;p=thirdparty%2Fbugzilla.git Bug 587793: Add a new "object_end_of_create" hook so that extensions can operate on any new objects r=mkanat, a=mkanat --- diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index ad9eb01756..4ec6b3e4a2 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -208,8 +208,7 @@ Params: =over -=item C - The changed bug object, with all fields set to their updated -values. +=item C - The created bug object. =item C - The timestamp used for all updates in this transaction, as a SQL date string. @@ -683,6 +682,27 @@ The value being set on the object. =back +=head2 object_end_of_create + +Called at the end of L, after all other changes are +made to the database. This occurs inside a database transaction. + +Params: + +=over + +=item C + +The name of the class that C was called on. You can check this +like C<< if ($class->isa('Some::Class')) >> in your code, to perform specific +tasks for only certain classes. + +=item C + +The created object. + +=back + =head2 object_end_of_create_validators Called at the end of L. You can diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index b1be766352..71ced8e9d2 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -487,7 +487,12 @@ sub insert_create_data { $dbh->do("INSERT INTO $table (" . join(', ', @field_names) . ") VALUES ($qmarks)", undef, @values); my $id = $dbh->bz_last_key($table, $class->ID_FIELD); - return $class->new($id); + + my $object = $class->new($id); + + Bugzilla::Hook::process('object_end_of_create', { class => $class, + object => $object }); + return $object; } sub get_all { diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm index d8e4228c05..60096692e7 100644 --- a/extensions/Example/Extension.pm +++ b/extensions/Example/Extension.pm @@ -359,6 +359,15 @@ sub object_before_set { } } +sub object_end_of_create { + my ($self, $args) = @_; + + my $class = $args->{'class'}; + my $object = $args->{'object'}; + + warn "Created a new $class object!"; +} + sub object_end_of_create_validators { my ($self, $args) = @_;