[aur-dev] [PATCH 1/2] Fix pkgbase_user_voted()
pkgbase_user_voted() should expect a package base ID, not a package ID. Change the SQL query accordingly. This fixes the vote status on package base pages. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgbasefuncs.inc.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index c55bd89..4e026f5 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -703,28 +703,24 @@ function pkgbase_votes_from_name($pkgname) { } /** - * Determine if a user has already voted for a specific package + * Determine if a user has already voted for a specific package base * * @param string $uid The user ID to check for an existing vote - * @param string $pkgid The package ID to check for an existing vote + * @param string $base_id The package base ID to check for an existing vote * * @return bool True if the user has already voted, otherwise false */ -function pkgbase_user_voted($uid, $pkgid) { +function pkgbase_user_voted($uid, $base_id) { $dbh = DB::connect(); - - $q = "SELECT * FROM PackageVotes, Packages WHERE "; - $q.= "PackageVotes.UsersID = ". $dbh->quote($uid) . " AND "; - $q.= "PackageVotes.PackageBaseID = Packages.PackageBaseID AND "; - $q.= "Packages.ID = " . $dbh->quote($pkgid); + $q = "SELECT COUNT(*) FROM PackageVotes WHERE "; + $q.= "UsersID = ". $dbh->quote($uid) . " AND "; + $q.= "PackageBaseID = " . $dbh->quote($base_id); $result = $dbh->query($q); - - if ($result->fetch(PDO::FETCH_NUM)) { - return true; - } - else { - return false; + if (!$result) { + return null; } + + return ($result->fetch(PDO::FETCH_COLUMN, 0) > 0); } /** -- 1.9.1
All pkgbase_*() functions should operate on package base IDs. Drop the superfluous (and incorrect) parameter conversion from package IDs to package base IDs. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgbasefuncs.inc.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 4e026f5..4eaa640 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -350,7 +350,7 @@ function pkgbase_flag($atype, $base_ids) { return array(false, __("You must be logged in before you can flag packages.")); } - $base_ids = pkgbase_from_pkgid($base_ids); + $base_ids = sanitize_ids($base_ids); if (empty($base_ids)) { return array(false, __("You did not select any packages to flag.")); } @@ -406,7 +406,7 @@ function pkgbase_unflag($atype, $base_ids) { return array(false, __("You must be logged in before you can unflag packages.")); } - $base_ids = pkgbase_from_pkgid($base_ids); + $base_ids = sanitize_ids($base_ids); if (empty($base_ids)) { return array(false, __("You did not select any packages to unflag.")); } @@ -856,13 +856,14 @@ function pkgbase_delete_comment($atype) { } /** - * Change package category + * Change package base category * + * @param int Package base ID of the package base to modify * @param string $atype Account type, output of account_from_sid * * @return array Tuple of success/failure indicator and error message */ -function pkgbase_change_category($pid, $atype) { +function pkgbase_change_category($base_id, $atype) { if (!$atype) { return array(false, __("You must be logged in before you can edit package information.")); } @@ -879,7 +880,7 @@ function pkgbase_change_category($pid, $atype) { return array(false, __("Invalid category ID.")); } - $base_id = pkgbase_from_pkgid($pid); + $base_id = intval($base_id); /* Verify package ownership. */ $q = "SELECT MaintainerUID FROM PackageBases WHERE ID = " . $base_id; -- 1.9.1
participants (1)
-
Lukas Fleischer