# Get the activity of a bug, starting from $starttime (if given).
# This routine assumes Bugzilla::Bug->check has been previously called.
sub GetBugActivity {
- my ($bug_id, $attach_id, $starttime, $include_comment_tags) = @_;
+ my ($bug_id, $attach_id, $starttime, $include_comment_activity) = @_;
my $dbh = Bugzilla->dbh;
# Arguments passed to the SQL query.
= "SELECT DISTINCT fielddefs.name,
bugs_activity.id AS activity_id,
bugs_activity.attach_id, "
- . $dbh->sql_date_format('bugs_activity.bug_when', '%Y.%m.%d %H:%i:%s')
+ . $dbh->sql_date_format('bugs_activity.bug_when', '%Y-%m-%d %H:%i:%s')
. " AS bug_when, bugs_activity.removed, bugs_activity.added, profiles.login_name,
bugs_activity.comment_id
FROM bugs_activity
$suppwhere ";
if ( Bugzilla->params->{'comment_taggers_group'}
- && $include_comment_tags
+ && $include_comment_activity
&& !$attach_id)
{
# Only includes comment tag activity for comments the user is allowed to see.
NULL AS activity_id,
NULL AS attach_id,"
. $dbh->sql_date_format('longdescs_tags_activity.bug_when',
- '%Y.%m.%d %H:%i:%s')
+ '%Y-%m-%d %H:%i:%s')
. " AS bug_when,
longdescs_tags_activity.removed,
longdescs_tags_activity.added,
my $list = $dbh->selectall_arrayref($query, undef, @args);
+ Bugzilla::Hook::process(
+ 'get_bug_activity',
+ {
+ bug_id => $bug_id,
+ attach_id => $attach_id,
+ start_time => $starttime,
+ include_comment_activity => $include_comment_activity,
+ list => \@$list
+ }
+ );
+
+ # ORDER BY bug_when
+ @$list = sort { $a->[3] cmp $b->[3] } @$list;
+
my @operations;
my $operation = {};
my $changes = [];
=back
+=head2 get_bug_activity
+
+This happens in L<Bugzilla::Bug::GetBugActivity>, where you can add custom bug
+activity, such as comment revisions, if needed.
+
+Params:
+
+=over
+
+=item C<bug_id>
+
+The bug ID that the activity belongs to.
+
+=item C<attach_id>
+
+An optional attachment ID that filters the activity.
+
+=item C<start_time>
+
+An optional time that filters the activity.
+
+=item C<include_comment_activity>
+
+Whether any comment activity, including comment tags, should be included.
+
+=item C<list>
+
+The core activity list that you can extend or modify in a hook. An list item is
+an array that should contain field name, activity ID (can be undef), attach ID
+(can be undef), timestamp, removed value, added value, user name and comment ID
+(can be undef).
+
+=back
+
=head2 bug_check_can_change_field
This hook controls what fields users are allowed to change. You can add code
$item{id} = $self->type('int', $bug_id);
my ($activity)
- = Bugzilla::Bug::GetBugActivity($bug_id, undef, $params->{new_since});
+ = Bugzilla::Bug::GetBugActivity($bug_id, undef, $params->{new_since}, 1);
my @history;
foreach my $changeset (@$activity) {
if (filter_wants $params, 'history', ['extra']) {
my @result;
my ($activity)
- = Bugzilla::Bug::GetBugActivity($bug->id, undef, $params->{new_since});
+ = Bugzilla::Bug::GetBugActivity($bug->id, undef, $params->{new_since}, 1);
foreach my $changeset (@$activity) {
push(@result,
$self->_changeset_to_hash($changeset, $params, ['extra'], 'history'));
my $api_field_type = $api_field_types{$field_name} || 'string';
my $api_field_name = $api_field_names{$field_name} || $field_name;
my $attach_id = delete $change->{attachid};
+ my $comment = delete $change->{comment};
$change->{field_name} = $self->type('string', $api_field_name);
$change->{removed} = $self->type($api_field_type, $change->{removed});
$change->{added} = $self->type($api_field_type, $change->{added});
$change->{attachment_id} = $self->type('int', $attach_id) if $attach_id;
+ $change->{comment_id} = $self->type('int', $comment->id) if $comment;
+ $change->{comment_count} = $self->type('int', $comment->count) if $comment;
push (@{$item->{changes}}, $change);
}
};
}
+sub get_bug_activity {
+ my ($self, $args) = @_;
+
+ return unless $args->{include_comment_activity};
+
+ my $list = $args->{list};
+ my $is_insider = Bugzilla->user->is_insider;
+ my $hidden_placeholder = '(Hidden by Administrator)';
+
+ my $edited_comment_ids
+ = Bugzilla->dbh->selectcol_arrayref('
+ SELECT DISTINCT(c.comment_id) from longdescs_activity AS a
+ INNER JOIN longdescs AS c ON c.comment_id = a.comment_id AND c.bug_id = ?
+ ' . ($is_insider ? '' : 'AND c.isprivate = 0'), undef, $args->{bug_id});
+
+ foreach my $comment_id (@$edited_comment_ids) {
+ my $prev_rev = {};
+
+ foreach my $revision (@{Bugzilla::Comment->new($comment_id)->activity}) {
+ # Exclude original comment, because we are interested only in revisions
+ if ($revision->{old}) {
+ push(@$list, [
+ 'comment_revision',
+ undef,
+ undef,
+ $revision->{created_time},
+ $prev_rev->{is_hidden} && !$is_insider ? $hidden_placeholder : $revision->{old},
+ $revision->{is_hidden} && !$is_insider ? $hidden_placeholder : $revision->{new},
+ $revision->{author}->{login_name},
+ $comment_id
+ ]);
+ }
+
+ $prev_rev = $revision;
+ }
+ }
+}
+
sub webservice {
my ($self, $args) = @_;
my $dispatch = $args->{dispatch};