Add support for scores_removed

This commit is contained in:
Morgan Bazalgette 2018-06-21 22:18:48 +02:00
parent 334c409e9e
commit 4470ca2e63
No known key found for this signature in database
GPG Key ID: 40D328300D245DA5

View File

@ -245,15 +245,25 @@ func WipeUserPOST(md common.MethodData) common.CodeMessager {
return common.SimpleResponse(403, "Can't edit that user") 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 { for _, mode := range data.Modes {
if mode < 0 || mode > 3 { if mode < 0 || mode > 3 {
continue 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 { if err != nil {
md.Err(err) 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, `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 playcount_MODE = 0, avg_accuracy_MODE = 0, total_hits_MODE = 0, level_MODE = 0, pp_MODE = 0
WHERE id = ?`, "MODE", modesToReadable[mode], -1, 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)) 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)) return userPutsSingle(md, md.DB.QueryRowx(userFields+" WHERE users.id = ? LIMIT 1", data.ID))