Skip to content

Commit aa962de

Browse files
ethantkoeniglafriks
authored andcommitted
Replace deprecated Id method with ID (#2655)
1 parent e1266a1 commit aa962de

31 files changed

+84
-84
lines changed

models/action_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestRenameRepoAction(t *testing.T) {
7676
assert.NoError(t, RenameRepoAction(user, oldRepoName, repo))
7777
AssertExistsAndLoadBean(t, actionBean)
7878

79-
_, err := x.Id(repo.ID).Cols("name", "lower_name").Update(repo)
79+
_, err := x.ID(repo.ID).Cols("name", "lower_name").Update(repo)
8080
assert.NoError(t, err)
8181
CheckConsistencyFor(t, &Action{})
8282
}
@@ -337,7 +337,7 @@ func TestTransferRepoAction(t *testing.T) {
337337
assert.NoError(t, TransferRepoAction(user2, user2, repo))
338338
AssertExistsAndLoadBean(t, actionBean)
339339

340-
_, err := x.Id(repo.ID).Cols("owner_id").Update(repo)
340+
_, err := x.ID(repo.ID).Cols("owner_id").Update(repo)
341341
assert.NoError(t, err)
342342
CheckConsistencyFor(t, &Action{})
343343
}

models/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func Notices(page, pageSize int) ([]*Notice, error) {
9393

9494
// DeleteNotice deletes a system notice by given ID.
9595
func DeleteNotice(id int64) error {
96-
_, err := x.Id(id).Delete(new(Notice))
96+
_, err := x.ID(id).Delete(new(Notice))
9797
return err
9898
}
9999

models/branches.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func UpdateProtectBranch(repo *Repository, protectBranch *ProtectedBranch, white
142142
return nil
143143
}
144144

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

models/gpg_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func ListGPGKeys(uid int64) ([]*GPGKey, error) {
7373
// GetGPGKeyByID returns public key by given ID.
7474
func GetGPGKeyByID(keyID int64) (*GPGKey, error) {
7575
key := new(GPGKey)
76-
has, err := x.Id(keyID).Get(key)
76+
has, err := x.ID(keyID).Get(key)
7777
if err != nil {
7878
return nil, err
7979
} else if !has {

models/issue.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ func (issue *Issue) ReadBy(userID int64) error {
570570
}
571571

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

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

10091009
func getIssueByID(e Engine, id int64) (*Issue, error) {
10101010
issue := new(Issue)
1011-
has, err := e.Id(id).Get(issue)
1011+
has, err := e.ID(id).Get(issue)
10121012
if err != nil {
10131013
return nil, err
10141014
} else if !has {
@@ -1435,7 +1435,7 @@ func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen
14351435
}
14361436

14371437
func updateIssue(e Engine, issue *Issue) error {
1438-
_, err := e.Id(issue.ID).AllCols().Update(issue)
1438+
_, err := e.ID(issue.ID).AllCols().Update(issue)
14391439
if err != nil {
14401440
return err
14411441
}

models/issue_comment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
356356
attachments[i].IssueID = opts.Issue.ID
357357
attachments[i].CommentID = comment.ID
358358
// No assign value could be 0, so ignore AllCols().
359-
if _, err = e.Id(attachments[i].ID).Update(attachments[i]); err != nil {
359+
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
360360
return nil, fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
361361
}
362362
}
@@ -569,7 +569,7 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi
569569
// GetCommentByID returns the comment by given ID.
570570
func GetCommentByID(id int64) (*Comment, error) {
571571
c := new(Comment)
572-
has, err := x.Id(id).Get(c)
572+
has, err := x.ID(id).Get(c)
573573
if err != nil {
574574
return nil, err
575575
} else if !has {
@@ -647,7 +647,7 @@ func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) {
647647

648648
// UpdateComment updates information of comment.
649649
func UpdateComment(c *Comment) error {
650-
if _, err := x.Id(c.ID).AllCols().Update(c); err != nil {
650+
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
651651
return err
652652
} else if c.Type == CommentTypeComment {
653653
UpdateIssueIndexer(c.IssueID)

models/issue_label.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func GetLabelsByIssueID(issueID int64) ([]*Label, error) {
222222
}
223223

224224
func updateLabel(e Engine, l *Label) error {
225-
_, err := e.Id(l.ID).AllCols().Update(l)
225+
_, err := e.ID(l.ID).AllCols().Update(l)
226226
return err
227227
}
228228

@@ -247,7 +247,7 @@ func DeleteLabel(repoID, labelID int64) error {
247247
return err
248248
}
249249

250-
if _, err = sess.Id(labelID).Delete(new(Label)); err != nil {
250+
if _, err = sess.ID(labelID).Delete(new(Label)); err != nil {
251251
return err
252252
} else if _, err = sess.
253253
Where("label_id = ?", labelID).

models/issue_milestone.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func GetMilestones(repoID int64, page int, isClosed bool, sortType string) ([]*M
165165
}
166166

167167
func updateMilestone(e Engine, m *Milestone) error {
168-
_, err := e.Id(m.ID).AllCols().Update(m)
168+
_, err := e.ID(m.ID).AllCols().Update(m)
169169
return err
170170
}
171171

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

222222
repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
223223
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
224-
if _, err = sess.Id(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
224+
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
225225
return err
226226
}
227227
return sess.Commit()
@@ -329,13 +329,13 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
329329
return err
330330
}
331331

332-
if _, err = sess.Id(m.ID).Delete(new(Milestone)); err != nil {
332+
if _, err = sess.ID(m.ID).Delete(new(Milestone)); err != nil {
333333
return err
334334
}
335335

336336
repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
337337
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
338-
if _, err = sess.Id(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
338+
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
339339
return err
340340
}
341341

models/issue_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func UpdateIssueUsersByMentions(e Engine, issueID int64, uids []int64) error {
101101

102102
iu.IsMentioned = true
103103
if has {
104-
_, err = e.Id(iu.ID).Cols("is_mentioned").Update(iu)
104+
_, err = e.ID(iu.ID).Cols("is_mentioned").Update(iu)
105105
} else {
106106
_, err = e.Insert(iu)
107107
}

models/issue_watch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
6262
} else {
6363
iw.IsWatching = isWatching
6464

65-
if _, err := x.Id(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil {
65+
if _, err := x.ID(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil {
6666
return err
6767
}
6868
}

models/login_source.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func LoginSources() ([]*LoginSource, error) {
308308
// GetLoginSourceByID returns login source by given ID.
309309
func GetLoginSourceByID(id int64) (*LoginSource, error) {
310310
source := new(LoginSource)
311-
has, err := x.Id(id).Get(source)
311+
has, err := x.ID(id).Get(source)
312312
if err != nil {
313313
return nil, err
314314
} else if !has {
@@ -328,15 +328,15 @@ func UpdateSource(source *LoginSource) error {
328328
}
329329
}
330330

331-
_, err := x.Id(source.ID).AllCols().Update(source)
331+
_, err := x.ID(source.ID).AllCols().Update(source)
332332
if err == nil && source.IsOAuth2() && source.IsActived {
333333
oAuth2Config := source.OAuth2()
334334
err = oauth2.RegisterProvider(source.Name, oAuth2Config.Provider, oAuth2Config.ClientID, oAuth2Config.ClientSecret, oAuth2Config.OpenIDConnectAutoDiscoveryURL, oAuth2Config.CustomURLMapping)
335335
err = wrapOpenIDConnectInitializeError(err, source.Name, oAuth2Config)
336336

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

365-
_, err = x.Id(source.ID).Delete(new(LoginSource))
365+
_, err = x.ID(source.ID).Delete(new(LoginSource))
366366
return err
367367
}
368368

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

648648
default:
649649
var source LoginSource
650-
hasSource, err := x.Id(user.LoginSource).Get(&source)
650+
hasSource, err := x.ID(user.LoginSource).Get(&source)
651651
if err != nil {
652652
return nil, err
653653
} else if !hasSource {

models/migrations/migrations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to curr
173173
if int(v-minDBVersion) > len(migrations) {
174174
// User downgraded Gitea.
175175
currentVersion.Version = int64(len(migrations) + minDBVersion)
176-
_, err = x.Id(1).Update(currentVersion)
176+
_, err = x.ID(1).Update(currentVersion)
177177
return err
178178
}
179179
for i, m := range migrations[v-minDBVersion:] {
@@ -182,7 +182,7 @@ Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to curr
182182
return fmt.Errorf("do migrate: %v", err)
183183
}
184184
currentVersion.Version = v + int64(i) + 1
185-
if _, err = x.Id(1).Update(currentVersion); err != nil {
185+
if _, err = x.ID(1).Update(currentVersion); err != nil {
186186
return err
187187
}
188188
}

models/migrations/v28.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func addRepoSize(x *xorm.Engine) (err error) {
6767
}
6868

6969
repo.Size = countObject.Size + countObject.SizePack
70-
if _, err = x.Id(repo.ID).Cols("size").Update(repo); err != nil {
70+
if _, err = x.ID(repo.ID).Cols("size").Update(repo); err != nil {
7171
return fmt.Errorf("update size: %v", err)
7272
}
7373
}

models/migrations/v38.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func removeCommitsUnitType(x *xorm.Engine) (err error) {
3333
}
3434
}
3535
team.UnitTypes = ut
36-
if _, err := x.Id(team.ID).Cols("unit_types").Update(team); err != nil {
36+
if _, err := x.ID(team.ID).Cols("unit_types").Update(team); err != nil {
3737
return err
3838
}
3939
}

models/migrations/v39.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func addTimetracking(x *xorm.Engine) error {
5656
changes = true
5757
}
5858
if changes {
59-
if _, err := x.Id(unit.ID).Cols("config").Update(unit); err != nil {
59+
if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
6060
return err
6161
}
6262
}

models/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Engine interface {
3737
Exec(string, ...interface{}) (sql.Result, error)
3838
Find(interface{}, ...interface{}) error
3939
Get(interface{}) (bool, error)
40-
Id(interface{}) *xorm.Session
40+
ID(interface{}) *xorm.Session
4141
In(string, ...interface{}) *xorm.Session
4242
Incr(column string, arg ...interface{}) *xorm.Session
4343
Insert(...interface{}) (int64, error)

models/notification.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func updateIssueNotification(e Engine, userID, issueID, updatedByID int64) error
195195
notification.Status = NotificationStatusUnread
196196
notification.UpdatedBy = updatedByID
197197

198-
_, err = e.Id(notification.ID).Update(notification)
198+
_, err = e.ID(notification.ID).Update(notification)
199199
return err
200200
}
201201

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

275275
notification.Status = NotificationStatusRead
276276

277-
_, err = e.Id(notification.ID).Update(notification)
277+
_, err = e.ID(notification.ID).Update(notification)
278278
return err
279279
}
280280

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

292292
notification.Status = status
293293

294-
_, err = x.Id(notificationID).Update(notification)
294+
_, err = x.ID(notificationID).Update(notification)
295295
return err
296296
}
297297

models/org.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func deleteOrg(e *xorm.Session, u *User) error {
259259
return fmt.Errorf("deleteBeans: %v", err)
260260
}
261261

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

@@ -412,7 +412,7 @@ func ChangeOrgUserStatus(orgID, uid int64, public bool) error {
412412
}
413413

414414
ou.IsPublic = public
415-
_, err = x.Id(ou.ID).Cols("is_public").Update(ou)
415+
_, err = x.ID(ou.ID).Cols("is_public").Update(ou)
416416
return err
417417
}
418418

@@ -480,7 +480,7 @@ func RemoveOrgUser(orgID, userID int64) error {
480480
return err
481481
}
482482

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

0 commit comments

Comments
 (0)