Do not trigger a PHP warning if there are no votes to be added or removed. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/pkgbasefuncs.inc.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index b20c2ff..cd4b271 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -735,6 +735,8 @@ function pkgbase_vote ($base_ids, $action=true) { $uid = uid_from_sid($_COOKIE["AURSID"]); $first = 1; + $vote_ids = ""; + $vote_clauses = ""; foreach ($base_ids as $pid) { if ($action) { $check = !isset($my_votes[$pid]); @@ -758,22 +760,24 @@ function pkgbase_vote ($base_ids, $action=true) { } } - /* Only add votes for packages the user hasn't already voted for. */ - $op = $action ? "+" : "-"; - $q = "UPDATE PackageBases SET NumVotes = NumVotes $op 1 "; - $q.= "WHERE ID IN ($vote_ids)"; + if (!empty($vote_ids)) { + /* Only add votes for packages the user hasn't already voted for. */ + $op = $action ? "+" : "-"; + $q = "UPDATE PackageBases SET NumVotes = NumVotes $op 1 "; + $q.= "WHERE ID IN ($vote_ids)"; - $dbh->exec($q); + $dbh->exec($q); - if ($action) { - $q = "INSERT INTO PackageVotes (UsersID, PackageBaseID, VoteTS) VALUES "; - $q.= $vote_clauses; - } else { - $q = "DELETE FROM PackageVotes WHERE UsersID = $uid "; - $q.= "AND PackageBaseID IN ($vote_ids)"; - } + if ($action) { + $q = "INSERT INTO PackageVotes (UsersID, PackageBaseID, VoteTS) VALUES "; + $q.= $vote_clauses; + } else { + $q = "DELETE FROM PackageVotes WHERE UsersID = $uid "; + $q.= "AND PackageBaseID IN ($vote_ids)"; + } - $dbh->exec($q); + $dbh->exec($q); + } if ($action) { return array(true, __("Your votes have been cast for the selected packages.")); -- 2.12.0