summaryrefslogtreecommitdiffstats
path: root/web/lib
diff options
context:
space:
mode:
authorLukas Fleischer <archlinux@cryptocrack.de>2014-07-25 10:28:15 +0200
committerLukas Fleischer <archlinux@cryptocrack.de>2014-07-25 11:30:32 +0200
commitf4ee1278e5509c531675828dc8fce78ae1a608b9 (patch)
tree0f6d4c7fe3987eac251166a672b17c5cf6f60607 /web/lib
parentdaceef50ebb33a477795a0d790f17fc8770dc45d (diff)
downloadaurweb-f4ee1278e5509c531675828dc8fce78ae1a608b9.tar.xz
Clean up user references in user_delete()
Explicitly clean up all references before deleting a user. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/acctfuncs.inc.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 73d01a5..943e80b 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -829,6 +829,41 @@ function user_suspended($id) {
*/
function user_delete($id) {
$dbh = DB::connect();
+ $id = intval($id);
+
+ /*
+ * These are normally already taken care of by propagation constraints
+ * but it is better to be explicit here.
+ */
+ $fields_delete = array(
+ array("Sessions", "UsersID"),
+ array("PackageVotes", "UsersID"),
+ array("CommentNotify", "UsersID")
+ );
+
+ $fields_set_null = array(
+ array("PackageBases", "SubmitterUID"),
+ array("PackageBases", "MaintainerUID"),
+ array("PackageBases", "SubmitterUID"),
+ array("PackageComments", "UsersID"),
+ array("PackageComments", "DelUsersID"),
+ array("PackageRequests", "UsersID"),
+ array("TU_VoteInfo", "SubmitterID"),
+ array("TU_Votes", "UserID")
+ );
+
+ foreach($fields_delete as list($table, $field)) {
+ $q = "DELETE FROM " . $table . " ";
+ $q.= "WHERE " . $field . " = " . $id;
+ $dbh->query($q);
+ }
+
+ foreach($fields_set_null as list($table, $field)) {
+ $q = "UPDATE " . $table . " SET " . $field . " = NULL ";
+ $q.= "WHERE " . $field . " = " . $id;
+ $dbh->query($q);
+ }
+
$q = "DELETE FROM Users WHERE ID = " . $id;
$dbh->query($q);
return;