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

update.go 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2019 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. "strconv"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/structs"
  10. )
  11. // UpdateMigrationPosterID updates all migrated repositories' issues and comments posterID
  12. func UpdateMigrationPosterID() {
  13. for _, gitService := range structs.SupportedFullGitService {
  14. if err := updateMigrationPosterIDByGitService(gitService); err != nil {
  15. log.Error("updateMigrationPosterIDByGitService failed: %v", err)
  16. }
  17. }
  18. }
  19. func updateMigrationPosterIDByGitService(tp structs.GitServiceType) error {
  20. provider := tp.Name()
  21. if len(provider) == 0 {
  22. return nil
  23. }
  24. const batchSize = 100
  25. var start int
  26. for {
  27. users, err := models.FindExternalUsersByProvider(models.FindExternalUserOptions{
  28. Provider: provider,
  29. Start: start,
  30. Limit: batchSize,
  31. })
  32. if err != nil {
  33. return err
  34. }
  35. for _, user := range users {
  36. externalUserID, err := strconv.ParseInt(user.ExternalID, 10, 64)
  37. if err != nil {
  38. log.Warn("Parse externalUser %#v 's userID failed: %v", user, err)
  39. continue
  40. }
  41. if err := models.UpdateMigrationsByType(tp, externalUserID, user.UserID); err != nil {
  42. log.Error("UpdateMigrationsByType type %s external user id %v to local user id %v failed: %v", tp.Name(), user.ExternalID, user.UserID, err)
  43. }
  44. }
  45. if len(users) < batchSize {
  46. break
  47. }
  48. start += len(users)
  49. }
  50. return nil
  51. }