From e74d21eaeb3bc4ba3a5521882815b6a6c6d45bcc Mon Sep 17 00:00:00 2001 From: Sebastin Santy Date: Sat, 29 Jul 2017 02:04:41 +0530 Subject: Bug 1383268 - Add attachments to new-bug --- new_bug.cgi | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'new_bug.cgi') diff --git a/new_bug.cgi b/new_bug.cgi index 7f35f9ebc..6a62d0dcb 100644 --- a/new_bug.cgi +++ b/new_bug.cgi @@ -45,6 +45,8 @@ my $user = Bugzilla->login(LOGIN_REQUIRED); my $cgi = Bugzilla->cgi; my $template = Bugzilla->template; my $vars = {}; +my $dbh = Bugzilla->dbh; + unless ($user->in_group('new-bug-testers')) { print $cgi->redirect(correct_urlbase()); @@ -70,6 +72,34 @@ if (lc($cgi->request_method) eq 'post') { }); delete_token($token); + my $data_fh = $cgi->upload('data'); + + if ($data_fh) { + my $content_type = Bugzilla::Attachment::get_content_type(); + my $attachment; + + my $error_mode_cache = Bugzilla->error_mode; + Bugzilla->error_mode(ERROR_MODE_DIE); + my $timestamp = $dbh->selectrow_array( + 'SELECT creation_ts FROM bugs WHERE bug_id = ?', undef, $new_bug->bug_id); + eval { + $attachment = Bugzilla::Attachment->create( + {bug => $new_bug, + creation_ts => $timestamp, + data => $data_fh, + description => scalar $cgi->param('description'), + filename => $data_fh, + ispatch => 0, + isprivate => 0, + mimetype => $content_type, + }); + }; + Bugzilla->error_mode($error_mode_cache); + unless ($attachment) { + $vars->{'message'} = 'attachment_creation_failed'; + } + } + my $recipients = { changer => $user }; my $bug_sent = Bugzilla::BugMail::Send($new_bug->bug_id, $recipients); $bug_sent->{type} = 'created'; -- cgit v1.2.3-24-g4f1b