Commit c712d457 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 346121: Creating an attachment upon new bug doesn't create attachment link…

Bug 346121: Creating an attachment upon new bug doesn't create attachment link in comment #0 - Patch by Fré©ric Buclin <LpSolit@gmail.com> r=bkor a=justdave
parent 840eaae0
...@@ -1351,6 +1351,36 @@ sub AppendComment { ...@@ -1351,6 +1351,36 @@ sub AppendComment {
undef, $timestamp, $bugid); undef, $timestamp, $bugid);
} }
sub update_comment {
my ($self, $comment_id, $new_comment) = @_;
# Some validation checks.
if ($self->{'error'}) {
ThrowCodeError("bug_error", { bug => $self });
}
detaint_natural($comment_id)
|| ThrowCodeError('bad_arg', {argument => 'comment_id', function => 'update_comment'});
# The comment ID must belong to this bug.
my @current_comment_obj = grep {$_->{'id'} == $comment_id} @{$self->longdescs};
scalar(@current_comment_obj)
|| ThrowCodeError('bad_arg', {argument => 'comment_id', function => 'update_comment'});
# If the new comment is undefined, then there is nothing to update.
# To delete a comment, an empty string should be passed.
return unless defined $new_comment;
$new_comment =~ s/\s*$//s; # Remove trailing whitespaces.
$new_comment =~ s/\r\n?/\n/g; # Handle Windows and Mac-style line endings.
trick_taint($new_comment);
# We assume ValidateComment() has already been called earlier.
Bugzilla->dbh->do('UPDATE longdescs SET thetext = ? WHERE comment_id = ?',
undef, ($new_comment, $comment_id));
# Update the comment object with this new text.
$current_comment_obj[0]->{'body'} = $new_comment;
}
# Represents which fields from the bugs table are handled by process_bug.cgi. # Represents which fields from the bugs table are handled by process_bug.cgi.
sub editable_bug_fields { sub editable_bug_fields {
my @fields = Bugzilla->dbh->bz_table_columns('bugs'); my @fields = Bugzilla->dbh->bz_table_columns('bugs');
...@@ -1416,7 +1446,8 @@ sub GetComments { ...@@ -1416,7 +1446,8 @@ sub GetComments {
my @comments; my @comments;
my @args = ($id); my @args = ($id);
my $query = 'SELECT profiles.realname AS name, profiles.login_name AS email, ' . my $query = 'SELECT longdescs.comment_id AS id, profiles.realname AS name,
profiles.login_name AS email, ' .
$dbh->sql_date_format('longdescs.bug_when', '%Y.%m.%d %H:%i:%s') . $dbh->sql_date_format('longdescs.bug_when', '%Y.%m.%d %H:%i:%s') .
' AS time, longdescs.thetext AS body, longdescs.work_time, ' AS time, longdescs.thetext AS body, longdescs.work_time,
isprivate, already_wrapped, type, extra_data isprivate, already_wrapped, type, extra_data
......
...@@ -187,10 +187,26 @@ if (defined $cgi->param('version')) { ...@@ -187,10 +187,26 @@ if (defined $cgi->param('version')) {
# Add an attachment if requested. # Add an attachment if requested.
if (defined($cgi->upload('data')) || $cgi->param('attachurl')) { if (defined($cgi->upload('data')) || $cgi->param('attachurl')) {
$cgi->param('isprivate', $cgi->param('commentprivacy')); $cgi->param('isprivate', $cgi->param('commentprivacy'));
Bugzilla::Attachment->insert_attachment_for_bug(!THROW_ERROR, my $attach_id = Bugzilla::Attachment->insert_attachment_for_bug(!THROW_ERROR,
$bug, $user, $timestamp, $bug, $user, $timestamp, \$vars);
\$vars)
|| ($vars->{'message'} = 'attachment_creation_failed'); if ($attach_id) {
# Update the comment to include the new attachment ID.
# This string is hardcoded here because Template::quoteUrls()
# expects to find this exact string.
my $new_comment = "Created an attachment (id=$attach_id)\n" .
$cgi->param('description') . "\n";
# We can use $bug->longdescs here because we are sure that the bug
# description is of type CMT_NORMAL. No need to include it if it's
# empty, though.
if ($bug->longdescs->[0]->{'body'} !~ /^\s+$/) {
$new_comment .= "\n" . $bug->longdescs->[0]->{'body'};
}
$bug->update_comment($bug->longdescs->[0]->{'id'}, $new_comment);
}
else {
$vars->{'message'} = 'attachment_creation_failed';
}
# Determine if Patch Viewer is installed, for Diff link # Determine if Patch Viewer is installed, for Diff link
eval { eval {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment