]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 556869: New Hook: object_before_delete
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Fri, 2 Apr 2010 21:01:39 +0000 (14:01 -0700)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Fri, 2 Apr 2010 21:01:39 +0000 (14:01 -0700)
r=mkanat, a=mkanat (module owner)

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

index 9917c68e843ec2432e2264cc565342ccf6cc25d7..0406e5cecd4a3990352d77103a71146fe85638d9 100644 (file)
@@ -630,6 +630,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.
index 3d92b19a7618504467f54dc5d51eb127652904d1..32262dd2a40cea7dd333cf38bd78eb0e61490169 100644 (file)
@@ -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 = ?",
index 0c795f80895a6c054b03425bce4d5031d4e242ad..d8e4228c05f5e6b76764f1636f434e9b81be597b 100644 (file)
@@ -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) = @_;