You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v37.go 772B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "html"
  7. "xorm.io/xorm"
  8. )
  9. func unescapeUserFullNames(x *xorm.Engine) (err error) {
  10. type User struct {
  11. ID int64 `xorm:"pk autoincr"`
  12. FullName string
  13. }
  14. const batchSize = 100
  15. for start := 0; ; start += batchSize {
  16. users := make([]*User, 0, batchSize)
  17. if err := x.Limit(batchSize, start).Find(&users); err != nil {
  18. return err
  19. }
  20. if len(users) == 0 {
  21. return nil
  22. }
  23. for _, user := range users {
  24. user.FullName = html.UnescapeString(user.FullName)
  25. if _, err := x.ID(user.ID).Cols("full_name").Update(user); err != nil {
  26. return err
  27. }
  28. }
  29. }
  30. }