Fix bug when deleting user accounts if they own forum threads
This commit is contained in:
parent
a1d80fc2b0
commit
99e9ef9c7b
|
@ -223,6 +223,17 @@ func DeleteForumThreads(userID uint64) error {
|
||||||
|
|
||||||
// Wipe all these threads and their comments.
|
// Wipe all these threads and their comments.
|
||||||
if len(threadIDs) > 0 {
|
if len(threadIDs) > 0 {
|
||||||
|
// First, delete the threads - so they won't be referring to comment_ids that we
|
||||||
|
// delete next and causing errors to arise.
|
||||||
|
result = models.DB.Where(
|
||||||
|
"id IN ?",
|
||||||
|
threadIDs,
|
||||||
|
).Delete(&models.Thread{})
|
||||||
|
if result.Error != nil {
|
||||||
|
return fmt.Errorf("Couldn't delete your forum threads: %s", result.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the comments.
|
||||||
result = models.DB.Where(
|
result = models.DB.Where(
|
||||||
"table_name = ? AND table_id IN ?",
|
"table_name = ? AND table_id IN ?",
|
||||||
"threads", threadIDs,
|
"threads", threadIDs,
|
||||||
|
@ -231,11 +242,6 @@ func DeleteForumThreads(userID uint64) error {
|
||||||
return fmt.Errorf("Couldn't wipe threads of comments: %s", result.Error)
|
return fmt.Errorf("Couldn't wipe threads of comments: %s", result.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// And finish the threads off too.
|
|
||||||
result = models.DB.Where(
|
|
||||||
"id IN ?",
|
|
||||||
threadIDs,
|
|
||||||
).Delete(&models.Thread{})
|
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user