Fix bug when deleting user accounts if they own forum threads

face-detect
Noah Petherbridge 2023-02-24 16:54:27 -08:00
parent a1d80fc2b0
commit 99e9ef9c7b
1 changed files with 11 additions and 5 deletions

View File

@ -223,6 +223,17 @@ func DeleteForumThreads(userID uint64) error {
// Wipe all these threads and their comments.
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(
"table_name = ? AND table_id IN ?",
"threads", threadIDs,
@ -231,11 +242,6 @@ func DeleteForumThreads(userID uint64) 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
}