Commit b4c91ada authored by Reed Loden's avatar Reed Loden

Bug 395451 - "Bugzilla::BugMail needs to use Bug objects internally instead of direct SQL"

[r=mkanat a=mkanat]
parent 2ca283e7
...@@ -90,6 +90,7 @@ sub DB_COLUMNS { ...@@ -90,6 +90,7 @@ sub DB_COLUMNS {
delta_ts delta_ts
estimated_time estimated_time
everconfirmed everconfirmed
lastdiffed
op_sys op_sys
priority priority
product_id product_id
...@@ -2612,6 +2613,11 @@ sub blocked { ...@@ -2612,6 +2613,11 @@ sub blocked {
# Even bugs in an error state always have a bug_id. # Even bugs in an error state always have a bug_id.
sub bug_id { $_[0]->{'bug_id'}; } sub bug_id { $_[0]->{'bug_id'}; }
sub bug_group {
my ($self) = @_;
return join(', ', (map { $_->name } @{$self->groups_in}));
}
sub related_bugs { sub related_bugs {
my ($self, $relationship) = @_; my ($self, $relationship) = @_;
return [] if $self->{'error'}; return [] if $self->{'error'};
...@@ -3586,7 +3592,8 @@ sub _validate_attribute { ...@@ -3586,7 +3592,8 @@ sub _validate_attribute {
qw(error groups product_id component_id qw(error groups product_id component_id
comments milestoneurl attachments isopened comments milestoneurl attachments isopened
flag_types num_attachment_flag_types flag_types num_attachment_flag_types
show_attachment_flags any_flags_requesteeble), show_attachment_flags any_flags_requesteeble
lastdiffed),
# Bug fields. # Bug fields.
Bugzilla::Bug->fields Bugzilla::Bug->fields
......
...@@ -1427,7 +1427,7 @@ sub wants_bug_mail { ...@@ -1427,7 +1427,7 @@ sub wants_bug_mail {
# #
# We do them separately because if _any_ of them are set, we don't want # We do them separately because if _any_ of them are set, we don't want
# the mail. # the mail.
if ($wants_mail && $changer && ($self->login eq $changer)) { if ($wants_mail && $changer && ($self->id == $changer->id)) {
$wants_mail &= $self->wants_mail([EVT_CHANGED_BY_ME], $relationship); $wants_mail &= $self->wants_mail([EVT_CHANGED_BY_ME], $relationship);
} }
......
...@@ -430,7 +430,7 @@ sub create { ...@@ -430,7 +430,7 @@ sub create {
Bugzilla->login(LOGIN_REQUIRED); Bugzilla->login(LOGIN_REQUIRED);
$params = Bugzilla::Bug::map_fields($params); $params = Bugzilla::Bug::map_fields($params);
my $bug = Bugzilla::Bug->create($params); my $bug = Bugzilla::Bug->create($params);
Bugzilla::BugMail::Send($bug->bug_id, { changer => $bug->reporter->login }); Bugzilla::BugMail::Send($bug->bug_id, { changer => $bug->reporter });
return { id => $self->type('int', $bug->bug_id) }; return { id => $self->type('int', $bug->bug_id) };
} }
...@@ -520,7 +520,7 @@ sub add_comment { ...@@ -520,7 +520,7 @@ sub add_comment {
$dbh->bz_commit_transaction(); $dbh->bz_commit_transaction();
# Send mail. # Send mail.
Bugzilla::BugMail::Send($bug->bug_id, { changer => Bugzilla->user->login }); Bugzilla::BugMail::Send($bug->bug_id, { changer => Bugzilla->user });
return { id => $self->type('int', $new_comment_id) }; return { id => $self->type('int', $new_comment_id) };
} }
...@@ -566,7 +566,7 @@ sub update_see_also { ...@@ -566,7 +566,7 @@ sub update_see_also {
$changes{$bug->id}->{see_also} = { added => [], removed => [] }; $changes{$bug->id}->{see_also} = { added => [], removed => [] };
} }
Bugzilla::BugMail::Send($bug->id, { changer => $user->login }); Bugzilla::BugMail::Send($bug->id, { changer => $user });
} }
return { changes => \%changes }; return { changes => \%changes };
......
...@@ -538,7 +538,7 @@ sub insert { ...@@ -538,7 +538,7 @@ sub insert {
$vars->{'header_done'} = 1; $vars->{'header_done'} = 1;
$vars->{'contenttypemethod'} = $cgi->param('contenttypemethod'); $vars->{'contenttypemethod'} = $cgi->param('contenttypemethod');
my $recipients = { 'changer' => $user->login, 'owner' => $owner }; my $recipients = { 'changer' => $user, 'owner' => $owner };
$vars->{'sent_bugmail'} = Bugzilla::BugMail::Send($bugid, $recipients); $vars->{'sent_bugmail'} = Bugzilla::BugMail::Send($bugid, $recipients);
print $cgi->header(); print $cgi->header();
...@@ -666,7 +666,7 @@ sub update { ...@@ -666,7 +666,7 @@ sub update {
$vars->{'bugs'} = [$bug]; $vars->{'bugs'} = [$bug];
$vars->{'header_done'} = 1; $vars->{'header_done'} = 1;
$vars->{'sent_bugmail'} = $vars->{'sent_bugmail'} =
Bugzilla::BugMail::Send($bug->id, { 'changer' => $user->login }); Bugzilla::BugMail::Send($bug->id, { 'changer' => $user });
print $cgi->header(); print $cgi->header();
...@@ -739,7 +739,7 @@ sub delete_attachment { ...@@ -739,7 +739,7 @@ sub delete_attachment {
$vars->{'header_done'} = 1; $vars->{'header_done'} = 1;
$vars->{'sent_bugmail'} = $vars->{'sent_bugmail'} =
Bugzilla::BugMail::Send($bug->id, { 'changer' => $user->login }); Bugzilla::BugMail::Send($bug->id, { 'changer' => $user });
$template->process("attachment/updated.html.tmpl", $vars) $template->process("attachment/updated.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
......
...@@ -56,13 +56,14 @@ if ($changer !~ /$match/) { ...@@ -56,13 +56,14 @@ if ($changer !~ /$match/) {
print STDERR "Changer \"$changer\" doesn't match email regular expression.\n"; print STDERR "Changer \"$changer\" doesn't match email regular expression.\n";
usage(); usage();
} }
if(!login_to_id($changer)) { my $changer_user = new Bugzilla::User({ name => $changer });
print STDERR "\"$changer\" is not a login ID.\n"; unless ($changer_user) {
print STDERR "\"$changer\" is not a valid user.\n";
usage(); usage();
} }
# Send the email. # Send the email.
my $outputref = Bugzilla::BugMail::Send($bugnum, {'changer' => $changer }); my $outputref = Bugzilla::BugMail::Send($bugnum, {'changer' => $changer_user });
# Report the results. # Report the results.
my $sent = scalar(@{$outputref->{sent}}); my $sent = scalar(@{$outputref->{sent}});
......
...@@ -647,7 +647,7 @@ if ($action eq 'search') { ...@@ -647,7 +647,7 @@ if ($action eq 'search') {
# Send mail about what we've done to bugs. # Send mail about what we've done to bugs.
# The deleted user is not notified of the changes. # The deleted user is not notified of the changes.
foreach (keys(%updatedbugs)) { foreach (keys(%updatedbugs)) {
Bugzilla::BugMail::Send($_, {'changer' => $user->login} ); Bugzilla::BugMail::Send($_, {'changer' => $user} );
} }
########################################################################### ###########################################################################
......
...@@ -422,7 +422,7 @@ handle_attachments($bug, $attachments, $comment); ...@@ -422,7 +422,7 @@ handle_attachments($bug, $attachments, $comment);
# to wait for $bug->update() to be fully used in email_in.pl first. So # to wait for $bug->update() to be fully used in email_in.pl first. So
# currently, process_bug.cgi does the mail sending for bugs, and this does # currently, process_bug.cgi does the mail sending for bugs, and this does
# any mail sending for attachments after the first one. # any mail sending for attachments after the first one.
Bugzilla::BugMail::Send($bug->id, { changer => Bugzilla->user->login }); Bugzilla::BugMail::Send($bug->id, { changer => Bugzilla->user });
debug_print("Sent bugmail"); debug_print("Sent bugmail");
......
...@@ -619,7 +619,7 @@ sub _update_votes { ...@@ -619,7 +619,7 @@ sub _update_votes {
foreach my $bug_id (@updated_bugs) { foreach my $bug_id (@updated_bugs) {
$vars->{'id'} = $bug_id; $vars->{'id'} = $bug_id;
$vars->{'sent_bugmail'} = $vars->{'sent_bugmail'} =
Bugzilla::BugMail::Send($bug_id, { 'changer' => $user->login }); Bugzilla::BugMail::Send($bug_id, { 'changer' => $user });
$template->process("bug/process/results.html.tmpl", $vars) $template->process("bug/process/results.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
...@@ -729,7 +729,7 @@ sub _modify_bug_votes { ...@@ -729,7 +729,7 @@ sub _modify_bug_votes {
# And send out emails about changed bugs # And send out emails about changed bugs
foreach my $bug_id (@updated_bugs) { foreach my $bug_id (@updated_bugs) {
my $sent_bugmail = Bugzilla::BugMail::Send( my $sent_bugmail = Bugzilla::BugMail::Send(
$bug_id, { changer => Bugzilla->user->login }); $bug_id, { changer => Bugzilla->user });
$changes->{'confirmed_bugs_sent_bugmail'}->{$bug_id} = $sent_bugmail; $changes->{'confirmed_bugs_sent_bugmail'}->{$bug_id} = $sent_bugmail;
} }
} }
......
...@@ -1285,7 +1285,7 @@ sub process_bug { ...@@ -1285,7 +1285,7 @@ sub process_bug {
} }
Debug( $log, OK_LEVEL ); Debug( $log, OK_LEVEL );
push(@logs, $log); push(@logs, $log);
Bugzilla::BugMail::Send( $id, { 'changer' => $exporter_login } ) if ($mail); Bugzilla::BugMail::Send( $id, { 'changer' => $exporter } ) if ($mail);
# done with the xml data. Lets clear it from memory # done with the xml data. Lets clear it from memory
$twig->purge; $twig->purge;
......
...@@ -245,7 +245,7 @@ if ($token) { ...@@ -245,7 +245,7 @@ if ($token) {
("createbug:$id", $token)); ("createbug:$id", $token));
} }
my $recipients = { changer => $user->login }; my $recipients = { changer => $user };
my $bug_sent = Bugzilla::BugMail::Send($id, $recipients); my $bug_sent = Bugzilla::BugMail::Send($id, $recipients);
$bug_sent->{type} = 'created'; $bug_sent->{type} = 'created';
$bug_sent->{id} = $id; $bug_sent->{id} = $id;
......
...@@ -469,7 +469,7 @@ if ($move_action eq Bugzilla->params->{'move-button-text'}) { ...@@ -469,7 +469,7 @@ if ($move_action eq Bugzilla->params->{'move-button-text'}) {
# Now send emails. # Now send emails.
foreach my $bug (@bug_objects) { foreach my $bug (@bug_objects) {
$vars->{'mailrecipients'} = { 'changer' => $user->login }; $vars->{'mailrecipients'} = { 'changer' => $user };
$vars->{'id'} = $bug->id; $vars->{'id'} = $bug->id;
$vars->{'type'} = "move"; $vars->{'type'} = "move";
send_results($bug->id, $vars); send_results($bug->id, $vars);
...@@ -589,7 +589,7 @@ foreach my $bug (@bug_objects) { ...@@ -589,7 +589,7 @@ foreach my $bug (@bug_objects) {
cc => [split(/[\s,]+/, $old_cc)], cc => [split(/[\s,]+/, $old_cc)],
owner => $old_own, owner => $old_own,
qacontact => $old_qa, qacontact => $old_qa,
changer => Bugzilla->user->login }; changer => Bugzilla->user };
$vars->{'id'} = $bug->id; $vars->{'id'} = $bug->id;
$vars->{'type'} = "bug"; $vars->{'type'} = "bug";
...@@ -602,7 +602,7 @@ foreach my $bug (@bug_objects) { ...@@ -602,7 +602,7 @@ foreach my $bug (@bug_objects) {
# other bug of any changes to that bug. # other bug of any changes to that bug.
my $new_dup_id = $changes->{'dup_id'} ? $changes->{'dup_id'}->[1] : undef; my $new_dup_id = $changes->{'dup_id'} ? $changes->{'dup_id'}->[1] : undef;
if ($new_dup_id) { if ($new_dup_id) {
$vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login }; $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user };
$vars->{'id'} = $new_dup_id; $vars->{'id'} = $new_dup_id;
$vars->{'type'} = "dupe"; $vars->{'type'} = "dupe";
...@@ -614,7 +614,7 @@ foreach my $bug (@bug_objects) { ...@@ -614,7 +614,7 @@ foreach my $bug (@bug_objects) {
my %all_dep_changes = (%notify_deps, %changed_deps); my %all_dep_changes = (%notify_deps, %changed_deps);
foreach my $id (sort { $a <=> $b } (keys %all_dep_changes)) { foreach my $id (sort { $a <=> $b } (keys %all_dep_changes)) {
$vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login }; $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user };
$vars->{'id'} = $id; $vars->{'id'} = $id;
$vars->{'type'} = "dep"; $vars->{'type'} = "dep";
......
...@@ -248,7 +248,7 @@ if ($cgi->param('rescanallBugMail')) { ...@@ -248,7 +248,7 @@ if ($cgi->param('rescanallBugMail')) {
# and so choosing this user as being the last one having done a change # and so choosing this user as being the last one having done a change
# for the bug may be problematic. So the best we can do at this point # for the bug may be problematic. So the best we can do at this point
# is to choose the currently logged in user for email notification. # is to choose the currently logged in user for email notification.
$vars->{'changer'} = Bugzilla->user->login; $vars->{'changer'} = Bugzilla->user;
foreach my $bugid (@$list) { foreach my $bugid (@$list) {
Bugzilla::BugMail::Send($bugid, $vars); Bugzilla::BugMail::Send($bugid, $vars);
......
...@@ -23,26 +23,26 @@ ...@@ -23,26 +23,26 @@
From: [% Param('mailfrom') %] From: [% Param('mailfrom') %]
To: [% to_user.email %] To: [% to_user.email %]
Subject: [[% terms.Bug %] [%+ bugid %]] [% 'New: ' IF isnew %][%+ summary %] Subject: [[% terms.Bug %] [%+ bug.id %]] [% 'New: ' IF isnew %][%+ bug.short_desc %]
X-Bugzilla-Reason: [% reasonsheader %] X-Bugzilla-Reason: [% reasonsheader %]
X-Bugzilla-Type: [% isnew ? 'new' : 'changed' %] X-Bugzilla-Type: [% isnew ? 'new' : 'changed' %]
X-Bugzilla-Watch-Reason: [% reasonswatchheader %] X-Bugzilla-Watch-Reason: [% reasonswatchheader %]
[% IF Param('useclassification') %] [% IF Param('useclassification') %]
X-Bugzilla-Classification: [% classification %] X-Bugzilla-Classification: [% bug.classification %]
[% END %] [% END %]
X-Bugzilla-Product: [% product %] X-Bugzilla-Product: [% bug.product %]
X-Bugzilla-Component: [% comp %] X-Bugzilla-Component: [% bug.component %]
X-Bugzilla-Keywords: [% keywords %] X-Bugzilla-Keywords: [% bug.keywords %]
X-Bugzilla-Severity: [% severity %] X-Bugzilla-Severity: [% bug.bug_severity %]
X-Bugzilla-Who: [% changer %] X-Bugzilla-Who: [% changer.login %]
X-Bugzilla-Status: [% status %] X-Bugzilla-Status: [% bug.bug_status %]
X-Bugzilla-Priority: [% priority %] X-Bugzilla-Priority: [% bug.priority %]
X-Bugzilla-Assigned-To: [% assignedto %] X-Bugzilla-Assigned-To: [% bug.assigned_to.login %]
X-Bugzilla-Target-Milestone: [% targetmilestone %] X-Bugzilla-Target-Milestone: [% bug.target_milestone %]
X-Bugzilla-Changed-Fields: [% changedfields %] X-Bugzilla-Changed-Fields: [% changedfields %]
[%+ threadingmarker %] [%+ threadingmarker %]
[%+ urlbase %]show_bug.cgi?id=[% bugid %] [%+ urlbase %]show_bug.cgi?id=[% bug.id %]
[%- IF diffs %] [%- IF diffs %]
[%+ diffs %] [%+ diffs %]
......
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