Bugzilla扩展:使用bug_end_update中的set_assigned_to修改“已分配给”字段

时间:2012-03-09 04:55:49

标签: perl bugzilla

当我将状态设置为RESOLVED时,我正在尝试修改bug上的Assigned To字段(到Reporter)。我目前的代码如下:

sub bug_end_of_update
{
    my ($self, $args) = @_; 

    my $bug = $args->{ 'bug' };
    my $changes = $args->{ 'changes' };
    # Check if the status has changed
    if ( $changes->{ 'bug_status' } )
    {
        my ($old_status, $new_status) = @{ $changes->{ 'bug_status' } };
        # Check if the bug status has been set to RESOLVED
        if ( $new_status eq "RESOLVED" )
        {
            # Change Assignee to the original Reporter of the Bug.
            $bug->set_assigned_to( <reporter obj> );

            # Add to changes for tracking
            $changes->{ 'assigned_to' } = [ <assigned obj>, <reporter obj> ];
        }
    }
}

我正在寻找两件事:
1)在bug_end_of_update中,如何获取报告者用户对象和分配给用户对象?
2)changes数组是在寻找用户对象还是只是登录信息?

谢谢!

1 个答案:

答案 0 :(得分:3)

这将有效:

sub bug_end_of_update {
    my ($self, $args) = @_;

    my ($bug, $old_bug, $timestamp, $changes) = @$args{qw(bug old_bug timestamp changes)};

    if ($changes->{bug_status}[1] eq 'RESOLVED') {      # Status has been changed to RESOLVED
        $bug->set_assigned_to($bug->reporter->login);   # re-assign to Reporter
        $bug->update();
    }
}

但是,它会更新错误两次(因为一旦数据库已经更新,就会调用bug_end_of_update)。

更好的解决方案是:

sub object_end_of_set_all {
    my ($self, $args) = @_;

    my $object = $args->{'object'};

    if ($object->isa('Bugzilla::Bug')) {
        if ($object->{'bug_status'} eq 'RESOLVED') {            # Bug has been RESOLVED
            $object->{'assigned_to'} = $object->{'reporter_id'};    # re-assign to Reporter
        }
    }
}