From 4470ca2e63b8c6e17d0eeeb925ef5fbf4204b875 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Thu, 21 Jun 2018 22:18:48 +0200 Subject: [PATCH] Add support for scores_removed --- app/v1/manage_user.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/v1/manage_user.go b/app/v1/manage_user.go index 8738dbf..61fa2c0 100644 --- a/app/v1/manage_user.go +++ b/app/v1/manage_user.go @@ -245,15 +245,25 @@ func WipeUserPOST(md common.MethodData) common.CodeMessager { return common.SimpleResponse(403, "Can't edit that user") } + tx, err := md.DB.Beginx() + if err != nil { + md.Err(err) + return Err500 + } + for _, mode := range data.Modes { if mode < 0 || mode > 3 { continue } - _, err = md.DB.Exec("DELETE FROM scores WHERE userid = ? AND play_mode = ?", data.ID, mode) + _, err = tx.Exec("INSERT INTO scores_removed SELECT * FROM scores WHERE userid = ? AND play_mode = ?", data.ID, mode) if err != nil { md.Err(err) } - _, err = md.DB.Exec(strings.Replace( + _, err = tx.Exec("DELETE FROM scores WHERE userid = ? AND play_mode = ?", data.ID, mode) + if err != nil { + md.Err(err) + } + _, err = tx.Exec(strings.Replace( `UPDATE users_stats SET total_score_MODE = 0, ranked_score_MODE = 0, replays_watched_MODE = 0, playcount_MODE = 0, avg_accuracy_MODE = 0, total_hits_MODE = 0, level_MODE = 0, pp_MODE = 0 WHERE id = ?`, "MODE", modesToReadable[mode], -1, @@ -263,6 +273,11 @@ func WipeUserPOST(md common.MethodData) common.CodeMessager { } } + if err = tx.Commit(); err != nil { + md.Err(err) + return Err500 + } + rapLog(md, fmt.Sprintf("has wiped %s's account", userData.Username)) return userPutsSingle(md, md.DB.QueryRowx(userFields+" WHERE users.id = ? LIMIT 1", data.ID))