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

Bug 303700: Eliminate deprecated Bugzilla::DB routines from votes.cgi - Patch by…

Bug 303700: Eliminate deprecated Bugzilla::DB routines from votes.cgi - Patch by Frédéric Buclin <LpSolit@gmail.com> r=joel a=justdave
parent 6b44875b
...@@ -22,9 +22,8 @@ ...@@ -22,9 +22,8 @@
[%# INTERFACE: [%# INTERFACE:
# bug_id: integer. ID of the bug we are listing the votes for. # bug_id: integer. ID of the bug we are listing the votes for.
# users: list of hashes. May be empty. Each hash has two members: # users: list of hashes. May be empty. Each hash has two members:
# name: string. The login name of the user whose vote is attached # login_name: string. The login name of the user whose vote is attached
# count: integer. The number of times that user has votes for this bug. # vote_count: integer. The number of times that user has votes for this bug.
# total: integer. The total number of votes for this bug.
#%] #%]
[% PROCESS global/variables.none.tmpl %] [% PROCESS global/variables.none.tmpl %]
...@@ -34,6 +33,7 @@ ...@@ -34,6 +33,7 @@
h2 = "$terms.Bug <a href=\"show_bug.cgi?id=$bug_id\">$bug_id</a>" h2 = "$terms.Bug <a href=\"show_bug.cgi?id=$bug_id\">$bug_id</a>"
%] %]
[% total = 0 %]
<table cellspacing="4"> <table cellspacing="4">
<tr> <tr>
<th>Who</th> <th>Who</th>
...@@ -41,14 +41,15 @@ ...@@ -41,14 +41,15 @@
</tr> </tr>
[% FOREACH voter = users %] [% FOREACH voter = users %]
[% total = total + voter.vote_count %]
<tr> <tr>
<td> <td>
<a href="votes.cgi?action=show_user&amp;user=[% voter.name FILTER url_quote %]"> <a href="votes.cgi?action=show_user&amp;user=[% voter.login_name FILTER url_quote %]">
[% voter.name FILTER html %] [% voter.login_name FILTER html %]
</a> </a>
</td> </td>
<td align="right"> <td align="right">
[% voter.count %] [% voter.vote_count %]
</td> </td>
</tr> </tr>
[% END %] [% END %]
......
...@@ -388,7 +388,7 @@ ...@@ -388,7 +388,7 @@
], ],
'bug/votes/list-for-bug.html.tmpl' => [ 'bug/votes/list-for-bug.html.tmpl' => [
'voter.count', 'voter.vote_count',
'total', 'total',
], ],
......
...@@ -89,27 +89,19 @@ exit; ...@@ -89,27 +89,19 @@ exit;
# Display the names of all the people voting for this one bug. # Display the names of all the people voting for this one bug.
sub show_bug { sub show_bug {
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
ThrowCodeError("missing_bug_id") unless defined $bug_id; ThrowCodeError("missing_bug_id") unless defined $bug_id;
my $total = 0;
my @users;
SendSQL("SELECT profiles.login_name, votes.who, votes.vote_count
FROM votes INNER JOIN profiles
ON profiles.userid = votes.who
WHERE votes.bug_id = $bug_id");
while (MoreSQLData()) {
my ($name, $userid, $count) = (FetchSQLData());
push (@users, { name => $name, id => $userid, count => $count });
$total += $count;
}
$vars->{'bug_id'} = $bug_id; $vars->{'bug_id'} = $bug_id;
$vars->{'users'} = \@users; $vars->{'users'} =
$vars->{'total'} = $total; $dbh->selectall_arrayref('SELECT profiles.login_name, votes.vote_count
FROM votes
INNER JOIN profiles
ON profiles.userid = votes.who
WHERE votes.bug_id = ?',
{'Slice' => {}}, $bug_id);
print $cgi->header(); print $cgi->header();
$template->process("bug/votes/list-for-bug.html.tmpl", $vars) $template->process("bug/votes/list-for-bug.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
...@@ -122,13 +114,14 @@ sub show_user { ...@@ -122,13 +114,14 @@ sub show_user {
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $user = Bugzilla->user;
# If a bug_id is given, and we're editing, we'll add it to the votes list. # If a bug_id is given, and we're editing, we'll add it to the votes list.
$bug_id ||= ""; $bug_id ||= "";
my $name = $cgi->param('user') || Bugzilla->user->login; my $name = $cgi->param('user') || $user->login;
my $who = DBNameToIdAndCheck($name); my $who = DBNameToIdAndCheck($name);
my $userid = Bugzilla->user->id; my $userid = $user->id;
my $canedit = (Param('usevotes') && $userid == $who) ? 1 : 0; my $canedit = (Param('usevotes') && $userid == $who) ? 1 : 0;
...@@ -140,11 +133,12 @@ sub show_user { ...@@ -140,11 +133,12 @@ sub show_user {
if ($canedit && $bug_id) { if ($canedit && $bug_id) {
# Make sure there is an entry for this bug # Make sure there is an entry for this bug
# in the vote table, just so that things display right. # in the vote table, just so that things display right.
SendSQL("SELECT votes.vote_count FROM votes my $has_votes = $dbh->selectrow_array('SELECT vote_count FROM votes
WHERE votes.bug_id = $bug_id AND votes.who = $who"); WHERE bug_id = ? AND who = ?',
if (!FetchOneColumn()) { undef, ($bug_id, $who));
SendSQL("INSERT INTO votes (who, bug_id, vote_count) if (!$has_votes) {
VALUES ($who, $bug_id, 0)"); $dbh->do('INSERT INTO votes (who, bug_id, vote_count)
VALUES (?, ?, 0)', undef, ($who, $bug_id));
} }
} }
...@@ -152,10 +146,10 @@ sub show_user { ...@@ -152,10 +146,10 @@ sub show_user {
# we can do it all in one query. # we can do it all in one query.
my %maxvotesperbug; my %maxvotesperbug;
if($canedit) { if($canedit) {
SendSQL("SELECT products.name, products.maxvotesperbug my $products = $dbh->selectall_arrayref('SELECT name, maxvotesperbug
FROM products"); FROM products');
while (MoreSQLData()) { foreach (@$products) {
my ($prod, $max) = FetchSQLData(); my ($prod, $max) = @$_;
$maxvotesperbug{$prod} = $max; $maxvotesperbug{$prod} = $max;
} }
} }
...@@ -169,27 +163,27 @@ sub show_user { ...@@ -169,27 +163,27 @@ sub show_user {
my @bugs; my @bugs;
my $total = 0; my $total = 0;
my $onevoteonly = 0; my $onevoteonly = 0;
SendSQL("SELECT votes.bug_id, votes.vote_count, bugs.short_desc, my $vote_list =
bugs.bug_status $dbh->selectall_arrayref('SELECT votes.bug_id, votes.vote_count,
FROM votes bugs.short_desc, bugs.bug_status
INNER JOIN bugs ON votes.bug_id = bugs.bug_id FROM votes
INNER JOIN products ON bugs.product_id = products.id INNER JOIN bugs ON votes.bug_id = bugs.bug_id
WHERE votes.who = $who INNER JOIN products ON bugs.product_id = products.id
AND products.name = " . SqlQuote($product) . WHERE votes.who = ? AND products.name = ?
"ORDER BY votes.bug_id"); ORDER BY votes.bug_id',
undef, ($who, $product));
while (MoreSQLData()) {
my ($id, $count, $summary, $status) = FetchSQLData(); foreach (@$vote_list) {
next if !defined($status); my ($id, $count, $summary, $status) = @$_;
$total += $count; $total += $count;
# Next if user can't see this bug. So, the totals will be correct # Next if user can't see this bug. So, the totals will be correct
# and they can see there are votes 'missing', but not on what bug # and they can see there are votes 'missing', but not on what bug
# they are. This seems a reasonable compromise; the alternative is # they are. This seems a reasonable compromise; the alternative is
# to lie in the totals. # to lie in the totals.
next if !Bugzilla->user->can_see_bug($id); next if !$user->can_see_bug($id);
push (@bugs, { id => $id, push (@bugs, { id => $id,
summary => $summary, summary => $summary,
count => $count, count => $count,
...@@ -214,7 +208,7 @@ sub show_user { ...@@ -214,7 +208,7 @@ sub show_user {
} }
} }
SendSQL("DELETE FROM votes WHERE vote_count <= 0"); $dbh->do('DELETE FROM votes WHERE vote_count <= 0');
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
$vars->{'canedit'} = $canedit; $vars->{'canedit'} = $canedit;
...@@ -281,16 +275,18 @@ sub record_votes { ...@@ -281,16 +275,18 @@ sub record_votes {
# If the user is voting for bugs, make sure they aren't overstuffing # If the user is voting for bugs, make sure they aren't overstuffing
# the ballot box. # the ballot box.
if (scalar(@buglist)) { if (scalar(@buglist)) {
SendSQL("SELECT bugs.bug_id, products.name, products.maxvotesperbug my $product_vote_settings =
FROM bugs $dbh->selectall_arrayref('SELECT bugs.bug_id, products.name,
INNER JOIN products products.maxvotesperbug
ON products.id = bugs.product_id FROM bugs
WHERE bugs.bug_id IN (" . join(", ", @buglist) . ")"); INNER JOIN products
ON products.id = bugs.product_id
WHERE bugs.bug_id IN
(' . join(', ', @buglist) . ')');
my %prodcount; my %prodcount;
foreach (@$product_vote_settings) {
while (MoreSQLData()) { my ($id, $prod, $max) = @$_;
my ($id, $prod, $max) = FetchSQLData();
$prodcount{$prod} ||= 0; $prodcount{$prod} ||= 0;
$prodcount{$prod} += $votes{$id}; $prodcount{$prod} += $votes{$id};
...@@ -324,23 +320,24 @@ sub record_votes { ...@@ -324,23 +320,24 @@ sub record_votes {
'products READ', 'fielddefs READ'); 'products READ', 'fielddefs READ');
# Take note of, and delete the user's old votes from the database. # Take note of, and delete the user's old votes from the database.
SendSQL("SELECT bug_id FROM votes WHERE who = $who"); my $bug_list = $dbh->selectcol_arrayref('SELECT bug_id FROM votes
while (MoreSQLData()) { WHERE who = ?', undef, $who);
my $id = FetchOneColumn();
foreach my $id (@$bug_list) {
$affected{$id} = 1; $affected{$id} = 1;
} }
$dbh->do('DELETE FROM votes WHERE who = ?', undef, $who);
SendSQL("DELETE FROM votes WHERE who = $who");
my $sth_insertVotes = $dbh->prepare('INSERT INTO votes (who, bug_id, vote_count)
VALUES (?, ?, ?)');
# Insert the new values in their place # Insert the new values in their place
foreach my $id (@buglist) { foreach my $id (@buglist) {
if ($votes{$id} > 0) { if ($votes{$id} > 0) {
SendSQL("INSERT INTO votes (who, bug_id, vote_count) $sth_insertVotes->execute($who, $id, $votes{$id});
VALUES ($who, $id, ".$votes{$id}.")");
} }
$affected{$id} = 1; $affected{$id} = 1;
} }
# Update the cached values in the bugs table # Update the cached values in the bugs table
print $cgi->header(); print $cgi->header();
my @updated_bugs = (); my @updated_bugs = ();
......
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