当状态设置为RESOLVED时,我正试图修改bug(到Reporter)的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) changes数组是在查找用户对象还是仅查找登录信息?
谢谢!
这将起作用:
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
}
}
}