summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-04-02 23:00:18 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-04-02 23:00:18 +0200
commita9a869f8e20ecfbeafeb8020ad4c1e86b60aa21a (patch)
tree4a0a763f1289cbcce3075505b5f012bb3527b7c2
parent07f947c99e162dc991f368cd5ff9065824c4ec86 (diff)
downloadbugzilla-a9a869f8e20ecfbeafeb8020ad4c1e86b60aa21a.tar.gz
bugzilla-a9a869f8e20ecfbeafeb8020ad4c1e86b60aa21a.tar.xz
Bug 556869: New Hook: object_before_delete
r=mkanat, a=mkanat (module owner)
-rw-r--r--Bugzilla/Hook.pm19
-rw-r--r--Bugzilla/Object.pm1
-rw-r--r--extensions/Example/Extension.pm12
3 files changed, 32 insertions, 0 deletions
diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm
index b8d763d20..7f85e70d8 100644
--- a/Bugzilla/Hook.pm
+++ b/Bugzilla/Hook.pm
@@ -704,6 +704,25 @@ A hashref. The set of named parameters passed to C<create>.
=back
+
+=head2 object_before_delete
+
+This happens in L<Bugzilla::Object/remove_from_db>, 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<object> - The L<Bugzilla::Object> 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<Bugzilla::Object/set>, before any actual work is done.
diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm
index e50be1fbf..2477244df 100644
--- a/Bugzilla/Object.pm
+++ b/Bugzilla/Object.pm
@@ -383,6 +383,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 835d36f80..26a91b789 100644
--- a/extensions/Example/Extension.pm
+++ b/extensions/Example/Extension.pm
@@ -354,6 +354,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) = @_;