mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Add boolean return values to several pkg_*() functions
Change the return values of following functions to return both error/success and an error/success message: * pkg_flag() * pkg_unflag() * pkg_adopt() * pkg_vote() * pkg_delete() * pkg_notify() * pkg_delete_comment() * pkg_change_category() Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
parent
86d2efaaa0
commit
23867a211c
2 changed files with 55 additions and 54 deletions
|
@ -54,30 +54,31 @@ if (isset($_POST['IDs'])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine what action to do
|
# Determine what action to do
|
||||||
|
$ret = false;
|
||||||
$output = "";
|
$output = "";
|
||||||
if (check_token()) {
|
if (check_token()) {
|
||||||
if (current_action("do_Flag")) {
|
if (current_action("do_Flag")) {
|
||||||
$output = pkg_flag($atype, $ids);
|
list($ret, $output) = pkg_flag($atype, $ids);
|
||||||
} elseif (current_action("do_UnFlag")) {
|
} elseif (current_action("do_UnFlag")) {
|
||||||
$output = pkg_unflag($atype, $ids);
|
list($ret, $output) = pkg_unflag($atype, $ids);
|
||||||
} elseif (current_action("do_Adopt")) {
|
} elseif (current_action("do_Adopt")) {
|
||||||
$output = pkg_adopt($atype, $ids, true);
|
list($ret, $output) = pkg_adopt($atype, $ids, true);
|
||||||
} elseif (current_action("do_Disown")) {
|
} elseif (current_action("do_Disown")) {
|
||||||
$output = pkg_adopt($atype, $ids, False);
|
list($ret, $output) = pkg_adopt($atype, $ids, False);
|
||||||
} elseif (current_action("do_Vote")) {
|
} elseif (current_action("do_Vote")) {
|
||||||
$output = pkg_vote($atype, $ids, true);
|
list($ret, $output) = pkg_vote($atype, $ids, true);
|
||||||
} elseif (current_action("do_UnVote")) {
|
} elseif (current_action("do_UnVote")) {
|
||||||
$output = pkg_vote($atype, $ids, False);
|
list($ret, $output) = pkg_vote($atype, $ids, False);
|
||||||
} elseif (current_action("do_Delete")) {
|
} elseif (current_action("do_Delete")) {
|
||||||
if (isset($_POST['confirm_Delete'])) {
|
if (isset($_POST['confirm_Delete'])) {
|
||||||
if (!isset($_POST['merge_Into']) || empty($_POST['merge_Into'])) {
|
if (!isset($_POST['merge_Into']) || empty($_POST['merge_Into'])) {
|
||||||
$output = pkg_delete($atype, $ids, NULL);
|
list($ret, $output) = pkg_delete($atype, $ids, NULL);
|
||||||
unset($_GET['ID']);
|
unset($_GET['ID']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$mergepkgid = pkgid_from_name($_POST['merge_Into']);
|
$mergepkgid = pkgid_from_name($_POST['merge_Into']);
|
||||||
if ($mergepkgid) {
|
if ($mergepkgid) {
|
||||||
$output = pkg_delete($atype, $ids, $mergepkgid);
|
list($ret, $output) = pkg_delete($atype, $ids, $mergepkgid);
|
||||||
unset($_GET['ID']);
|
unset($_GET['ID']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -89,13 +90,13 @@ if (check_token()) {
|
||||||
$output = __("The selected packages have not been deleted, check the confirmation checkbox.");
|
$output = __("The selected packages have not been deleted, check the confirmation checkbox.");
|
||||||
}
|
}
|
||||||
} elseif (current_action("do_Notify")) {
|
} elseif (current_action("do_Notify")) {
|
||||||
$output = pkg_notify($atype, $ids);
|
list($ret, $output) = pkg_notify($atype, $ids);
|
||||||
} elseif (current_action("do_UnNotify")) {
|
} elseif (current_action("do_UnNotify")) {
|
||||||
$output = pkg_notify($atype, $ids, False);
|
list($ret, $output) = pkg_notify($atype, $ids, False);
|
||||||
} elseif (current_action("do_DeleteComment")) {
|
} elseif (current_action("do_DeleteComment")) {
|
||||||
$output = pkg_delete_comment($atype);
|
list($ret, $output) = pkg_delete_comment($atype);
|
||||||
} elseif (current_action("do_ChangeCategory")) {
|
} elseif (current_action("do_ChangeCategory")) {
|
||||||
$output = pkg_change_category($pkgid, $atype);
|
list($ret, $output) = pkg_change_category($pkgid, $atype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -752,18 +752,18 @@ function sanitize_ids($ids) {
|
||||||
* @param string $atype Account type, output of account_from_sid
|
* @param string $atype Account type, output of account_from_sid
|
||||||
* @param array $ids Array of package IDs to flag/unflag
|
* @param array $ids Array of package IDs to flag/unflag
|
||||||
*
|
*
|
||||||
* @return string Translated success or error messages
|
* @return array Tuple of success/failure indicator and error message
|
||||||
*/
|
*/
|
||||||
function pkg_flag($atype, $ids) {
|
function pkg_flag($atype, $ids) {
|
||||||
global $AUR_LOCATION;
|
global $AUR_LOCATION;
|
||||||
|
|
||||||
if (!$atype) {
|
if (!$atype) {
|
||||||
return __("You must be logged in before you can flag packages.");
|
return array(false, __("You must be logged in before you can flag packages."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids = sanitize_ids($ids);
|
$ids = sanitize_ids($ids);
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return __("You did not select any packages to flag.");
|
return array(false, __("You did not select any packages to flag."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbh = DB::connect();
|
$dbh = DB::connect();
|
||||||
|
@ -797,7 +797,7 @@ function pkg_flag($atype, $ids) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return __("The selected packages have been flagged out-of-date.");
|
return array(true, __("The selected packages have been flagged out-of-date."));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -806,16 +806,16 @@ function pkg_flag($atype, $ids) {
|
||||||
* @param string $atype Account type, output of account_from_sid
|
* @param string $atype Account type, output of account_from_sid
|
||||||
* @param array $ids Array of package IDs to flag/unflag
|
* @param array $ids Array of package IDs to flag/unflag
|
||||||
*
|
*
|
||||||
* @return string Translated success or error messages
|
* @return array Tuple of success/failure indicator and error message
|
||||||
*/
|
*/
|
||||||
function pkg_unflag($atype, $ids) {
|
function pkg_unflag($atype, $ids) {
|
||||||
if (!$atype) {
|
if (!$atype) {
|
||||||
return __("You must be logged in before you can unflag packages.");
|
return array(false, __("You must be logged in before you can unflag packages."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids = sanitize_ids($ids);
|
$ids = sanitize_ids($ids);
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return __("You did not select any packages to unflag.");
|
return array(false, __("You did not select any packages to unflag."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbh = DB::connect();
|
$dbh = DB::connect();
|
||||||
|
@ -831,7 +831,7 @@ function pkg_unflag($atype, $ids) {
|
||||||
$result = $dbh->exec($q);
|
$result = $dbh->exec($q);
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return __("The selected packages have been unflagged.");
|
return array(true, __("The selected packages have been unflagged."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -842,21 +842,21 @@ function pkg_unflag($atype, $ids) {
|
||||||
* @param array $ids Array of package IDs to delete
|
* @param array $ids Array of package IDs to delete
|
||||||
* @param int $mergepkgid Package to merge the deleted ones into
|
* @param int $mergepkgid Package to merge the deleted ones into
|
||||||
*
|
*
|
||||||
* @return string Translated error or success message
|
* @return array Tuple of success/failure indicator and error message
|
||||||
*/
|
*/
|
||||||
function pkg_delete ($atype, $ids, $mergepkgid) {
|
function pkg_delete ($atype, $ids, $mergepkgid) {
|
||||||
if (!$atype) {
|
if (!$atype) {
|
||||||
return __("You must be logged in before you can delete packages.");
|
return array(false, __("You must be logged in before you can delete packages."));
|
||||||
}
|
}
|
||||||
|
|
||||||
# If they're a TU or dev, can delete
|
# If they're a TU or dev, can delete
|
||||||
if ($atype != "Trusted User" && $atype != "Developer") {
|
if ($atype != "Trusted User" && $atype != "Developer") {
|
||||||
return __("You do not have permission to delete packages.");
|
return array(false, __("You do not have permission to delete packages."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids = sanitize_ids($ids);
|
$ids = sanitize_ids($ids);
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return __("You did not select any packages to delete.");
|
return array(false, __("You did not select any packages to delete."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbh = DB::connect();
|
$dbh = DB::connect();
|
||||||
|
@ -929,7 +929,7 @@ function pkg_delete ($atype, $ids, $mergepkgid) {
|
||||||
$q = "DELETE FROM Packages WHERE ID IN (" . implode(",", $ids) . ")";
|
$q = "DELETE FROM Packages WHERE ID IN (" . implode(",", $ids) . ")";
|
||||||
$result = $dbh->exec($q);
|
$result = $dbh->exec($q);
|
||||||
|
|
||||||
return __("The selected packages have been deleted.");
|
return array(true, __("The selected packages have been deleted."));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -939,23 +939,23 @@ function pkg_delete ($atype, $ids, $mergepkgid) {
|
||||||
* @param array $ids Array of package IDs to adopt/disown
|
* @param array $ids Array of package IDs to adopt/disown
|
||||||
* @param bool $action Adopts if true, disowns if false. Adopts by default
|
* @param bool $action Adopts if true, disowns if false. Adopts by default
|
||||||
*
|
*
|
||||||
* @return string Translated error or success message
|
* @return array Tuple of success/failure indicator and error message
|
||||||
*/
|
*/
|
||||||
function pkg_adopt ($atype, $ids, $action=true) {
|
function pkg_adopt ($atype, $ids, $action=true) {
|
||||||
if (!$atype) {
|
if (!$atype) {
|
||||||
if ($action) {
|
if ($action) {
|
||||||
return __("You must be logged in before you can adopt packages.");
|
return array(false, __("You must be logged in before you can adopt packages."));
|
||||||
} else {
|
} else {
|
||||||
return __("You must be logged in before you can disown packages.");
|
return array(false, __("You must be logged in before you can disown packages."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids = sanitize_ids($ids);
|
$ids = sanitize_ids($ids);
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
if ($action) {
|
if ($action) {
|
||||||
return __("You did not select any packages to adopt.");
|
return array(false, __("You did not select any packages to adopt."));
|
||||||
} else {
|
} else {
|
||||||
return __("You did not select any packages to disown.");
|
return array(false, __("You did not select any packages to disown."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -984,9 +984,9 @@ function pkg_adopt ($atype, $ids, $action=true) {
|
||||||
|
|
||||||
if ($action) {
|
if ($action) {
|
||||||
pkg_notify(account_from_sid($_COOKIE["AURSID"]), $ids);
|
pkg_notify(account_from_sid($_COOKIE["AURSID"]), $ids);
|
||||||
return __("The selected packages have been adopted.");
|
return array(true, __("The selected packages have been adopted."));
|
||||||
} else {
|
} else {
|
||||||
return __("The selected packages have been disowned.");
|
return array(true, __("The selected packages have been disowned."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,23 +997,23 @@ function pkg_adopt ($atype, $ids, $action=true) {
|
||||||
* @param array $ids Array of package IDs to vote/un-vote
|
* @param array $ids Array of package IDs to vote/un-vote
|
||||||
* @param bool $action Votes if true, un-votes if false. Votes by default
|
* @param bool $action Votes if true, un-votes if false. Votes by default
|
||||||
*
|
*
|
||||||
* @return string Translated error or success message
|
* @return array Tuple of success/failure indicator and error message
|
||||||
*/
|
*/
|
||||||
function pkg_vote ($atype, $ids, $action=true) {
|
function pkg_vote ($atype, $ids, $action=true) {
|
||||||
if (!$atype) {
|
if (!$atype) {
|
||||||
if ($action) {
|
if ($action) {
|
||||||
return __("You must be logged in before you can vote for packages.");
|
return array(false, __("You must be logged in before you can vote for packages."));
|
||||||
} else {
|
} else {
|
||||||
return __("You must be logged in before you can un-vote for packages.");
|
return array(false, __("You must be logged in before you can un-vote for packages."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ids = sanitize_ids($ids);
|
$ids = sanitize_ids($ids);
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
if ($action) {
|
if ($action) {
|
||||||
return __("You did not select any packages to vote for.");
|
return array(false, __("You did not select any packages to vote for."));
|
||||||
} else {
|
} else {
|
||||||
return __("Your votes have been removed from the selected packages.");
|
return array(false, __("Your votes have been removed from the selected packages."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1070,9 +1070,9 @@ function pkg_vote ($atype, $ids, $action=true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action) {
|
if ($action) {
|
||||||
return __("Your votes have been cast for the selected packages.");
|
return array(true, __("Your votes have been cast for the selected packages."));
|
||||||
} else {
|
} else {
|
||||||
return __("Your votes have been removed from the selected packages.");
|
return array(true, __("Your votes have been removed from the selected packages."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1156,7 +1156,7 @@ function user_notify($uid, $pkgid) {
|
||||||
* @param string $atype Account type, output of account_from_sid
|
* @param string $atype Account type, output of account_from_sid
|
||||||
* @param array $ids Array of package IDs to toggle, formatted as $package_id
|
* @param array $ids Array of package IDs to toggle, formatted as $package_id
|
||||||
*
|
*
|
||||||
* @return string Translated error or success message
|
* @return array Tuple of success/failure indicator and error message
|
||||||
*/
|
*/
|
||||||
function pkg_notify ($atype, $ids, $action=true) {
|
function pkg_notify ($atype, $ids, $action=true) {
|
||||||
if (!$atype) {
|
if (!$atype) {
|
||||||
|
@ -1166,7 +1166,7 @@ function pkg_notify ($atype, $ids, $action=true) {
|
||||||
|
|
||||||
$ids = sanitize_ids($ids);
|
$ids = sanitize_ids($ids);
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return __("Couldn't add to notification list.");
|
return array(false, __("Couldn't add to notification list."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbh = DB::connect();
|
$dbh = DB::connect();
|
||||||
|
@ -1224,7 +1224,7 @@ function pkg_notify ($atype, $ids, $action=true) {
|
||||||
$output = __("You have been removed from the comment notification list for %s.", $output);
|
$output = __("You have been removed from the comment notification list for %s.", $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return array(true, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1232,18 +1232,18 @@ function pkg_notify ($atype, $ids, $action=true) {
|
||||||
*
|
*
|
||||||
* @param string $atype Account type, output of account_from_sid
|
* @param string $atype Account type, output of account_from_sid
|
||||||
*
|
*
|
||||||
* @return string Translated error or success message
|
* @return array Tuple of success/failure indicator and error message
|
||||||
*/
|
*/
|
||||||
function pkg_delete_comment($atype) {
|
function pkg_delete_comment($atype) {
|
||||||
if (!$atype) {
|
if (!$atype) {
|
||||||
return __("You must be logged in before you can edit package information.");
|
return array(false, __("You must be logged in before you can edit package information."));
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get ID of comment to be removed
|
# Get ID of comment to be removed
|
||||||
if (isset($_POST["comment_id"])) {
|
if (isset($_POST["comment_id"])) {
|
||||||
$comment_id = $_POST["comment_id"];
|
$comment_id = $_POST["comment_id"];
|
||||||
} else {
|
} else {
|
||||||
return __("Missing comment ID.");
|
return array(false, __("Missing comment ID."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbh = DB::connect();
|
$dbh = DB::connect();
|
||||||
|
@ -1253,9 +1253,9 @@ function pkg_delete_comment($atype) {
|
||||||
$q.= "SET DelUsersID = ".$uid." ";
|
$q.= "SET DelUsersID = ".$uid." ";
|
||||||
$q.= "WHERE ID = ".intval($comment_id);
|
$q.= "WHERE ID = ".intval($comment_id);
|
||||||
$dbh->exec($q);
|
$dbh->exec($q);
|
||||||
return __("Comment has been deleted.");
|
return array(true, __("Comment has been deleted."));
|
||||||
} else {
|
} else {
|
||||||
return __("You are not allowed to delete this comment.");
|
return array(false, __("You are not allowed to delete this comment."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1264,24 +1264,24 @@ function pkg_delete_comment($atype) {
|
||||||
*
|
*
|
||||||
* @param string $atype Account type, output of account_from_sid
|
* @param string $atype Account type, output of account_from_sid
|
||||||
*
|
*
|
||||||
* @return string Translated error or success message
|
* @return array Tuple of success/failure indicator and error message
|
||||||
*/
|
*/
|
||||||
function pkg_change_category($pid, $atype) {
|
function pkg_change_category($pid, $atype) {
|
||||||
if (!$atype) {
|
if (!$atype) {
|
||||||
return __("You must be logged in before you can edit package information.");
|
return array(false, __("You must be logged in before you can edit package information."));
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get ID of the new category
|
# Get ID of the new category
|
||||||
if (isset($_POST["category_id"])) {
|
if (isset($_POST["category_id"])) {
|
||||||
$category_id = $_POST["category_id"];
|
$category_id = $_POST["category_id"];
|
||||||
} else {
|
} else {
|
||||||
return __("Missing category ID.");
|
return array(false, __("Missing category ID."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbh = DB::connect();
|
$dbh = DB::connect();
|
||||||
$catArray = pkgCategories($dbh);
|
$catArray = pkgCategories($dbh);
|
||||||
if (!array_key_exists($category_id, $catArray)) {
|
if (!array_key_exists($category_id, $catArray)) {
|
||||||
return __("Invalid category ID.");
|
return array(false, __("Invalid category ID."));
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verify package ownership
|
# Verify package ownership
|
||||||
|
@ -1293,7 +1293,7 @@ function pkg_change_category($pid, $atype) {
|
||||||
$row = $result->fetch(PDO::FETCH_ASSOC);
|
$row = $result->fetch(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return __("You are not allowed to change this package category.");
|
return array(false, __("You are not allowed to change this package category."));
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = uid_from_sid($_COOKIE["AURSID"]);
|
$uid = uid_from_sid($_COOKIE["AURSID"]);
|
||||||
|
@ -1303,9 +1303,9 @@ function pkg_change_category($pid, $atype) {
|
||||||
$q.= "SET CategoryID = ".intval($category_id)." ";
|
$q.= "SET CategoryID = ".intval($category_id)." ";
|
||||||
$q.= "WHERE ID = ".intval($pid);
|
$q.= "WHERE ID = ".intval($pid);
|
||||||
$dbh->exec($q);
|
$dbh->exec($q);
|
||||||
return __("Package category changed.");
|
return array(true, __("Package category changed."));
|
||||||
} else {
|
} else {
|
||||||
return __("You are not allowed to change this package category.");
|
return array(false, __("You are not allowed to change this package category."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue