summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <archlinux@cryptocrack.de>2011-07-31 19:05:00 +0200
committerLukas Fleischer <archlinux@cryptocrack.de>2011-08-11 16:17:07 +0200
commitf481645e64145d2a0eca54af156bd7c175abfcb0 (patch)
treeff1c4e62c51a5ea668e15117ac5c660c71024005
parent0ac8970b62ad728bc0988e7e0a7f16efe78ea6cd (diff)
downloadaur-f481645e64145d2a0eca54af156bd7c175abfcb0.tar.gz
aur-f481645e64145d2a0eca54af156bd7c175abfcb0.tar.xz
Add "mergepkgid" argument to pkg_delete()
This allows for merging comments and votes of deleted packages into another one which is useful if a package needs to be renamed. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--web/lib/pkgfuncs.inc.php31
1 files changed, 30 insertions, 1 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index bb5a592c..eb2900bb 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -659,10 +659,11 @@ function pkg_flag ($atype, $ids, $action = True) {
*
* @param string $atype Account type, output of account_from_sid
* @param array $ids Array of package IDs to delete
+ * @param int $mergepkgid Package to merge the deleted ones into
*
* @return string Translated error or success message
*/
-function pkg_delete ($atype, $ids) {
+function pkg_delete ($atype, $ids, $mergepkgid) {
if (!$atype) {
return __("You must be logged in before you can delete packages.");
}
@@ -678,6 +679,34 @@ function pkg_delete ($atype, $ids) {
}
$dbh = db_connect();
+
+ if ($mergepkgid) {
+ /* Merge comments */
+ $q = "UPDATE PackageComments ";
+ $q.= "SET PackageID = " . intval($mergepkgid) . " ";
+ $q.= "WHERE PackageID IN (" . implode(",", $ids) . ")";
+ db_query($q, $dbh);
+
+ /* Merge votes */
+ foreach ($ids as $pkgid) {
+ $q = "UPDATE PackageVotes ";
+ $q.= "SET PackageID = " . intval($mergepkgid) . " ";
+ $q.= "WHERE PackageID = " . $pkgid . " ";
+ $q.= "AND UsersID NOT IN (";
+ $q.= "SELECT * FROM (SELECT UsersID ";
+ $q.= "FROM PackageVotes ";
+ $q.= "WHERE PackageID = " . intval($mergepkgid);
+ $q.= ") temp)";
+ db_query($q, $dbh);
+ }
+
+ $q = "UPDATE Packages ";
+ $q.= "SET NumVotes = (SELECT COUNT(*) FROM PackageVotes ";
+ $q.= "WHERE PackageID = " . intval($mergepkgid) . ") ";
+ $q.= "WHERE ID = " . intval($mergepkgid);
+ db_query($q, $dbh);
+ }
+
$q = "DELETE FROM Packages WHERE ID IN (" . implode(",", $ids) . ")";
$result = db_query($q, $dbh);