Commit 9a161bbf authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 282132: BugMail.pm: Eliminate deprecated Bugzilla::DB routines - Patch by…

Bug 282132: BugMail.pm: Eliminate deprecated Bugzilla::DB routines - Patch by Olav Vitters <bugzilla-mozilla@bkor.dhs.org> r=wicked a=justdave
parent aac2ea96
...@@ -32,7 +32,7 @@ use strict; ...@@ -32,7 +32,7 @@ use strict;
package Bugzilla::BugMail; package Bugzilla::BugMail;
use Bugzilla::DB qw(:deprecated); use Bugzilla::DB;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::Config qw(:DEFAULT $datadir);
...@@ -120,32 +120,33 @@ sub ProcessOneBug { ...@@ -120,32 +120,33 @@ sub ProcessOneBug {
my ($id, $forced) = (@_); my ($id, $forced) = (@_);
my @headerlist; my @headerlist;
my %values;
my %defmailhead; my %defmailhead;
my %fielddescription; my %fielddescription;
my $msg = ""; my $msg = "";
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
SendSQL("SELECT name, description, mailhead FROM fielddefs " . my $fields = $dbh->selectall_arrayref('SELECT name, description, mailhead
"ORDER BY sortkey"); FROM fielddefs ORDER BY sortkey');
while (MoreSQLData()) {
my ($field, $description, $mailhead) = (FetchSQLData()); foreach my $fielddef (@$fields) {
my ($field, $description, $mailhead) = @$fielddef;
push(@headerlist, $field); push(@headerlist, $field);
$defmailhead{$field} = $mailhead; $defmailhead{$field} = $mailhead;
$fielddescription{$field} = $description; $fielddescription{$field} = $description;
} }
SendSQL("SELECT " . join(',', @::log_columns) . ", lastdiffed, now() " .
"FROM bugs WHERE bug_id = $id"); my %values = %{$dbh->selectrow_hashref(
my @row = FetchSQLData(); 'SELECT ' . join(',', @::log_columns) . ',
foreach my $i (@::log_columns) { lastdiffed AS start, NOW() AS end
$values{$i} = shift(@row); FROM bugs WHERE bug_id = ?',
} undef, $id)};
$values{product} = &::get_product_name($values{product_id}); $values{product} = &::get_product_name($values{product_id});
$values{component} = &::get_component_name($values{component_id}); $values{component} = &::get_component_name($values{component_id});
my ($start, $end) = (@row); my ($start, $end) = ($values{start}, $values{end});
# User IDs of people in various roles. More than one person can 'have' a # User IDs of people in various roles. More than one person can 'have' a
# role, if the person in that role has changed, or people are watching. # role, if the person in that role has changed, or people are watching.
...@@ -199,47 +200,47 @@ sub ProcessOneBug { ...@@ -199,47 +200,47 @@ sub ProcessOneBug {
$values{'deadline'} = time2str("%Y-%m-%d", str2time($values{'deadline'})); $values{'deadline'} = time2str("%Y-%m-%d", str2time($values{'deadline'}));
} }
my @dependslist; my $dependslist = $dbh->selectcol_arrayref(
SendSQL("SELECT dependson FROM dependencies WHERE 'SELECT dependson FROM dependencies
blocked = $id ORDER BY dependson"); WHERE blocked = ? ORDER BY dependson',
while (MoreSQLData()) { undef, ($id));
push(@dependslist, FetchOneColumn());
}
$values{'dependson'} = join(",", @dependslist);
my @blockedlist; $values{'dependson'} = join(",", @$dependslist);
SendSQL("SELECT blocked FROM dependencies WHERE
dependson = $id ORDER BY blocked");
while (MoreSQLData()) {
push(@blockedlist, FetchOneColumn());
}
$values{'blocked'} = join(",", @blockedlist);
my @diffs; my $blockedlist = $dbh->selectcol_arrayref(
'SELECT blocked FROM dependencies
WHERE dependson = ? ORDER BY blocked',
undef, ($id));
$values{'blocked'} = join(",", @$blockedlist);
my @args = ($id);
# If lastdiffed is NULL, then we don't limit the search on time. # If lastdiffed is NULL, then we don't limit the search on time.
my $when_restriction = $start ? my $when_restriction = '';
" AND bug_when > '$start' AND bug_when <= '$end'" : ''; if ($start) {
SendSQL("SELECT profiles.login_name, fielddefs.description, " . $when_restriction = ' AND bug_when > ? AND bug_when <= ?';
" bug_when, removed, added, attach_id, fielddefs.name " . push @args, ($start, $end);
"FROM bugs_activity, fielddefs, profiles " .
"WHERE bug_id = $id " .
" AND fielddefs.fieldid = bugs_activity.fieldid " .
" AND profiles.userid = who " .
$when_restriction .
"ORDER BY bug_when"
);
while (MoreSQLData()) {
my @row = FetchSQLData();
push(@diffs, \@row);
} }
my $diffs = $dbh->selectall_arrayref(
"SELECT profiles.login_name, fielddefs.description,
bugs_activity.bug_when, bugs_activity.removed,
bugs_activity.added, bugs_activity.attach_id, fielddefs.name
FROM bugs_activity
INNER JOIN fielddefs
ON fielddefs.fieldid = bugs_activity.fieldid
INNER JOIN profiles
ON profiles.userid = bugs_activity.who
WHERE bugs_activity.bug_id = ?
$when_restriction
ORDER BY bugs_activity.bug_when", undef, @args);
my $difftext = ""; my $difftext = "";
my $diffheader = ""; my $diffheader = "";
my @diffparts; my @diffparts;
my $lastwho = ""; my $lastwho = "";
foreach my $ref (@diffs) { foreach my $ref (@$diffs) {
my ($who, $what, $when, $old, $new, $attachid, $fieldname) = (@$ref); my ($who, $what, $when, $old, $new, $attachid, $fieldname) = (@$ref);
my $diffpart = {}; my $diffpart = {};
if ($who ne $lastwho) { if ($who ne $lastwho) {
...@@ -255,9 +256,9 @@ sub ProcessOneBug { ...@@ -255,9 +256,9 @@ sub ProcessOneBug {
$new = format_time_decimal($new); $new = format_time_decimal($new);
} }
if ($attachid) { if ($attachid) {
SendSQL("SELECT isprivate FROM attachments ($diffpart->{'isprivate'}) = $dbh->selectrow_array(
WHERE attach_id = $attachid"); 'SELECT isprivate FROM attachments WHERE attach_id = ?',
$diffpart->{'isprivate'} = FetchOneColumn(); undef, ($attachid));
} }
$difftext = FormatTriple($what, $old, $new); $difftext = FormatTriple($what, $old, $new);
$diffpart->{'header'} = $diffheader; $diffpart->{'header'} = $diffheader;
...@@ -268,26 +269,29 @@ sub ProcessOneBug { ...@@ -268,26 +269,29 @@ sub ProcessOneBug {
my $deptext = ""; my $deptext = "";
SendSQL("SELECT bugs_activity.bug_id, bugs.short_desc, fielddefs.name, " . my $dependency_diffs = $dbh->selectall_arrayref(
" removed, added " . "SELECT bugs_activity.bug_id, bugs.short_desc, fielddefs.name,
"FROM bugs_activity, bugs, dependencies, fielddefs ". bugs_activity.removed, bugs_activity.added
"WHERE bugs_activity.bug_id = dependencies.dependson " . FROM bugs_activity
" AND bugs.bug_id = bugs_activity.bug_id ". INNER JOIN bugs
" AND dependencies.blocked = $id " . ON bugs.bug_id = bugs_activity.bug_id
" AND fielddefs.fieldid = bugs_activity.fieldid" . INNER JOIN dependencies
" AND (fielddefs.name = 'bug_status' " . ON bugs_activity.bug_id = dependencies.dependson
" OR fielddefs.name = 'resolution') " . INNER JOIN fielddefs
$when_restriction . ON fielddefs.fieldid = bugs_activity.fieldid
"ORDER BY bug_when, bug_id"); WHERE dependencies.blocked = ?
AND (fielddefs.name = 'bug_status'
OR fielddefs.name = 'resolution')
$when_restriction
ORDER BY bugs_activity.bug_when, bugs.bug_id", undef, @args);
my $thisdiff = ""; my $thisdiff = "";
my $lastbug = ""; my $lastbug = "";
my $interestingchange = 0; my $interestingchange = 0;
my $depbug = 0;
my @depbugs; my @depbugs;
while (MoreSQLData()) { foreach my $dependency_diff (@$dependency_diffs) {
my ($summary, $what, $old, $new); my ($depbug, $summary, $what, $old, $new) = @$dependency_diff;
($depbug, $summary, $what, $old, $new) = (FetchSQLData());
if ($depbug ne $lastbug) { if ($depbug ne $lastbug) {
if ($interestingchange) { if ($interestingchange) {
$deptext .= $thisdiff; $deptext .= $thisdiff;
...@@ -337,8 +341,8 @@ sub ProcessOneBug { ...@@ -337,8 +341,8 @@ sub ProcessOneBug {
# array of role constants. # array of role constants.
# Voters # Voters
my $voters = my $voters = $dbh->selectcol_arrayref(
$dbh->selectcol_arrayref("SELECT who FROM votes WHERE bug_id = $id"); "SELECT who FROM votes WHERE bug_id = ?", undef, ($id));
push(@{$recipients{$_}}, REL_VOTER) foreach (@$voters); push(@{$recipients{$_}}, REL_VOTER) foreach (@$voters);
...@@ -361,7 +365,7 @@ sub ProcessOneBug { ...@@ -361,7 +365,7 @@ sub ProcessOneBug {
# The last relevant set of people are those who are being removed from # The last relevant set of people are those who are being removed from
# their roles in this change. We get their names out of the diffs. # their roles in this change. We get their names out of the diffs.
foreach my $ref (@diffs) { foreach my $ref (@$diffs) {
my ($who, $what, $when, $old, $new) = (@$ref); my ($who, $what, $when, $old, $new) = (@$ref);
if ($old) { if ($old) {
# You can't stop being the reporter, and mail isn't sent if you # You can't stop being the reporter, and mail isn't sent if you
...@@ -419,7 +423,7 @@ sub ProcessOneBug { ...@@ -419,7 +423,7 @@ sub ProcessOneBug {
foreach my $relationship (@{$recipients{$user_id}}) { foreach my $relationship (@{$recipients{$user_id}}) {
if ($user->wants_bug_mail($id, if ($user->wants_bug_mail($id,
$relationship, $relationship,
\@diffs, $diffs,
$newcomments, $newcomments,
$changer)) $changer))
{ {
...@@ -480,7 +484,8 @@ sub ProcessOneBug { ...@@ -480,7 +484,8 @@ sub ProcessOneBug {
} }
} }
$dbh->do("UPDATE bugs SET lastdiffed = '$end' WHERE bug_id = $id"); $dbh->do('UPDATE bugs SET lastdiffed = ? WHERE bug_id = ?',
undef, ($end, $id));
return {'sent' => \@sent, 'excluded' => \@excluded}; return {'sent' => \@sent, 'excluded' => \@excluded};
} }
...@@ -766,7 +771,8 @@ sub get_comments_by_bug { ...@@ -766,7 +771,8 @@ sub get_comments_by_bug {
longdescs.thetext, longdescs.isprivate, longdescs.thetext, longdescs.isprivate,
longdescs.already_wrapped longdescs.already_wrapped
FROM longdescs FROM longdescs
INNER JOIN profiles ON profiles.userid = longdescs.who INNER JOIN profiles
ON profiles.userid = longdescs.who
WHERE longdescs.bug_id = ? '; WHERE longdescs.bug_id = ? ';
my @args = ($id); my @args = ($id);
......
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