1
哪個鉤子需要鉤入以確定何時將新評論添加到錯誤中?在Bugzilla擴展中,如何檢測正在添加的新評論?
我的用例是,無論何時添加評論,我都需要處理所有評論,並根據該評論執行一些操作。但是,此操作「非常昂貴」,因此除非真的添加了評論,否則我不想執行操作。我迄今發現,以確定此
的唯一方法是掛接到object_end_of_update
與代碼:
sub object_end_of_update {
my ($self, $args) = @_;
my ($object, $old_object, $changes) = @$args{qw(object old_object changes)};
print STDERR "--- Object Type: " . ref $object;
if ($object->isa('Bugzilla::Bug')) {
# Load comments on the old object here, otherwise by the time we get
# to bug_end_of_update it is too late, and we cannot determine if a
# new comment has been added or not.
$old_object->comments({order=>'oldest_to_newest'});
}
}
,然後掛接到bug_end_of_update
,於是我可以這樣做:
sub bug_end_of_update {
my ($self, $args) = @_;
my ($bug, $old_bug, $timestamp, $changes) = @$args{qw(bug old_bug timestamp changes)};
# Note that this will only work if the old comments have already been
# loaded in object_end_of_update, otherwise when we get the old comments
# here, it just goes to the DB, and gets all of the comments, including
# the new one, if there is one.
my $oldComments = $old_bug->comments({order=>'oldest_to_newest'});
my $newComments = $bug->comments({order=>'oldest_to_newest'});
if (scalar(@$newComments) > scalar(@$oldComments)) {
# If we added a new comment, then perform processing.
do_slow_action($bug);
}
}
但是,這感覺脆弱,即使它不是,絕對不是明確的代碼。
確定評論已添加到bugzilla錯誤的正確方法是什麼?
雖然我知道這是可能從數據庫中調用Web服務,這最終會在更多地方蔓延的邏輯比我想的。 –