Skip to content

Commit

Permalink
Replace deprecated Id method with ID (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethantkoenig authored and lafriks committed Oct 5, 2017
1 parent e1266a1 commit aa962de
Show file tree
Hide file tree
Showing 31 changed files with 84 additions and 84 deletions.
4 changes: 2 additions & 2 deletions models/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestRenameRepoAction(t *testing.T) {
assert.NoError(t, RenameRepoAction(user, oldRepoName, repo))
AssertExistsAndLoadBean(t, actionBean)

_, err := x.Id(repo.ID).Cols("name", "lower_name").Update(repo)
_, err := x.ID(repo.ID).Cols("name", "lower_name").Update(repo)
assert.NoError(t, err)
CheckConsistencyFor(t, &Action{})
}
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestTransferRepoAction(t *testing.T) {
assert.NoError(t, TransferRepoAction(user2, user2, repo))
AssertExistsAndLoadBean(t, actionBean)

_, err := x.Id(repo.ID).Cols("owner_id").Update(repo)
_, err := x.ID(repo.ID).Cols("owner_id").Update(repo)
assert.NoError(t, err)
CheckConsistencyFor(t, &Action{})
}
Expand Down
2 changes: 1 addition & 1 deletion models/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Notices(page, pageSize int) ([]*Notice, error) {

// DeleteNotice deletes a system notice by given ID.
func DeleteNotice(id int64) error {
_, err := x.Id(id).Delete(new(Notice))
_, err := x.ID(id).Delete(new(Notice))
return err
}

Expand Down
2 changes: 1 addition & 1 deletion models/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func UpdateProtectBranch(repo *Repository, protectBranch *ProtectedBranch, white
return nil
}

if _, err = x.Id(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
if _, err = x.ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
return fmt.Errorf("Update: %v", err)
}

Expand Down
2 changes: 1 addition & 1 deletion models/gpg_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ListGPGKeys(uid int64) ([]*GPGKey, error) {
// GetGPGKeyByID returns public key by given ID.
func GetGPGKeyByID(keyID int64) (*GPGKey, error) {
key := new(GPGKey)
has, err := x.Id(keyID).Get(key)
has, err := x.ID(keyID).Get(key)
if err != nil {
return nil, err
} else if !has {
Expand Down
8 changes: 4 additions & 4 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ func (issue *Issue) ReadBy(userID int64) error {
}

func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
if _, err := e.Id(issue.ID).Cols(cols...).Update(issue); err != nil {
if _, err := e.ID(issue.ID).Cols(cols...).Update(issue); err != nil {
return err
}
UpdateIssueIndexer(issue.ID)
Expand Down Expand Up @@ -911,7 +911,7 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {

for i := 0; i < len(attachments); i++ {
attachments[i].IssueID = opts.Issue.ID
if _, err = e.Id(attachments[i].ID).Update(attachments[i]); err != nil {
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err)
}
}
Expand Down Expand Up @@ -1008,7 +1008,7 @@ func GetIssueByIndex(repoID, index int64) (*Issue, error) {

func getIssueByID(e Engine, id int64) (*Issue, error) {
issue := new(Issue)
has, err := e.Id(id).Get(issue)
has, err := e.ID(id).Get(issue)
if err != nil {
return nil, err
} else if !has {
Expand Down Expand Up @@ -1435,7 +1435,7 @@ func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen
}

func updateIssue(e Engine, issue *Issue) error {
_, err := e.Id(issue.ID).AllCols().Update(issue)
_, err := e.ID(issue.ID).AllCols().Update(issue)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
attachments[i].IssueID = opts.Issue.ID
attachments[i].CommentID = comment.ID
// No assign value could be 0, so ignore AllCols().
if _, err = e.Id(attachments[i].ID).Update(attachments[i]); err != nil {
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
return nil, fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
}
}
Expand Down Expand Up @@ -569,7 +569,7 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi
// GetCommentByID returns the comment by given ID.
func GetCommentByID(id int64) (*Comment, error) {
c := new(Comment)
has, err := x.Id(id).Get(c)
has, err := x.ID(id).Get(c)
if err != nil {
return nil, err
} else if !has {
Expand Down Expand Up @@ -647,7 +647,7 @@ func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) {

// UpdateComment updates information of comment.
func UpdateComment(c *Comment) error {
if _, err := x.Id(c.ID).AllCols().Update(c); err != nil {
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
return err
} else if c.Type == CommentTypeComment {
UpdateIssueIndexer(c.IssueID)
Expand Down
4 changes: 2 additions & 2 deletions models/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func GetLabelsByIssueID(issueID int64) ([]*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
}

Expand All @@ -247,7 +247,7 @@ func DeleteLabel(repoID, labelID int64) error {
return err
}

if _, err = sess.Id(labelID).Delete(new(Label)); err != nil {
if _, err = sess.ID(labelID).Delete(new(Label)); err != nil {
return err
} else if _, err = sess.
Where("label_id = ?", labelID).
Expand Down
8 changes: 4 additions & 4 deletions models/issue_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func GetMilestones(repoID int64, page int, isClosed bool, sortType string) ([]*M
}

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
}

Expand Down Expand Up @@ -221,7 +221,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {

repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
if _, err = sess.Id(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
return err
}
return sess.Commit()
Expand Down Expand Up @@ -329,13 +329,13 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
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
}

repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
if _, err = sess.Id(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion models/issue_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func UpdateIssueUsersByMentions(e Engine, issueID int64, uids []int64) error {

iu.IsMentioned = true
if has {
_, err = e.Id(iu.ID).Cols("is_mentioned").Update(iu)
_, err = e.ID(iu.ID).Cols("is_mentioned").Update(iu)
} else {
_, err = e.Insert(iu)
}
Expand Down
2 changes: 1 addition & 1 deletion models/issue_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
} else {
iw.IsWatching = isWatching

if _, err := x.Id(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil {
if _, err := x.ID(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil {
return err
}
}
Expand Down
10 changes: 5 additions & 5 deletions models/login_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func LoginSources() ([]*LoginSource, error) {
// GetLoginSourceByID returns login source by given ID.
func GetLoginSourceByID(id int64) (*LoginSource, error) {
source := new(LoginSource)
has, err := x.Id(id).Get(source)
has, err := x.ID(id).Get(source)
if err != nil {
return nil, err
} else if !has {
Expand All @@ -328,15 +328,15 @@ func UpdateSource(source *LoginSource) error {
}
}

_, err := x.Id(source.ID).AllCols().Update(source)
_, err := x.ID(source.ID).AllCols().Update(source)
if err == nil && source.IsOAuth2() && source.IsActived {
oAuth2Config := source.OAuth2()
err = oauth2.RegisterProvider(source.Name, oAuth2Config.Provider, oAuth2Config.ClientID, oAuth2Config.ClientSecret, oAuth2Config.OpenIDConnectAutoDiscoveryURL, oAuth2Config.CustomURLMapping)
err = wrapOpenIDConnectInitializeError(err, source.Name, oAuth2Config)

if err != nil {
// restore original values since we cannot update the provider it self
x.Id(source.ID).AllCols().Update(originalLoginSource)
x.ID(source.ID).AllCols().Update(originalLoginSource)
}
}
return err
Expand All @@ -362,7 +362,7 @@ func DeleteSource(source *LoginSource) error {
oauth2.RemoveProvider(source.Name)
}

_, err = x.Id(source.ID).Delete(new(LoginSource))
_, err = x.ID(source.ID).Delete(new(LoginSource))
return err
}

Expand Down Expand Up @@ -647,7 +647,7 @@ func UserSignIn(username, password string) (*User, error) {

default:
var source LoginSource
hasSource, err := x.Id(user.LoginSource).Get(&source)
hasSource, err := x.ID(user.LoginSource).Get(&source)
if err != nil {
return nil, err
} else if !hasSource {
Expand Down
4 changes: 2 additions & 2 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to curr
if int(v-minDBVersion) > len(migrations) {
// User downgraded Gitea.
currentVersion.Version = int64(len(migrations) + minDBVersion)
_, err = x.Id(1).Update(currentVersion)
_, err = x.ID(1).Update(currentVersion)
return err
}
for i, m := range migrations[v-minDBVersion:] {
Expand All @@ -182,7 +182,7 @@ Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to curr
return fmt.Errorf("do migrate: %v", err)
}
currentVersion.Version = v + int64(i) + 1
if _, err = x.Id(1).Update(currentVersion); err != nil {
if _, err = x.ID(1).Update(currentVersion); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v28.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func addRepoSize(x *xorm.Engine) (err error) {
}

repo.Size = countObject.Size + countObject.SizePack
if _, err = x.Id(repo.ID).Cols("size").Update(repo); err != nil {
if _, err = x.ID(repo.ID).Cols("size").Update(repo); err != nil {
return fmt.Errorf("update size: %v", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v38.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func removeCommitsUnitType(x *xorm.Engine) (err error) {
}
}
team.UnitTypes = ut
if _, err := x.Id(team.ID).Cols("unit_types").Update(team); err != nil {
if _, err := x.ID(team.ID).Cols("unit_types").Update(team); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v39.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func addTimetracking(x *xorm.Engine) error {
changes = true
}
if changes {
if _, err := x.Id(unit.ID).Cols("config").Update(unit); err != nil {
if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Engine interface {
Exec(string, ...interface{}) (sql.Result, error)
Find(interface{}, ...interface{}) error
Get(interface{}) (bool, error)
Id(interface{}) *xorm.Session
ID(interface{}) *xorm.Session
In(string, ...interface{}) *xorm.Session
Incr(column string, arg ...interface{}) *xorm.Session
Insert(...interface{}) (int64, error)
Expand Down
6 changes: 3 additions & 3 deletions models/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func updateIssueNotification(e Engine, userID, issueID, updatedByID int64) error
notification.Status = NotificationStatusUnread
notification.UpdatedBy = updatedByID

_, err = e.Id(notification.ID).Update(notification)
_, err = e.ID(notification.ID).Update(notification)
return err
}

Expand Down Expand Up @@ -274,7 +274,7 @@ func setNotificationStatusReadIfUnread(e Engine, userID, issueID int64) error {

notification.Status = NotificationStatusRead

_, err = e.Id(notification.ID).Update(notification)
_, err = e.ID(notification.ID).Update(notification)
return err
}

Expand All @@ -291,7 +291,7 @@ func SetNotificationStatus(notificationID int64, user *User, status Notification

notification.Status = status

_, err = x.Id(notificationID).Update(notification)
_, err = x.ID(notificationID).Update(notification)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions models/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func deleteOrg(e *xorm.Session, u *User) error {
return fmt.Errorf("deleteBeans: %v", err)
}

if _, err = e.Id(u.ID).Delete(new(User)); err != nil {
if _, err = e.ID(u.ID).Delete(new(User)); err != nil {
return fmt.Errorf("Delete: %v", err)
}

Expand Down Expand Up @@ -412,7 +412,7 @@ func ChangeOrgUserStatus(orgID, uid int64, public bool) error {
}

ou.IsPublic = public
_, err = x.Id(ou.ID).Cols("is_public").Update(ou)
_, err = x.ID(ou.ID).Cols("is_public").Update(ou)
return err
}

Expand Down Expand Up @@ -480,7 +480,7 @@ func RemoveOrgUser(orgID, userID int64) error {
return err
}

if _, err := sess.Id(ou.ID).Delete(ou); err != nil {
if _, err := sess.ID(ou.ID).Delete(ou); err != nil {
return err
} else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id=?", orgID); err != nil {
return err
Expand Down
Loading

0 comments on commit aa962de

Please sign in to comment.