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.

update.go 1.4KB

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