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

Bug 303706: Eliminate deprecated Bugzilla::DB routines from editproducts.cgi -…

Bug 303706: Eliminate deprecated Bugzilla::DB routines from editproducts.cgi - Patch by Frédéric Buclin <LpSolit@gmail.com> r=wicked a=justdave
parent 4a27b937
...@@ -197,46 +197,40 @@ if ($action eq 'new') { ...@@ -197,46 +197,40 @@ if ($action eq 'new') {
} }
my $milestoneurl = trim($cgi->param('milestoneurl') || ''); my $milestoneurl = trim($cgi->param('milestoneurl') || '');
my $disallownew = 0; my $disallownew = $cgi->param('disallownew') ? 1 : 0;
$disallownew = 1 if $cgi->param('disallownew'); my $votesperuser = $cgi->param('votesperuser') || 0;
my $votesperuser = $cgi->param('votesperuser'); my $maxvotesperbug = defined($cgi->param('maxvotesperbug')) ?
$votesperuser ||= 0; $cgi->param('maxvotesperbug') : 10000;
my $maxvotesperbug = $cgi->param('maxvotesperbug'); my $votestoconfirm = $cgi->param('votestoconfirm') || 0;
$maxvotesperbug = 10000 if !defined $maxvotesperbug;
my $votestoconfirm = $cgi->param('votestoconfirm');
$votestoconfirm ||= 0;
my $defaultmilestone = $cgi->param('defaultmilestone') || "---"; my $defaultmilestone = $cgi->param('defaultmilestone') || "---";
# The following variables are used in placeholders only.
trick_taint($product_name);
trick_taint($version);
trick_taint($description);
trick_taint($milestoneurl);
trick_taint($defaultmilestone);
detaint_natural($disallownew);
detaint_natural($votesperuser);
detaint_natural($maxvotesperbug);
detaint_natural($votestoconfirm);
# Add the new product. # Add the new product.
SendSQL("INSERT INTO products ( " . $dbh->do('INSERT INTO products
"name, description, milestoneurl, disallownew, votesperuser, " . (name, description, milestoneurl, disallownew, votesperuser,
"maxvotesperbug, votestoconfirm, defaultmilestone, classification_id" . maxvotesperbug, votestoconfirm, defaultmilestone, classification_id)
" ) VALUES ( " . VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
SqlQuote($product_name) . "," . undef, ($product_name, $description, $milestoneurl, $disallownew,
SqlQuote($description) . "," . $votesperuser, $maxvotesperbug, $votestoconfirm, $defaultmilestone,
SqlQuote($milestoneurl) . "," . $classification_id));
# had tainting issues under cygwin, IIS 5.0, perl -T %s %s
# see bug 208647. http://bugzilla.mozilla.org/show_bug.cgi?id=208647
# had to de-taint $disallownew, $votesperuser, $maxvotesperbug,
# and $votestoconfirm w/ SqlQuote()
# - jpyeron@pyerotechnics.com
SqlQuote($disallownew) . "," .
SqlQuote($votesperuser) . "," .
SqlQuote($maxvotesperbug) . "," .
SqlQuote($votestoconfirm) . "," .
SqlQuote($defaultmilestone) . "," .
SqlQuote($classification_id) . ")");
$product = new Bugzilla::Product({name => $product_name}); $product = new Bugzilla::Product({name => $product_name});
SendSQL("INSERT INTO versions ( " . $dbh->do('INSERT INTO versions (value, product_id) VALUES (?, ?)',
"value, product_id" . undef, ($version, $product->id));
" ) VALUES ( " .
SqlQuote($version) . "," .
$product->id . ")" );
SendSQL("INSERT INTO milestones (product_id, value) VALUES (" . $dbh->do('INSERT INTO milestones (product_id, value) VALUES (?, ?)',
$product->id . ", " . SqlQuote($defaultmilestone) . ")"); undef, ($product->id, $defaultmilestone));
# If we're using bug groups, then we need to create a group for this # If we're using bug groups, then we need to create a group for this
# product as well. -JMR, 2/16/00 # product as well. -JMR, 2/16/00
...@@ -246,31 +240,35 @@ if ($action eq 'new') { ...@@ -246,31 +240,35 @@ if ($action eq 'new') {
while (GroupExists($productgroup)) { while (GroupExists($productgroup)) {
$productgroup .= '_'; $productgroup .= '_';
} }
SendSQL("INSERT INTO groups " . my $group_description = "Access to bugs in the " .
"(name, description, isbuggroup, last_changed) " . $product->name . " product";
"VALUES (" .
SqlQuote($productgroup) . ", " . $dbh->do('INSERT INTO groups
SqlQuote("Access to bugs in the " . $product->name . (name, description, isbuggroup, last_changed)
" product") . ", 1, NOW())"); VALUES (?, ?, ?, NOW())',
undef, ($productgroup, $group_description, 1));
my $gid = $dbh->bz_last_key('groups', 'id'); my $gid = $dbh->bz_last_key('groups', 'id');
my $admin = GroupNameToId('admin');
# If we created a new group, give the "admin" group priviledges # If we created a new group, give the "admin" group priviledges
# initially. # initially.
SendSQL("INSERT INTO group_group_map (member_id, grantor_id, grant_type) my $admin = GroupNameToId('admin');
VALUES ($admin, $gid," . GROUP_MEMBERSHIP .")");
SendSQL("INSERT INTO group_group_map (member_id, grantor_id, grant_type) my $sth = $dbh->prepare('INSERT INTO group_group_map
VALUES ($admin, $gid," . GROUP_BLESS .")"); (member_id, grantor_id, grant_type)
SendSQL("INSERT INTO group_group_map (member_id, grantor_id, grant_type) VALUES (?, ?, ?)');
VALUES ($admin, $gid," . GROUP_VISIBLE .")");
$sth->execute($admin, $gid, GROUP_MEMBERSHIP);
$sth->execute($admin, $gid, GROUP_BLESS);
$sth->execute($admin, $gid, GROUP_VISIBLE);
# Associate the new group and new product. # Associate the new group and new product.
SendSQL("INSERT INTO group_control_map " . $dbh->do('INSERT INTO group_control_map
"(group_id, product_id, entry, " . (group_id, product_id, entry, membercontrol,
"membercontrol, othercontrol, canedit) VALUES " . othercontrol, canedit)
"($gid, " . $product->id . ", " . VALUES (?, ?, ?, ?, ?, ?)',
Param("useentrygroupdefault") . undef, ($gid, $product->id, Param('useentrygroupdefault'),
", " . CONTROLMAPDEFAULT . ", " . CONTROLMAPDEFAULT, CONTROLMAPNA, 0));
CONTROLMAPNA . ", 0)");
} }
if ($cgi->param('createseries')) { if ($cgi->param('createseries')) {
...@@ -493,57 +491,53 @@ if ($action eq 'updategroupcontrols') { ...@@ -493,57 +491,53 @@ if ($action eq 'updategroupcontrols') {
} }
} }
if (!defined $cgi->param('confirmed')) { if (!defined $cgi->param('confirmed')) {
my @na_groups = (); my $na_groups;
if (@now_na) { if (@now_na) {
SendSQL("SELECT groups.name, COUNT(bugs.bug_id) $na_groups = $dbh->selectall_arrayref(
FROM bugs, bug_group_map, groups 'SELECT groups.name, COUNT(bugs.bug_id) AS count
WHERE groups.id IN(" . join(', ', @now_na) . ") FROM bugs
AND bug_group_map.group_id = groups.id INNER JOIN bug_group_map
AND bug_group_map.bug_id = bugs.bug_id ON bug_group_map.bug_id = bugs.bug_id
AND bugs.product_id = " . $product->id . " " . INNER JOIN groups
$dbh->sql_group_by('groups.name')); ON bug_group_map.group_id = groups.id
while (MoreSQLData()) { WHERE groups.id IN (' . join(', ', @now_na) . ')
my ($groupname, $bugcount) = FetchSQLData(); AND bugs.product_id = ? ' .
my %g = (); $dbh->sql_group_by('groups.name'),
$g{'name'} = $groupname; {'Slice' => {}}, $product->id);
$g{'count'} = $bugcount; }
push @na_groups,\%g;
} my $mandatory_groups;
}
my @mandatory_groups = ();
if (@now_mandatory) { if (@now_mandatory) {
SendSQL("SELECT groups.name, COUNT(bugs.bug_id) $mandatory_groups = $dbh->selectall_arrayref(
'SELECT groups.name, COUNT(bugs.bug_id) AS count
FROM bugs FROM bugs
LEFT JOIN bug_group_map LEFT JOIN bug_group_map
ON bug_group_map.bug_id = bugs.bug_id ON bug_group_map.bug_id = bugs.bug_id
INNER JOIN groups INNER JOIN groups
ON bug_group_map.group_id = groups.id ON bug_group_map.group_id = groups.id
WHERE groups.id IN(" . join(', ', @now_mandatory) . ") WHERE groups.id IN (' . join(', ', @now_mandatory) . ')
AND bugs.product_id = " . $product->id . " AND bugs.product_id = ?
AND bug_group_map.bug_id IS NULL " . AND bug_group_map.bug_id IS NULL ' .
$dbh->sql_group_by('groups.name')); $dbh->sql_group_by('groups.name'),
while (MoreSQLData()) { {'Slice' => {}}, $product->id);
my ($groupname, $bugcount) = FetchSQLData(); }
my %g = (); if (($na_groups && scalar(@$na_groups))
$g{'name'} = $groupname; || ($mandatory_groups && scalar(@$mandatory_groups)))
$g{'count'} = $bugcount; {
push @mandatory_groups,\%g;
}
}
if ((@na_groups) || (@mandatory_groups)) {
$vars->{'product'} = $product; $vars->{'product'} = $product;
$vars->{'na_groups'} = \@na_groups; $vars->{'na_groups'} = $na_groups;
$vars->{'mandatory_groups'} = \@mandatory_groups; $vars->{'mandatory_groups'} = $mandatory_groups;
$template->process("admin/products/groupcontrol/confirm-edit.html.tmpl", $vars) $template->process("admin/products/groupcontrol/confirm-edit.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
} }
SendSQL("SELECT id, name FROM groups " .
"WHERE isbuggroup != 0 AND isactive != 0"); my $groups = $dbh->selectall_arrayref('SELECT id, name FROM groups
while (MoreSQLData()){ WHERE isbuggroup != 0
my ($groupid, $groupname) = FetchSQLData(); AND isactive != 0');
foreach my $group (@$groups) {
my ($groupid, $groupname) = @$group;
my $newmembercontrol = $cgi->param("membercontrol_$groupid") || 0; my $newmembercontrol = $cgi->param("membercontrol_$groupid") || 0;
my $newothercontrol = $cgi->param("othercontrol_$groupid") || 0; my $newothercontrol = $cgi->param("othercontrol_$groupid") || 0;
# Legality of control combination is a function of # Legality of control combination is a function of
...@@ -567,14 +561,33 @@ if ($action eq 'updategroupcontrols') { ...@@ -567,14 +561,33 @@ if ($action eq 'updategroupcontrols') {
'bugs_activity WRITE', 'bugs_activity WRITE',
'bug_group_map WRITE', 'bug_group_map WRITE',
'fielddefs READ'); 'fielddefs READ');
SendSQL("SELECT id, name, entry, membercontrol, othercontrol, canedit " .
"FROM groups " . my $sth_Insert = $dbh->prepare('INSERT INTO group_control_map
"LEFT JOIN group_control_map " . (group_id, product_id, entry, membercontrol,
"ON group_control_map.group_id = id AND product_id = " . othercontrol, canedit)
$product->id . " WHERE isbuggroup != 0 AND isactive != 0"); VALUES (?, ?, ?, ?, ?, ?)');
while (MoreSQLData()) {
my $sth_Update = $dbh->prepare('UPDATE group_control_map
SET entry = ?, membercontrol = ?,
othercontrol = ?, canedit = ?
WHERE group_id = ? AND product_id = ?');
my $sth_Delete = $dbh->prepare('DELETE FROM group_control_map
WHERE group_id = ? AND product_id = ?');
$groups = $dbh->selectall_arrayref('SELECT id, name, entry, membercontrol,
othercontrol, canedit
FROM groups
LEFT JOIN group_control_map
ON group_control_map.group_id = id
AND product_id = ?
WHERE isbuggroup != 0
AND isactive != 0',
undef, $product->id);
foreach my $group (@$groups) {
my ($groupid, $groupname, $entry, $membercontrol, my ($groupid, $groupname, $entry, $membercontrol,
$othercontrol, $canedit) = FetchSQLData(); $othercontrol, $canedit) = @$group;
my $newentry = $cgi->param("entry_$groupid") || 0; my $newentry = $cgi->param("entry_$groupid") || 0;
my $newmembercontrol = $cgi->param("membercontrol_$groupid") || 0; my $newmembercontrol = $cgi->param("membercontrol_$groupid") || 0;
my $newothercontrol = $cgi->param("othercontrol_$groupid") || 0; my $newothercontrol = $cgi->param("othercontrol_$groupid") || 0;
...@@ -590,65 +603,63 @@ if ($action eq 'updategroupcontrols') { ...@@ -590,65 +603,63 @@ if ($action eq 'updategroupcontrols') {
detaint_natural($newcanedit); detaint_natural($newcanedit);
if ((!defined($oldentry)) && if ((!defined($oldentry)) &&
(($newentry) || ($newmembercontrol) || ($newcanedit))) { (($newentry) || ($newmembercontrol) || ($newcanedit))) {
PushGlobalSQLState(); $sth_Insert->execute($groupid, $product->id, $newentry,
SendSQL("INSERT INTO group_control_map " . $newmembercontrol, $newothercontrol, $newcanedit);
"(group_id, product_id, entry, " .
"membercontrol, othercontrol, canedit) " .
"VALUES " .
"($groupid, " . $product->id . ", $newentry, " .
"$newmembercontrol, $newothercontrol, $newcanedit)");
PopGlobalSQLState();
} elsif (($newentry != $entry) } elsif (($newentry != $entry)
|| ($newmembercontrol != $membercontrol) || ($newmembercontrol != $membercontrol)
|| ($newothercontrol != $othercontrol) || ($newothercontrol != $othercontrol)
|| ($newcanedit != $canedit)) { || ($newcanedit != $canedit)) {
PushGlobalSQLState(); $sth_Update->execute($newentry, $newmembercontrol, $newothercontrol,
SendSQL("UPDATE group_control_map " . $newcanedit, $groupid, $product->id);
"SET entry = $newentry, " .
"membercontrol = $newmembercontrol, " .
"othercontrol = $newothercontrol, " .
"canedit = $newcanedit " .
"WHERE group_id = $groupid " .
"AND product_id = " . $product->id);
PopGlobalSQLState();
} }
if (($newentry == 0) && ($newmembercontrol == 0) if (($newentry == 0) && ($newmembercontrol == 0)
&& ($newothercontrol == 0) && ($newcanedit == 0)) { && ($newothercontrol == 0) && ($newcanedit == 0)) {
PushGlobalSQLState(); $sth_Delete->execute($groupid, $product->id);
SendSQL("DELETE FROM group_control_map " .
"WHERE group_id = $groupid " .
"AND product_id = " . $product->id);
PopGlobalSQLState();
} }
} }
my $sth_Select = $dbh->prepare(
'SELECT bugs.bug_id,
CASE WHEN (lastdiffed >= delta_ts) THEN 1 ELSE 0 END
FROM bugs
INNER JOIN bug_group_map
ON bug_group_map.bug_id = bugs.bug_id
WHERE group_id = ?
AND bugs.product_id = ?
ORDER BY bugs.bug_id');
my $sth_Select2 = $dbh->prepare('SELECT name, NOW() FROM groups WHERE id = ?');
$sth_Update = $dbh->prepare('UPDATE bugs SET delta_ts = ? WHERE bug_id = ?');
my $sth_Update2 = $dbh->prepare('UPDATE bugs SET delta_ts = ?, lastdiffed = ?
WHERE bug_id = ?');
$sth_Delete = $dbh->prepare('DELETE FROM bug_group_map
WHERE bug_id = ? AND group_id = ?');
my @removed_na; my @removed_na;
foreach my $groupid (@now_na) { foreach my $groupid (@now_na) {
my $count = 0; my $count = 0;
SendSQL("SELECT bugs.bug_id, my $bugs = $dbh->selectall_arrayref($sth_Select, undef,
CASE WHEN (lastdiffed >= delta_ts) THEN 1 ELSE 0 END ($groupid, $product->id));
FROM bugs, bug_group_map
WHERE group_id = $groupid foreach my $bug (@$bugs) {
AND bug_group_map.bug_id = bugs.bug_id my ($bugid, $mailiscurrent) = @$bug;
AND bugs.product_id = " . $product->id . " $sth_Delete->execute($bugid, $groupid);
ORDER BY bugs.bug_id"); my ($removed, $timestamp) =
while (MoreSQLData()) { $dbh->selectrow_array($sth_Select2, undef, $groupid);
my ($bugid, $mailiscurrent) = FetchSQLData();
PushGlobalSQLState();
SendSQL("DELETE FROM bug_group_map WHERE
bug_id = $bugid AND group_id = $groupid");
SendSQL("SELECT name, NOW() FROM groups WHERE id = $groupid");
my ($removed, $timestamp) = FetchSQLData();
LogActivityEntry($bugid, "bug_group", $removed, "", LogActivityEntry($bugid, "bug_group", $removed, "",
$::userid, $timestamp); $::userid, $timestamp);
my $diffed = "";
if ($mailiscurrent) { if ($mailiscurrent) {
$diffed = ", lastdiffed = " . SqlQuote($timestamp); $sth_Update2->execute($timestamp, $timestamp, $bugid);
}
else {
$sth_Update->execute($timestamp, $bugid);
} }
SendSQL("UPDATE bugs SET delta_ts = " . SqlQuote($timestamp) .
$diffed . " WHERE bug_id = $bugid");
PopGlobalSQLState();
$count++; $count++;
} }
my %group = (name => GroupIdToName($groupid), my %group = (name => GroupIdToName($groupid),
...@@ -657,34 +668,41 @@ if ($action eq 'updategroupcontrols') { ...@@ -657,34 +668,41 @@ if ($action eq 'updategroupcontrols') {
push(@removed_na, \%group); push(@removed_na, \%group);
} }
my @added_mandatory; $sth_Select = $dbh->prepare(
foreach my $groupid (@now_mandatory) { 'SELECT bugs.bug_id,
my $count = 0;
SendSQL("SELECT bugs.bug_id,
CASE WHEN (lastdiffed >= delta_ts) THEN 1 ELSE 0 END CASE WHEN (lastdiffed >= delta_ts) THEN 1 ELSE 0 END
FROM bugs FROM bugs
LEFT JOIN bug_group_map LEFT JOIN bug_group_map
ON bug_group_map.bug_id = bugs.bug_id ON bug_group_map.bug_id = bugs.bug_id
AND group_id = $groupid AND group_id = ?
WHERE bugs.product_id = " . $product->id . " WHERE bugs.product_id = ?
AND bug_group_map.bug_id IS NULL AND bug_group_map.bug_id IS NULL
ORDER BY bugs.bug_id"); ORDER BY bugs.bug_id');
while (MoreSQLData()) {
my ($bugid, $mailiscurrent) = FetchSQLData(); $sth_Insert = $dbh->prepare('INSERT INTO bug_group_map
PushGlobalSQLState(); (bug_id, group_id) VALUES (?, ?)');
SendSQL("INSERT INTO bug_group_map (bug_id, group_id)
VALUES ($bugid, $groupid)"); my @added_mandatory;
SendSQL("SELECT name, NOW() FROM groups WHERE id = $groupid"); foreach my $groupid (@now_mandatory) {
my ($added, $timestamp) = FetchSQLData(); my $count = 0;
my $bugs = $dbh->selectall_arrayref($sth_Select, undef,
($groupid, $product->id));
foreach my $bug (@$bugs) {
my ($bugid, $mailiscurrent) = @$bug;
$sth_Insert->execute($bugid, $groupid);
my ($added, $timestamp) =
$dbh->selectrow_array($sth_Select2, undef, $groupid);
LogActivityEntry($bugid, "bug_group", "", $added, LogActivityEntry($bugid, "bug_group", "", $added,
$::userid, $timestamp); $::userid, $timestamp);
my $diffed = "";
if ($mailiscurrent) { if ($mailiscurrent) {
$diffed = ", lastdiffed = " . SqlQuote($timestamp); $sth_Update2->execute($timestamp, $timestamp, $bugid);
}
else {
$sth_Update->execute($timestamp, $bugid);
} }
SendSQL("UPDATE bugs SET delta_ts = " . SqlQuote($timestamp) .
$diffed . " WHERE bug_id = $bugid");
PopGlobalSQLState();
$count++; $count++;
} }
my %group = (name => GroupIdToName($groupid), my %group = (name => GroupIdToName($groupid),
...@@ -794,63 +812,53 @@ if ($action eq 'update') { ...@@ -794,63 +812,53 @@ if ($action eq 'update') {
$disallownew = $disallownew ? 1 : 0; $disallownew = $disallownew ? 1 : 0;
if ($disallownew ne $product_old->disallow_new) { if ($disallownew ne $product_old->disallow_new) {
SendSQL("UPDATE products $dbh->do('UPDATE products SET disallownew = ? WHERE id = ?',
SET disallownew=$disallownew undef, ($disallownew, $product_old->id));
WHERE id = " . $product_old->id);
} }
if ($description ne $product_old->description) { if ($description ne $product_old->description) {
SendSQL("UPDATE products trick_taint($description);
SET description=" . SqlQuote($description) . " $dbh->do('UPDATE products SET description = ? WHERE id = ?',
WHERE id = " . $product_old->id); undef, ($description, $product_old->id));
} }
if (Param('usetargetmilestone') if (Param('usetargetmilestone')
&& ($milestoneurl ne $product_old->milestone_url)) { && ($milestoneurl ne $product_old->milestone_url)) {
SendSQL("UPDATE products trick_taint($milestoneurl);
SET milestoneurl=" . SqlQuote($milestoneurl) . " $dbh->do('UPDATE products SET milestoneurl = ? WHERE id = ?',
WHERE id = " . $product_old->id); undef, ($milestoneurl, $product_old->id));
} }
if ($votesperuser ne $product_old->votes_per_user) { if ($votesperuser ne $product_old->votes_per_user) {
SendSQL("UPDATE products $dbh->do('UPDATE products SET votesperuser = ? WHERE id = ?',
SET votesperuser=$votesperuser undef, ($votesperuser, $product_old->id));
WHERE id = " . $product_old->id);
$checkvotes = 1; $checkvotes = 1;
} }
if ($maxvotesperbug ne $product_old->max_votes_per_bug) { if ($maxvotesperbug ne $product_old->max_votes_per_bug) {
SendSQL("UPDATE products $dbh->do('UPDATE products SET maxvotesperbug = ? WHERE id = ?',
SET maxvotesperbug=$maxvotesperbug undef, ($maxvotesperbug, $product_old->id));
WHERE id = " . $product_old->id);
$checkvotes = 1; $checkvotes = 1;
} }
if ($votestoconfirm ne $product_old->votes_to_confirm) { if ($votestoconfirm ne $product_old->votes_to_confirm) {
SendSQL("UPDATE products $dbh->do('UPDATE products SET votestoconfirm = ? WHERE id = ?',
SET votestoconfirm=$votestoconfirm undef, ($votestoconfirm, $product_old->id));
WHERE id = " . $product_old->id);
$checkvotes = 1; $checkvotes = 1;
} }
if ($defaultmilestone ne $product_old->default_milestone) { if ($defaultmilestone ne $product_old->default_milestone) {
SendSQL("UPDATE products " . trick_taint($defaultmilestone);
"SET defaultmilestone = " . SqlQuote($defaultmilestone) . $dbh->do('UPDATE products SET defaultmilestone = ? WHERE id = ?',
"WHERE id = " . $product_old->id); undef, ($defaultmilestone, $product_old->id));
} }
my $qp = SqlQuote($product_name);
if ($product_name ne $product_old->name) { if ($product_name ne $product_old->name) {
SendSQL("UPDATE products SET name=$qp WHERE id= ".$product_old->id); trick_taint($product_name);
$dbh->do('UPDATE products SET name = ? WHERE id = ?',
undef, ($product_name, $product_old->id));
} }
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
unlink "$datadir/versioncache"; unlink "$datadir/versioncache";
...@@ -862,44 +870,44 @@ if ($action eq 'update') { ...@@ -862,44 +870,44 @@ if ($action eq 'update') {
# 1. too many votes for a single user on a single bug. # 1. too many votes for a single user on a single bug.
my @toomanyvotes_list = (); my @toomanyvotes_list = ();
if ($maxvotesperbug < $votesperuser) { if ($maxvotesperbug < $votesperuser) {
my $votes = $dbh->selectall_arrayref(
SendSQL("SELECT votes.who, votes.bug_id " . 'SELECT votes.who, votes.bug_id
"FROM votes, bugs " . FROM votes
"WHERE bugs.bug_id = votes.bug_id " . INNER JOIN bugs
" AND bugs.product_id = " . $product->id . ON bugs.bug_id = votes.bug_id
" AND votes.vote_count > $maxvotesperbug"); WHERE bugs.product_id = ?
my @list; AND votes.vote_count > ?',
while (MoreSQLData()) { undef, ($product->id, $maxvotesperbug));
my ($who, $id) = (FetchSQLData());
push(@list, [$who, $id]); foreach my $vote (@$votes) {
} my ($who, $id) = (@$vote);
RemoveVotes($id, $who, "The rules for voting on this product " .
"has changed;\nyou had too many votes " .
foreach my $ref (@list) { "for a single bug.");
my ($who, $id) = (@$ref);
RemoveVotes($id, $who, "The rules for voting on this product has changed;\nyou had too many votes for a single bug.");
my $name = DBID_to_name($who); my $name = DBID_to_name($who);
push(@toomanyvotes_list, push(@toomanyvotes_list,
{id => $id, name => $name}); {id => $id, name => $name});
} }
} }
$vars->{'toomanyvotes'} = \@toomanyvotes_list; $vars->{'toomanyvotes'} = \@toomanyvotes_list;
# 2. too many total votes for a single user. # 2. too many total votes for a single user.
# This part doesn't work in the general case because RemoveVotes # This part doesn't work in the general case because RemoveVotes
# doesn't enforce votesperuser (except per-bug when it's less # doesn't enforce votesperuser (except per-bug when it's less
# than maxvotesperbug). See RemoveVotes in globals.pl. # than maxvotesperbug). See Bugzilla::Bug::RemoveVotes().
my $votes = $dbh->selectall_arrayref(
'SELECT votes.who, votes.vote_count
FROM votes
INNER JOIN bugs
ON bugs.bug_id = votes.bug_id
WHERE bugs.product_id = ?',
undef, $product->id);
SendSQL("SELECT votes.who, votes.vote_count FROM votes, bugs " .
"WHERE bugs.bug_id = votes.bug_id " .
" AND bugs.product_id = " . $product->id);
my %counts; my %counts;
while (MoreSQLData()) { foreach my $vote (@$votes) {
my ($who, $count) = (FetchSQLData()); my ($who, $count) = @$vote;
if (!defined $counts{$who}) { if (!defined $counts{$who}) {
$counts{$who} = $count; $counts{$who} = $count;
} else { } else {
...@@ -909,25 +917,32 @@ if ($action eq 'update') { ...@@ -909,25 +917,32 @@ if ($action eq 'update') {
my @toomanytotalvotes_list = (); my @toomanytotalvotes_list = ();
foreach my $who (keys(%counts)) { foreach my $who (keys(%counts)) {
if ($counts{$who} > $votesperuser) { if ($counts{$who} > $votesperuser) {
SendSQL("SELECT votes.bug_id FROM votes, bugs " . my $bug_ids = $dbh->selectcol_arrayref(
"WHERE bugs.bug_id = votes.bug_id " . 'SELECT votes.bug_id
" AND bugs.product_id = " . $product->id . FROM votes
" AND votes.who = $who"); INNER JOIN bugs
while (MoreSQLData()) { ON bugs.bug_id = votes.bug_id
my ($id) = FetchSQLData(); WHERE bugs.product_id = ?
RemoveVotes($id, $who, AND votes.who = ?',
"The rules for voting on this product has changed; you had too many\ntotal votes, so all votes have been removed."); undef, ($product->id, $who));
foreach my $bug_id (@$bug_ids) {
RemoveVotes($bug_id, $who, "The rules for voting on this " .
"product has changed; you had " .
"too many\ntotal votes, so all " .
"votes have been removed.");
my $name = DBID_to_name($who); my $name = DBID_to_name($who);
push(@toomanytotalvotes_list, push(@toomanytotalvotes_list,
{id => $id, name => $name}); {id => $bug_id, name => $name});
} }
} }
} }
$vars->{'toomanytotalvotes'} = \@toomanytotalvotes_list; $vars->{'toomanytotalvotes'} = \@toomanytotalvotes_list;
# 3. enough votes to confirm # 3. enough votes to confirm
my $bug_list = $dbh->selectcol_arrayref("SELECT bug_id FROM bugs my $bug_list = $dbh->selectcol_arrayref(
"SELECT bug_id FROM bugs
WHERE product_id = ? WHERE product_id = ?
AND bug_status = 'UNCONFIRMED' AND bug_status = 'UNCONFIRMED'
AND votes >= ?", AND votes >= ?",
...@@ -941,7 +956,6 @@ if ($action eq 'update') { ...@@ -941,7 +956,6 @@ if ($action eq 'update') {
$vars->{'confirmedbugs'} = \@updated_bugs; $vars->{'confirmedbugs'} = \@updated_bugs;
$vars->{'changer'} = $whoid; $vars->{'changer'} = $whoid;
} }
$vars->{'old_product'} = $product_old; $vars->{'old_product'} = $product_old;
...@@ -949,7 +963,6 @@ if ($action eq 'update') { ...@@ -949,7 +963,6 @@ if ($action eq 'update') {
$template->process("admin/products/updated.html.tmpl", $vars) $template->process("admin/products/updated.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
...@@ -960,40 +973,26 @@ if ($action eq 'update') { ...@@ -960,40 +973,26 @@ if ($action eq 'update') {
if ($action eq 'editgroupcontrols') { if ($action eq 'editgroupcontrols') {
my $product = Bugzilla::Product::check_product($product_name); my $product = Bugzilla::Product::check_product($product_name);
# Display a group if it is either enabled or has bugs for this product. # Display a group if it is either enabled or has bugs for this product.
SendSQL("SELECT id, name, entry, membercontrol, othercontrol, canedit, " . my $groups = $dbh->selectall_arrayref(
"isactive, COUNT(bugs.bug_id) " . 'SELECT id, name, entry, membercontrol, othercontrol, canedit,
"FROM groups " . isactive, COUNT(bugs.bug_id) AS bugcount
"LEFT JOIN group_control_map " . FROM groups
"ON group_control_map.group_id = id " . LEFT JOIN group_control_map
"AND group_control_map.product_id = " . $product->id . ON group_control_map.group_id = groups.id
" LEFT JOIN bug_group_map " . AND group_control_map.product_id = ?
"ON bug_group_map.group_id = groups.id " . LEFT JOIN bug_group_map
"LEFT JOIN bugs " . ON bug_group_map.group_id = groups.id
"ON bugs.bug_id = bug_group_map.bug_id " . LEFT JOIN bugs
"AND bugs.product_id = " . $product->id . ON bugs.bug_id = bug_group_map.bug_id
" WHERE isbuggroup != 0 " . AND bugs.product_id = ?
"AND (isactive != 0 OR entry IS NOT NULL " . WHERE isbuggroup != 0
"OR bugs.bug_id IS NOT NULL) " . AND (isactive != 0 OR entry IS NOT NULL OR bugs.bug_id IS NOT NULL) ' .
$dbh->sql_group_by('name', 'id, entry, membercontrol, $dbh->sql_group_by('name', 'id, entry, membercontrol,
othercontrol, canedit, isactive')); othercontrol, canedit, isactive'),
my @groups = (); {'Slice' => {}}, ($product->id, $product->id));
while (MoreSQLData()) {
my %group = ();
my ($groupid, $groupname, $entry, $membercontrol, $othercontrol,
$canedit, $isactive, $bugcount) = FetchSQLData();
$group{'id'} = $groupid;
$group{'name'} = $groupname;
$group{'entry'} = $entry;
$group{'membercontrol'} = $membercontrol;
$group{'othercontrol'} = $othercontrol;
$group{'canedit'} = $canedit;
$group{'isactive'} = $isactive;
$group{'bugcount'} = $bugcount;
push @groups,\%group;
}
$vars->{'product'} = $product;
$vars->{'groups'} = \@groups; $vars->{'product'} = $product;
$vars->{'groups'} = $groups;
$vars->{'const'} = { $vars->{'const'} = {
'CONTROLMAPNA' => CONTROLMAPNA, 'CONTROLMAPNA' => CONTROLMAPNA,
......
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