Remove NewSession method from db.Engine interface (#17577)
* Remove NewSession method from db.Engine interface * Fix bug * Some improvements * Fix bug * Fix test * Use XXXBean instead of XXXExample
This commit is contained in:
parent
0add627182
commit
d710af6669
44 changed files with 600 additions and 620 deletions
|
@ -109,11 +109,11 @@ func (u *User) UploadAvatar(data []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sess := db.NewSession(db.DefaultContext)
|
||||
defer sess.Close()
|
||||
if err = sess.Begin(); err != nil {
|
||||
ctx, committer, err := db.TxContext()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
|
||||
u.UseCustomAvatar = true
|
||||
// Different users can upload same image as avatar
|
||||
|
@ -121,7 +121,7 @@ func (u *User) UploadAvatar(data []byte) error {
|
|||
// Otherwise, if any of the users delete his avatar
|
||||
// Other users will lose their avatars too.
|
||||
u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
|
||||
if err = updateUserCols(sess, u, "use_custom_avatar", "avatar"); err != nil {
|
||||
if err = updateUserCols(db.GetEngine(ctx), u, "use_custom_avatar", "avatar"); err != nil {
|
||||
return fmt.Errorf("updateUser: %v", err)
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ func (u *User) UploadAvatar(data []byte) error {
|
|||
return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err)
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
return committer.Commit()
|
||||
}
|
||||
|
||||
// IsUploadAvatarChanged returns true if the current user's avatar would be changed with the provided data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue