From 06cf067d4f135a5ec1e36e3316e2b8b75644a86d Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 27 Feb 2017 20:09:15 +0100 Subject: 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 --- 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 b20c2ffb..cd4b2713 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.")); -- cgit v1.2.3-24-g4f1b