From d0002e9626b97df6fad2c597b89c8ec31f7c308a Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Wed, 5 Aug 2009 12:35:50 +0000 Subject: =?UTF-8?q?Bug=20415541:=20Implement=20$bug->set=5Fflags()=20and?= =?UTF-8?q?=20$attachment->set=5Fflags()=20-=20Patch=20by=20Fr=C3=83=C2=A9?= =?UTF-8?q?d=C3=83=C2=A9ric=20Buclin=20=20a=3DLpSolit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attachment.cgi | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) (limited to 'attachment.cgi') diff --git a/attachment.cgi b/attachment.cgi index f6549841f..b62e4f23c 100755 --- a/attachment.cgi +++ b/attachment.cgi @@ -469,26 +469,16 @@ sub insert { store_in_file => scalar $cgi->param('bigfile'), }); - Bugzilla::Flag->set_flags($bug, $attachment, $timestamp, $vars); - - my $fieldid = get_field_id('attachments.isobsolete'); - foreach my $obsolete_attachment (@obsolete_attachments) { - # If the obsolete attachment has request flags, cancel them. - # This call must be done before updating the 'attachments' table. - Bugzilla::Flag->CancelRequests($bug, $obsolete_attachment, $timestamp); - - $dbh->do('UPDATE attachments SET isobsolete = 1, modification_time = ? - WHERE attach_id = ?', - undef, ($timestamp, $obsolete_attachment->id)); - - $dbh->do('INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, - fieldid, removed, added) - VALUES (?,?,?,?,?,?,?)', - undef, ($bug->bug_id, $obsolete_attachment->id, $user->id, - $timestamp, $fieldid, 0, 1)); + $obsolete_attachment->set_is_obsolete(1); + $obsolete_attachment->update($timestamp); } + my ($flags, $new_flags) = Bugzilla::Flag->extract_flags_from_cgi( + $bug, $attachment, $vars, SKIP_REQUESTEE_ON_ERROR); + $attachment->set_flags($flags, $new_flags); + $attachment->update($timestamp); + # Insert a comment about the new attachment into the database. my $comment = "Created an attachment (id=" . $attachment->id . ")\n" . $attachment->description . "\n"; @@ -627,27 +617,18 @@ sub update { $bug->add_comment($comment, { isprivate => $attachment->isprivate }); } - # The order of these function calls is important, as Flag::validate - # assumes User::match_field has ensured that the values in the - # requestee fields are legitimate user email addresses. - Bugzilla::User::match_field($cgi, { - '^requestee(_type)?-(\d+)$' => { 'type' => 'multi' } - }); - Bugzilla::Flag::validate($bug->id, $attachment->id); - + my ($flags, $new_flags) = Bugzilla::Flag->extract_flags_from_cgi($bug, $attachment, $vars); + $attachment->set_flags($flags, $new_flags); # Figure out when the changes were made. - my ($timestamp) = $dbh->selectrow_array("SELECT NOW()"); - - # Update flags. We have to do this before committing changes - # to attachments so that we can delete pending requests if the user - # is obsoleting this attachment without deleting any requests - # the user submits at the same time. - Bugzilla::Flag->process($bug, $attachment, $timestamp, $vars); + my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); - $attachment->update($timestamp); + my $changes = $attachment->update($timestamp); + # If there are changes, we updated delta_ts in the DB. We have to + # reflect this change in the bug object. + $bug->{delta_ts} = $timestamp if scalar(keys %$changes); # Commit the comment, if any. - $bug->update(); + $bug->update($timestamp); # Commit the transaction now that we are finished updating the database. $dbh->bz_commit_transaction(); -- cgit v1.2.1