diff options
author | Lukas Fleischer <lfleischer@archlinux.org> | 2017-02-27 20:09:15 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2017-02-27 20:11:15 +0100 |
commit | 06cf067d4f135a5ec1e36e3316e2b8b75644a86d (patch) | |
tree | 74cac5d501a29ebd2435200cf58676f7fecf17bf /web | |
parent | 92f140c5ca121bcde0bb3cb283075e151f865d0d (diff) | |
download | aur-06cf067d4f135a5ec1e36e3316e2b8b75644a86d.tar.gz aur-06cf067d4f135a5ec1e36e3316e2b8b75644a86d.tar.xz |
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>
Diffstat (limited to 'web')
-rw-r--r-- | web/lib/pkgbasefuncs.inc.php | 30 |
1 files 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.")); |