Browse Source

models: rename Id to ID

pull/5388/head
Unknwon 6 years ago
parent
commit
77275a9b31
No known key found for this signature in database
GPG Key ID: 7A02C406FAC875A2
  1. 2
      models/comment.go
  2. 8
      models/issue.go
  3. 4
      models/issue_label.go
  4. 2
      models/migrations/migrations.go
  5. 8
      models/milestone.go
  6. 2
      models/mirror.go
  7. 2
      models/models.go
  8. 2
      models/org.go
  9. 20
      models/org_team.go
  10. 4
      models/pull.go
  11. 2
      models/release.go
  12. 8
      models/repo.go
  13. 4
      models/repo_branch.go
  14. 2
      models/repo_collaboration.go
  15. 2
      models/ssh_key.go
  16. 4
      models/user.go
  17. 4
      models/user_mail.go

2
models/comment.go

@ -500,7 +500,7 @@ func DeleteCommentByID(doer *User, id int64) error {
return err return err
} }
if _, err = sess.Id(comment.ID).Delete(new(Comment)); err != nil { if _, err = sess.ID(comment.ID).Delete(new(Comment)); err != nil {
return err return err
} }

8
models/issue.go

@ -402,7 +402,7 @@ func (i *Issue) ReadBy(uid int64) error {
} }
func updateIssueCols(e Engine, issue *Issue, cols ...string) error { func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
_, err := e.Id(issue.ID).Cols(cols...).Update(issue) _, err := e.ID(issue.ID).Cols(cols...).Update(issue)
return err return err
} }
@ -843,7 +843,7 @@ func GetIssueByIndex(repoID, index int64) (*Issue, error) {
func getRawIssueByID(e Engine, id int64) (*Issue, error) { func getRawIssueByID(e Engine, id int64) (*Issue, error) {
issue := new(Issue) issue := new(Issue)
has, err := e.Id(id).Get(issue) has, err := e.ID(id).Get(issue)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
@ -1354,7 +1354,7 @@ func GetRepoIssueStats(repoID, userID int64, filterMode FilterMode, isPull bool)
} }
func updateIssue(e Engine, issue *Issue) error { func updateIssue(e Engine, issue *Issue) error {
_, err := e.Id(issue.ID).AllCols().Update(issue) _, err := e.ID(issue.ID).AllCols().Update(issue)
return err return err
} }
@ -1423,7 +1423,7 @@ func updateIssueUsersByMentions(e Engine, issueID int64, uids []int64) error {
iu.IsMentioned = true iu.IsMentioned = true
if has { if has {
_, err = e.Id(iu.ID).AllCols().Update(iu) _, err = e.ID(iu.ID).AllCols().Update(iu)
} else { } else {
_, err = e.Insert(iu) _, err = e.Insert(iu)
} }

4
models/issue_label.go

@ -196,7 +196,7 @@ func GetLabelsByIssueID(issueID int64) ([]*Label, error) {
} }
func updateLabel(e Engine, l *Label) error { func updateLabel(e Engine, l *Label) error {
_, err := e.Id(l.ID).AllCols().Update(l) _, err := e.ID(l.ID).AllCols().Update(l)
return err return err
} }
@ -221,7 +221,7 @@ func DeleteLabel(repoID, labelID int64) error {
return err return err
} }
if _, err = sess.Id(labelID).Delete(new(Label)); err != nil { if _, err = sess.ID(labelID).Delete(new(Label)); err != nil {
return err return err
} else if _, err = sess.Where("label_id = ?", labelID).Delete(new(IssueLabel)); err != nil { } else if _, err = sess.Where("label_id = ?", labelID).Delete(new(IssueLabel)); err != nil {
return err return err

2
models/migrations/migrations.go

@ -162,7 +162,7 @@ func generateOrgRandsAndSalt(x *xorm.Engine) (err error) {
if org.Salt, err = tool.RandomString(10); err != nil { if org.Salt, err = tool.RandomString(10); err != nil {
return err return err
} }
if _, err = sess.Id(org.ID).Update(org); err != nil { if _, err = sess.ID(org.ID).Update(org); err != nil {
return err return err
} }
} }

8
models/milestone.go

@ -166,7 +166,7 @@ func GetMilestones(repoID int64, page int, isClosed bool) ([]*Milestone, error)
} }
func updateMilestone(e Engine, m *Milestone) error { func updateMilestone(e Engine, m *Milestone) error {
_, err := e.Id(m.ID).AllCols().Update(m) _, err := e.ID(m.ID).AllCols().Update(m)
return err return err
} }
@ -223,7 +223,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
repo.NumMilestones = int(countRepoMilestones(sess, repo.ID)) repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID)) repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
if _, err = sess.Id(repo.ID).AllCols().Update(repo); err != nil { if _, err = sess.ID(repo.ID).AllCols().Update(repo); err != nil {
return err return err
} }
return sess.Commit() return sess.Commit()
@ -383,13 +383,13 @@ func DeleteMilestoneOfRepoByID(repoID, id int64) error {
return err return err
} }
if _, err = sess.Id(m.ID).Delete(new(Milestone)); err != nil { if _, err = sess.ID(m.ID).Delete(new(Milestone)); err != nil {
return err return err
} }
repo.NumMilestones = int(countRepoMilestones(sess, repo.ID)) repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID)) repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
if _, err = sess.Id(repo.ID).AllCols().Update(repo); err != nil { if _, err = sess.ID(repo.ID).AllCols().Update(repo); err != nil {
return err return err
} }

