summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-01 17:33:00 +0100
committerLukas Fleischer <archlinux@cryptocrack.de>2011-03-04 10:29:14 +0100
commit0e304107677cbcd9aa73500d3e5f5fda692a260e (patch)
tree93b55cc7a95fe26d69699732cc77c7d5bc130a3b
parentf9eba12312fc6a1758f7f1051a8f30b435175f94 (diff)
downloadaur-0e304107677cbcd9aa73500d3e5f5fda692a260e.tar.gz
aur-0e304107677cbcd9aa73500d3e5f5fda692a260e.tar.xz
Vastly simplify pkg_delete function
Since only TUs/Devs can delete packages, we can remove almost all checks except the account type check. And now that our DB uses foreign keys, all of the other deletes happen implicitly when a package is deleted so we don't need to take care of it here. Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
-rw-r--r--web/lib/pkgfuncs.inc66
1 files changed, 8 insertions, 58 deletions
diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
index a0cd2692..20e3880f 100644
--- a/web/lib/pkgfuncs.inc
+++ b/web/lib/pkgfuncs.inc
@@ -700,71 +700,21 @@ function pkg_flag ($atype, $ids, $action = True) {
*/
function pkg_delete ($atype, $ids) {
if (!$atype) {
- return __("You must be logged in before you can disown packages.");
+ return __("You must be logged in before you can delete packages.");
}
- if (empty($ids)) {
- return __("You did not select any packages to delete.");
- }
-
- # Delete the packages in $ids array (but only if they are Unsupported)
- #
- $dbh = db_connect();
-
- # Delete the packages in $ids array
- #
- $first = 1;
- foreach ($ids as $pid) {
- if ($first) {
- $first = 0;
- $delete = $pid;
- } else {
- $delete .= ", ".$pid;
- }
- }
-
- $field = "MaintainerUID";
-
- # Only grab Unsupported packages that "we" own or are not owned at all
- $ids_to_delete = array();
- $q = "SELECT Packages.ID FROM Packages ";
- $q.= "WHERE Packages.ID IN (" . $delete . ") ";
-
# If they're a TU or dev, can delete
- if ($atype == "Trusted User" || $atype == "Developer") {
- $result = db_query($q, $dbh);
+ if ($atype != "Trusted User" && $atype != "Developer") {
+ return __("You do have permission to delete packages.");
}
- if ($result != Null && mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- $ids_to_delete[] = $row['ID'];
- }
- }
-
- if (empty($ids_to_delete)) {
- return __("None of the selected packages could be deleted.");
+ if (empty($ids)) {
+ return __("You did not select any packages to delete.");
}
- # These are the packages that are safe to delete
- foreach ($ids_to_delete as $id) {
- $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id;
- $result = db_query($q, $dbh);
-
- $q = "DELETE FROM PackageDepends WHERE PackageID = " . $id;
- $result = db_query($q, $dbh);
-
- $q = "DELETE FROM PackageSources WHERE PackageID = " . $id;
- $result = db_query($q, $dbh);
-
- $q = "DELETE FROM PackageComments WHERE PackageID = " . $id;
- $result = db_query($q, $dbh);
-
- $q = "DELETE FROM Packages WHERE ID = " . $id;
- $result = db_query($q, $dbh);
-
- $q = "DELETE FROM CommentNotify WHERE PkgID = " . $id;
- $result = db_query($q, $dbh);
- }
+ $dbh = db_connect();
+ $q = "DELETE FROM Packages WHERE ID IN (" . implode(",", $ids) . ")";
+ $result = db_query($q, $dbh);
return __("The selected packages have been deleted.");
}