From: Max Kanat-Alexander Date: Fri, 2 Apr 2010 21:01:39 +0000 (-0700) Subject: Bug 556869: New Hook: object_before_delete X-Git-Tag: bugzilla-3.6~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=099bd16f8a83f2e1b0501551119c0e3b51c383c7;p=thirdparty%2Fbugzilla.git Bug 556869: New Hook: object_before_delete r=mkanat, a=mkanat (module owner) --- diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 9917c68e84..0406e5cecd 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -630,6 +630,25 @@ A hashref. The set of named parameters passed to C. =back + +=head2 object_before_delete + +This happens in L, after we've confirmed +that the object can be deleted, but before any rows have actually +been removed from the database. This sometimes occurs inside a database +transaction. + +Params: + +=over + +=item C - The L being deleted. You will probably +want to check its type like C<< $object->isa('Some::Class') >> before doing +anything with it. + +=back + + =head2 object_before_set Called during L, before any actual work is done. diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index 3d92b19a76..32262dd2a4 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -376,6 +376,7 @@ sub update { sub remove_from_db { my $self = shift; + Bugzilla::Hook::process('object_before_delete', { object => $self }); my $table = $self->DB_TABLE; my $id_field = $self->ID_FIELD; Bugzilla->dbh->do("DELETE FROM $table WHERE $id_field = ?", diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm index 0c795f8089..d8e4228c05 100644 --- a/extensions/Example/Extension.pm +++ b/extensions/Example/Extension.pm @@ -335,6 +335,18 @@ sub object_before_create { } } +sub object_before_delete { + my ($self, $args) = @_; + + my $object = $args->{'object'}; + + # Note that this is a made-up class, for this example. + if ($object->isa('Bugzilla::ExampleObject')) { + my $id = $object->id; + warn "An object with id $id is about to be deleted!"; + } +} + sub object_before_set { my ($self, $args) = @_;