Squelch warning in pkgbase_vote()

Do not trigger a PHP warning if there are no votes to be added or
removed.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2017-02-27 20:09:15 +01:00
parent 92f140c5ca
commit 06cf067d4f

View file

@ -735,6 +735,8 @@ function pkgbase_vote ($base_ids, $action=true) {
$uid = uid_from_sid($_COOKIE["AURSID"]); $uid = uid_from_sid($_COOKIE["AURSID"]);
$first = 1; $first = 1;
$vote_ids = "";
$vote_clauses = "";
foreach ($base_ids as $pid) { foreach ($base_ids as $pid) {
if ($action) { if ($action) {
$check = !isset($my_votes[$pid]); $check = !isset($my_votes[$pid]);
@ -758,23 +760,25 @@ function pkgbase_vote ($base_ids, $action=true) {
} }
} }
/* Only add votes for packages the user hasn't already voted for. */ if (!empty($vote_ids)) {
$op = $action ? "+" : "-"; /* Only add votes for packages the user hasn't already voted for. */
$q = "UPDATE PackageBases SET NumVotes = NumVotes $op 1 "; $op = $action ? "+" : "-";
$q.= "WHERE ID IN ($vote_ids)"; $q = "UPDATE PackageBases SET NumVotes = NumVotes $op 1 ";
$q.= "WHERE ID IN ($vote_ids)";
$dbh->exec($q); $dbh->exec($q);
if ($action) { if ($action) {
$q = "INSERT INTO PackageVotes (UsersID, PackageBaseID, VoteTS) VALUES "; $q = "INSERT INTO PackageVotes (UsersID, PackageBaseID, VoteTS) VALUES ";
$q.= $vote_clauses; $q.= $vote_clauses;
} else { } else {
$q = "DELETE FROM PackageVotes WHERE UsersID = $uid "; $q = "DELETE FROM PackageVotes WHERE UsersID = $uid ";
$q.= "AND PackageBaseID IN ($vote_ids)"; $q.= "AND PackageBaseID IN ($vote_ids)";
}
$dbh->exec($q);
} }
$dbh->exec($q);
if ($action) { if ($action) {
return array(true, __("Your votes have been cast for the selected packages.")); return array(true, __("Your votes have been cast for the selected packages."));
} else { } else {