2
models/mirror.go

@ -320,7 +320,7 @@ func GetMirrorByRepoID(repoID int64) (*Mirror, error) {
} }
func updateMirror(e Engine, m *Mirror) error { func updateMirror(e Engine, m *Mirror) error {
_, err := e.Id(m.ID).AllCols().Update(m) _, err := e.ID(m.ID).AllCols().Update(m)
return err return err
} }

2
models/models.go

@ -33,7 +33,7 @@ type Engine interface {
Exec(string, ...interface{}) (sql.Result, error) Exec(string, ...interface{}) (sql.Result, error)
Find(interface{}, ...interface{}) error Find(interface{}, ...interface{}) error
Get(interface{}) (bool, error) Get(interface{}) (bool, error)
Id(interface{}) *xorm.Session ID(interface{}) *xorm.Session
In(string, ...interface{}) *xorm.Session In(string, ...interface{}) *xorm.Session
Insert(...interface{}) (int64, error) Insert(...interface{}) (int64, error)
InsertOne(interface{}) (int64, error) InsertOne(interface{}) (int64, error)

2
models/org.go

@ -410,7 +410,7 @@ func RemoveOrgUser(orgID, userID int64) error {
return err return err
} }
if _, err := sess.Id(ou.ID).Delete(ou); err != nil { if _, err := sess.ID(ou.ID).Delete(ou); err != nil {
return err return err
} else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id=?", orgID); err != nil { } else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id=?", orgID); err != nil {
return err return err

20
models/org_team.go

@ -111,7 +111,7 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
} }
t.NumRepos++ t.NumRepos++
if _, err = e.Id(t.ID).AllCols().Update(t); err != nil { if _, err = e.ID(t.ID).AllCols().Update(t); err != nil {
return fmt.Errorf("update team: %v", err) return fmt.Errorf("update team: %v", err)
} }
@ -157,7 +157,7 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
} }
t.NumRepos-- t.NumRepos--
if _, err = e.Id(t.ID).AllCols().Update(t); err != nil { if _, err = e.ID(t.ID).AllCols().Update(t); err != nil {
return err return err
} }
@ -286,7 +286,7 @@ func GetTeamOfOrgByName(orgID int64, name string) (*Team, error) {
func getTeamByID(e Engine, teamID int64) (*Team, error) { func getTeamByID(e Engine, teamID int64) (*Team, error) {
t := new(Team) t := new(Team)
has, err := e.Id(teamID).Get(t) has, err := e.ID(teamID).Get(t)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
@ -334,7 +334,7 @@ func UpdateTeam(t *Team, authChanged bool) (err error) {
return ErrTeamAlreadyExist{t.OrgID, t.LowerName} return ErrTeamAlreadyExist{t.OrgID, t.LowerName}
} }
if _, err = sess.Id(t.ID).AllCols().Update(t); err != nil { if _, err = sess.ID(t.ID).AllCols().Update(t); err != nil {
return fmt.Errorf("update: %v", err) return fmt.Errorf("update: %v", err)
} }
@ -386,7 +386,7 @@ func DeleteTeam(t *Team) error {
} }
// Delete team. // Delete team.
if _, err = sess.Id(t.ID).Delete(new(Team)); err != nil { if _, err = sess.ID(t.ID).Delete(new(Team)); err != nil {
return err return err
} }
// Update organization number of teams. // Update organization number of teams.
@ -431,7 +431,7 @@ func getTeamMembers(e Engine, teamID int64) (_ []*User, err error) {
members := make([]*User, 0, len(teamUsers)) members := make([]*User, 0, len(teamUsers))
for i := range teamUsers { for i := range teamUsers {
member := new(User) member := new(User)
if _, err = e.Id(teamUsers[i].UID).Get(member); err != nil { if _, err = e.ID(teamUsers[i].UID).Get(member); err != nil {
return nil, fmt.Errorf("get user '%d': %v", teamUsers[i].UID, err) return nil, fmt.Errorf("get user '%d': %v", teamUsers[i].UID, err)
} }
members = append(members, member) members = append(members, member)
@ -500,7 +500,7 @@ func AddTeamMember(orgID, teamID, userID int64) error {
} }
if _, err = sess.Insert(tu); err != nil { if _, err = sess.Insert(tu); err != nil {
return err return err
} else if _, err = sess.Id(t.ID).Update(t); err != nil { } else if _, err = sess.ID(t.ID).Update(t); err != nil {
return err return err
} }
@ -520,7 +520,7 @@ func AddTeamMember(orgID, teamID, userID int64) error {
if t.IsOwnerTeam() { if t.IsOwnerTeam() {
ou.IsOwner = true ou.IsOwner = true
} }
if _, err = sess.Id(ou.ID).AllCols().Update(ou); err != nil { if _, err = sess.ID(ou.ID).AllCols().Update(ou); err != nil {
return err return err
} }
@ -562,7 +562,7 @@ func removeTeamMember(e Engine, orgID, teamID, uid int64) error {
} }
if _, err := e.Delete(tu); err != nil { if _, err := e.Delete(tu); err != nil {
return err return err
} else if _, err = e.Id(t.ID).AllCols().Update(t); err != nil { } else if _, err = e.ID(t.ID).AllCols().Update(t); err != nil {
return err return err
} }
@ -583,7 +583,7 @@ func removeTeamMember(e Engine, orgID, teamID, uid int64) error {
if t.IsOwnerTeam() { if t.IsOwnerTeam() {
ou.IsOwner = false ou.IsOwner = false
} }
if _, err = e.Id(ou.ID).AllCols().Update(ou); err != nil { if _, err = e.ID(ou.ID).AllCols().Update(ou); err != nil {
return err return err
} }
return nil return nil

4
models/pull.go

@ -321,7 +321,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
pr.HasMerged = true pr.HasMerged = true
pr.Merged = time.Now() pr.Merged = time.Now()
pr.MergerID = doer.ID pr.MergerID = doer.ID
if _, err = sess.Id(pr.ID).AllCols().Update(pr); err != nil { if _, err = sess.ID(pr.ID).AllCols().Update(pr); err != nil {
return fmt.Errorf("update pull request: %v", err) return fmt.Errorf("update pull request: %v", err)
} }
@ -546,7 +546,7 @@ func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequ
func getPullRequestByID(e Engine, id int64) (*PullRequest, error) { func getPullRequestByID(e Engine, id int64) (*PullRequest, error) {
pr := new(PullRequest) pr := new(PullRequest)
has, err := e.Id(id).Get(pr) has, err := e.ID(id).Get(pr)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {

2
models/release.go

@ -293,7 +293,7 @@ func UpdateRelease(doer *User, gitRepo *git.Repository, r *Release, isPublish bo
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
return err return err
} }
if _, err = sess.Id(r.ID).AllCols().Update(r); err != nil { if _, err = sess.ID(r.ID).AllCols().Update(r); err != nil {
return fmt.Errorf("Update: %v", err) return fmt.Errorf("Update: %v", err)
} }

8
models/repo.go

@ -1264,7 +1264,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
repo.Owner = newOwner repo.Owner = newOwner
// Update repository. // Update repository.
if _, err := sess.Id(repo.ID).Update(repo); err != nil { if _, err := sess.ID(repo.ID).Update(repo); err != nil {
return fmt.Errorf("update owner: %v", err) return fmt.Errorf("update owner: %v", err)
} }
@ -1296,7 +1296,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
} }
t.NumRepos-- t.NumRepos--
if _, err := sess.Id(t.ID).AllCols().Update(t); err != nil { if _, err := sess.ID(t.ID).AllCols().Update(t); err != nil {
return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err) return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err)
} }
} }
@ -1409,7 +1409,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
repo.Website = repo.Website[:255] repo.Website = repo.Website[:255]
} }
if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil { if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil {
return fmt.Errorf("update: %v", err) return fmt.Errorf("update: %v", err)
} }
@ -1625,7 +1625,7 @@ func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
func getRepositoryByID(e Engine, id int64) (*Repository, error) { func getRepositoryByID(e Engine, id int64) (*Repository, error) {
repo := new(Repository) repo := new(Repository)
has, err := e.Id(id).Get(repo) has, err := e.ID(id).Get(repo)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {

4
models/repo_branch.go

@ -131,7 +131,7 @@ func UpdateProtectBranch(protectBranch *ProtectBranch) (err error) {
} }
} }
if _, err = sess.Id(protectBranch.ID).AllCols().Update(protectBranch); err != nil { if _, err = sess.ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
return fmt.Errorf("Update: %v", err) return fmt.Errorf("Update: %v", err)
} }
@ -234,7 +234,7 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit
return err return err
} }
if _, err = sess.Id(protectBranch.ID).AllCols().Update(protectBranch); err != nil { if _, err = sess.ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
return fmt.Errorf("Update: %v", err) return fmt.Errorf("Update: %v", err)
} }

