From 2f310307750a7d70da1bb4f3077c7a7fa616e2eb Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Tue, 18 Dec 2012 15:32:31 -0500 Subject: Bug 813628 - New extension hook for Bugzilla::Bug::update called bug_start_of_update --- Bugzilla/Hook.pm | 33 +++++++++++++++++++++++++++++++++ extensions/Example/Extension.pm | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 27d70e7f5..a18b11f77 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -434,6 +434,39 @@ to the user. =back +=head2 bug_start_of_update + +This happens near the beginning of L, after L +is called, but before all other special changes are made to the database. Once use case is +this allows for adding your own entries to the C hash which gets added to the +bugs_activity table later keeping you from having to do it yourself. Also this is also helpful +if your extension needs to add CC members, flags, keywords, groups, etc. This generally +occurs inside a database transaction. + +Params: + +=over + +=item C + +The changed bug object, with all fields set to their updated values. + +=item C + +A bug object pulled from the database before the fields were set to +their updated values (so it has the old values available for each field). + +=item C + +The timestamp used for all updates in this transaction, as a SQL date +string. + +=item C + +The hash of changed fields. C<< $changes->{field} = [old, new] >> + +=back + =head2 buglist_columns This happens in L, which determines legal bug diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm index d7b892cfa..3208d701a 100644 --- a/extensions/Example/Extension.pm +++ b/extensions/Example/Extension.pm @@ -168,6 +168,42 @@ sub bug_end_of_create_validators { # $bug_params->{cc} = []; } +sub bug_start_of_update { + my ($self, $args) = @_; + + # This code doesn't actually *do* anything, it's just here to show you + # how to use this hook. + my ($bug, $old_bug, $timestamp, $changes) = + @$args{qw(bug old_bug timestamp changes)}; + + foreach my $field (keys %$changes) { + my $used_to_be = $changes->{$field}->[0]; + my $now_it_is = $changes->{$field}->[1]; + } + + my $old_summary = $old_bug->short_desc; + + my $status_message; + if (my $status_change = $changes->{'bug_status'}) { + my $old_status = new Bugzilla::Status({ name => $status_change->[0] }); + my $new_status = new Bugzilla::Status({ name => $status_change->[1] }); + if ($new_status->is_open && !$old_status->is_open) { + $status_message = "Bug re-opened!"; + } + if (!$new_status->is_open && $old_status->is_open) { + $status_message = "Bug closed!"; + } + } + + my $bug_id = $bug->id; + my $num_changes = scalar keys %$changes; + my $result = "There were $num_changes changes to fields on bug $bug_id" + . " at $timestamp."; + # Uncomment this line to see $result in your webserver's error log whenever + # you update a bug. + # warn $result; +} + sub bug_end_of_update { my ($self, $args) = @_; -- cgit v1.2.3-24-g4f1b