2012-03-09 80 views
1

我试图在状态设置为RESOLVED时修改分配给To字段上的错误(给Reporter)。我当前的代码如下所示:Bugzilla扩展:在bug_end_update中使用set_assigned_to修改“分配给”字段

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)更改数组查找用户对象还是仅登录信息?

谢谢!

+0

发现http://bugzilla.glob.com.au/irc/a=date&h=&s=+4+Feb+2011&e=+4+Feb+2011其对我需要做的改变做了一些深入的了解,以便全面掌握和运行。首先我使用了错误的Hook,因为在bug_end_of_update中DB已经被写入。所以我用object_end_of_set_all调整了参数和一切工作。用户对象只需登录信息$ bug-> reporter->登录。 – TimReeves 2012-03-14 04:25:03

回答

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 
     } 
    } 
}