2
models/repo_collaboration.go

@ -170,7 +170,7 @@ func (repo *Repository) ChangeCollaborationAccessMode(userID int64, mode AccessM
return err return err
} }
if _, err = sess.Id(collaboration.ID).AllCols().Update(collaboration); err != nil { if _, err = sess.ID(collaboration.ID).AllCols().Update(collaboration); err != nil {
return fmt.Errorf("update collaboration: %v", err) return fmt.Errorf("update collaboration: %v", err)
} }

2
models/ssh_key.go

@ -747,7 +747,7 @@ func DeleteDeployKey(doer *User, id int64) error {
return err return err
} }
if _, err = sess.Id(key.ID).Delete(new(DeployKey)); err != nil { if _, err = sess.ID(key.ID).Delete(new(DeployKey)); err != nil {
return fmt.Errorf("delete deploy key [%d]: %v", key.ID, err) return fmt.Errorf("delete deploy key [%d]: %v", key.ID, err)
} }

4
models/user.go

@ -706,7 +706,7 @@ func updateUser(e Engine, u *User) error {
u.Website = tool.TruncateString(u.Website, 255) u.Website = tool.TruncateString(u.Website, 255)
u.Description = tool.TruncateString(u.Description, 255) u.Description = tool.TruncateString(u.Description, 255)
_, err := e.Id(u.ID).AllCols().Update(u) _, err := e.ID(u.ID).AllCols().Update(u)
return err return err
} }
@ -890,7 +890,7 @@ func GetUserByKeyID(keyID int64) (*User, error) {
func getUserByID(e Engine, id int64) (*User, error) { func getUserByID(e Engine, id int64) (*User, error) {
u := new(User) u := new(User)
has, err := e.Id(id).Get(u) has, err := e.ID(id).Get(u)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {

4
models/user_mail.go

@ -132,7 +132,7 @@ func (email *EmailAddress) Activate() error {
} }
email.IsActivated = true email.IsActivated = true
if _, err := sess.Id(email.ID).AllCols().Update(email); err != nil { if _, err := sess.ID(email.ID).AllCols().Update(email); err != nil {
return err return err
} else if err = updateUser(sess, user); err != nil { } else if err = updateUser(sess, user); err != nil {
return err return err
@ -202,7 +202,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
} }
user.Email = email.Email user.Email = email.Email
if _, err = sess.Id(user.ID).AllCols().Update(user); err != nil { if _, err = sess.ID(user.ID).AllCols().Update(user); err != nil {
return err return err
} }

Loading…
Cancel
Save