diff options
author | Unknown <joe2010xtmf@163.com> | 2014-06-21 00:51:41 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-06-21 00:51:41 -0400 |
commit | ad5ec45dd63aa2563d113e6a9ce31180246aa5f2 (patch) | |
tree | b49f76a29faeec1bdf734375f91e5291acf09e53 /models | |
parent | 8bfa7ae7453e56191aa6f7de8067d5b6bb5a4a8b (diff) | |
download | gitea-ad5ec45dd63aa2563d113e6a9ce31180246aa5f2.tar.gz gitea-ad5ec45dd63aa2563d113e6a9ce31180246aa5f2.zip |
Fix #165
Diffstat (limited to 'models')
-rw-r--r-- | models/access.go | 8 | ||||
-rw-r--r-- | models/action.go | 2 | ||||
-rw-r--r-- | models/issue.go | 84 | ||||
-rw-r--r-- | models/login.go | 18 | ||||
-rw-r--r-- | models/models.go | 48 | ||||
-rw-r--r-- | models/oauth2.go | 32 | ||||
-rw-r--r-- | models/publickey.go | 12 | ||||
-rw-r--r-- | models/release.go | 10 | ||||
-rw-r--r-- | models/repo.go | 64 | ||||
-rw-r--r-- | models/user.go | 54 | ||||
-rw-r--r-- | models/webhook.go | 18 |
11 files changed, 178 insertions, 172 deletions
diff --git a/models/access.go b/models/access.go index 4a202dc6bc..cf31fc137b 100644 --- a/models/access.go +++ b/models/access.go @@ -30,7 +30,7 @@ type Access struct { func AddAccess(access *Access) error { access.UserName = strings.ToLower(access.UserName) access.RepoName = strings.ToLower(access.RepoName) - _, err := orm.Insert(access) + _, err := x.Insert(access) return err } @@ -38,13 +38,13 @@ func AddAccess(access *Access) error { func UpdateAccess(access *Access) error { access.UserName = strings.ToLower(access.UserName) access.RepoName = strings.ToLower(access.RepoName) - _, err := orm.Id(access.Id).Update(access) + _, err := x.Id(access.Id).Update(access) return err } // DeleteAccess deletes access record. func DeleteAccess(access *Access) error { - _, err := orm.Delete(access) + _, err := x.Delete(access) return err } @@ -67,7 +67,7 @@ func HasAccess(uname, repoName string, mode int) (bool, error) { UserName: strings.ToLower(uname), RepoName: strings.ToLower(repoName), } - has, err := orm.Get(access) + has, err := x.Get(access) if err != nil { return false, err } else if !has { diff --git a/models/action.go b/models/action.go index 2846823386..8ecdf1de16 100644 --- a/models/action.go +++ b/models/action.go @@ -209,7 +209,7 @@ func TransferRepoAction(user, newUser *User, repo *Repository) (err error) { // GetFeeds returns action list of given user in given context. func GetFeeds(userid, offset int64, isProfile bool) ([]*Action, error) { actions := make([]*Action, 0, 20) - sess := orm.Limit(20, int(offset)).Desc("id").Where("user_id=?", userid) + sess := x.Limit(20, int(offset)).Desc("id").Where("user_id=?", userid) if isProfile { sess.Where("is_private=?", false).And("act_user_id=?", userid) } else { diff --git a/models/issue.go b/models/issue.go index 7db728ec3d..11f6dd4ef9 100644 --- a/models/issue.go +++ b/models/issue.go @@ -92,7 +92,7 @@ func (i *Issue) GetAssignee() (err error) { // CreateIssue creates new issue for repository. func NewIssue(issue *Issue) (err error) { - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -114,7 +114,7 @@ func NewIssue(issue *Issue) (err error) { // GetIssueByIndex returns issue by given index in repository. func GetIssueByIndex(rid, index int64) (*Issue, error) { issue := &Issue{RepoId: rid, Index: index} - has, err := orm.Get(issue) + has, err := x.Get(issue) if err != nil { return nil, err } else if !has { @@ -126,7 +126,7 @@ func GetIssueByIndex(rid, index int64) (*Issue, error) { // GetIssueById returns an issue by ID. func GetIssueById(id int64) (*Issue, error) { issue := &Issue{Id: id} - has, err := orm.Get(issue) + has, err := x.Get(issue) if err != nil { return nil, err } else if !has { @@ -137,7 +137,7 @@ func GetIssueById(id int64) (*Issue, error) { // GetIssues returns a list of issues by given conditions. func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labelIds, sortType string) ([]Issue, error) { - sess := orm.Limit(20, (page-1)*20) + sess := x.Limit(20, (page-1)*20) if rid > 0 { sess.Where("repo_id=?", rid).And("is_closed=?", isClosed) @@ -193,13 +193,13 @@ const ( // GetIssuesByLabel returns a list of issues by given label and repository. func GetIssuesByLabel(repoId int64, label string) ([]*Issue, error) { issues := make([]*Issue, 0, 10) - err := orm.Where("repo_id=?", repoId).And("label_ids like '%$" + label + "|%'").Find(&issues) + err := x.Where("repo_id=?", repoId).And("label_ids like '%$" + label + "|%'").Find(&issues) return issues, err } // GetIssueCountByPoster returns number of issues of repository by poster. func GetIssueCountByPoster(uid, rid int64, isClosed bool) int64 { - count, _ := orm.Where("repo_id=?", rid).And("poster_id=?", uid).And("is_closed=?", isClosed).Count(new(Issue)) + count, _ := x.Where("repo_id=?", rid).And("poster_id=?", uid).And("is_closed=?", isClosed).Count(new(Issue)) return count } @@ -241,7 +241,7 @@ func NewIssueUserPairs(rid, iid, oid, pid, aid int64, repoName string) (err erro isNeedAddPoster = false } iu.IsAssigned = iu.Uid == aid - if _, err = orm.Insert(iu); err != nil { + if _, err = x.Insert(iu); err != nil { return err } } @@ -249,7 +249,7 @@ func NewIssueUserPairs(rid, iid, oid, pid, aid int64, repoName string) (err erro iu.Uid = pid iu.IsPoster = true iu.IsAssigned = iu.Uid == aid - if _, err = orm.Insert(iu); err != nil { + if _, err = x.Insert(iu); err != nil { return err } } @@ -270,7 +270,7 @@ func PairsContains(ius []*IssueUser, issueId int64) int { // GetIssueUserPairs returns issue-user pairs by given repository and user. func GetIssueUserPairs(rid, uid int64, isClosed bool) ([]*IssueUser, error) { ius := make([]*IssueUser, 0, 10) - err := orm.Where("is_closed=?", isClosed).Find(&ius, &IssueUser{RepoId: rid, Uid: uid}) + err := x.Where("is_closed=?", isClosed).Find(&ius, &IssueUser{RepoId: rid, Uid: uid}) return ius, err } @@ -285,7 +285,7 @@ func GetIssueUserPairsByRepoIds(rids []int64, isClosed bool, page int) ([]*Issue cond := strings.TrimSuffix(buf.String(), " OR ") ius := make([]*IssueUser, 0, 10) - sess := orm.Limit(20, (page-1)*20).Where("is_closed=?", isClosed) + sess := x.Limit(20, (page-1)*20).Where("is_closed=?", isClosed) if len(cond) > 0 { sess.And(cond) } @@ -296,7 +296,7 @@ func GetIssueUserPairsByRepoIds(rids []int64, isClosed bool, page int) ([]*Issue // GetIssueUserPairsByMode returns issue-user pairs by given repository and user. func GetIssueUserPairsByMode(uid, rid int64, isClosed bool, page, filterMode int) ([]*IssueUser, error) { ius := make([]*IssueUser, 0, 10) - sess := orm.Limit(20, (page-1)*20).Where("uid=?", uid).And("is_closed=?", isClosed) + sess := x.Limit(20, (page-1)*20).Where("uid=?", uid).And("is_closed=?", isClosed) if rid > 0 { sess.And("repo_id=?", rid) } @@ -335,7 +335,7 @@ func GetIssueStats(rid, uid int64, isShowClosed bool, filterMode int) *IssueStat issue := new(Issue) tmpSess := &xorm.Session{} - sess := orm.Where("repo_id=?", rid) + sess := x.Where("repo_id=?", rid) *tmpSess = *sess stats.OpenCount, _ = tmpSess.And("is_closed=?", false).Count(issue) *tmpSess = *sess @@ -347,7 +347,7 @@ func GetIssueStats(rid, uid int64, isShowClosed bool, filterMode int) *IssueStat } if filterMode != FM_MENTION { - sess = orm.Where("repo_id=?", rid) + sess = x.Where("repo_id=?", rid) switch filterMode { case FM_ASSIGN: sess.And("assignee_id=?", uid) @@ -361,16 +361,16 @@ func GetIssueStats(rid, uid int64, isShowClosed bool, filterMode int) *IssueStat *tmpSess = *sess stats.ClosedCount, _ = tmpSess.And("is_closed=?", true).Count(issue) } else { - sess := orm.Where("repo_id=?", rid).And("uid=?", uid).And("is_mentioned=?", true) + sess := x.Where("repo_id=?", rid).And("uid=?", uid).And("is_mentioned=?", true) *tmpSess = *sess stats.OpenCount, _ = tmpSess.And("is_closed=?", false).Count(new(IssueUser)) *tmpSess = *sess stats.ClosedCount, _ = tmpSess.And("is_closed=?", true).Count(new(IssueUser)) } nofilter: - stats.AssignCount, _ = orm.Where("repo_id=?", rid).And("is_closed=?", isShowClosed).And("assignee_id=?", uid).Count(issue) - stats.CreateCount, _ = orm.Where("repo_id=?", rid).And("is_closed=?", isShowClosed).And("poster_id=?", uid).Count(issue) - stats.MentionCount, _ = orm.Where("repo_id=?", rid).And("uid=?", uid).And("is_closed=?", isShowClosed).And("is_mentioned=?", true).Count(new(IssueUser)) + stats.AssignCount, _ = x.Where("repo_id=?", rid).And("is_closed=?", isShowClosed).And("assignee_id=?", uid).Count(issue) + stats.CreateCount, _ = x.Where("repo_id=?", rid).And("is_closed=?", isShowClosed).And("poster_id=?", uid).Count(issue) + stats.MentionCount, _ = x.Where("repo_id=?", rid).And("uid=?", uid).And("is_closed=?", isShowClosed).And("is_mentioned=?", true).Count(new(IssueUser)) return stats } @@ -378,28 +378,28 @@ nofilter: func GetUserIssueStats(uid int64, filterMode int) *IssueStats { stats := &IssueStats{} issue := new(Issue) - stats.AssignCount, _ = orm.Where("assignee_id=?", uid).And("is_closed=?", false).Count(issue) - stats.CreateCount, _ = orm.Where("poster_id=?", uid).And("is_closed=?", false).Count(issue) + stats.AssignCount, _ = x.Where("assignee_id=?", uid).And("is_closed=?", false).Count(issue) + stats.CreateCount, _ = x.Where("poster_id=?", uid).And("is_closed=?", false).Count(issue) return stats } // UpdateIssue updates information of issue. func UpdateIssue(issue *Issue) error { - _, err := orm.Id(issue.Id).AllCols().Update(issue) + _, err := x.Id(issue.Id).AllCols().Update(issue) return err } // UpdateIssueUserByStatus updates issue-user pairs by issue status. func UpdateIssueUserPairsByStatus(iid int64, isClosed bool) error { rawSql := "UPDATE `issue_user` SET is_closed = ? WHERE issue_id = ?" - _, err := orm.Exec(rawSql, isClosed, iid) + _, err := x.Exec(rawSql, isClosed, iid) return err } // UpdateIssueUserPairByAssignee updates issue-user pair for assigning. func UpdateIssueUserPairByAssignee(aid, iid int64) error { rawSql := "UPDATE `issue_user` SET is_assigned = ? WHERE issue_id = ?" - if _, err := orm.Exec(rawSql, false, iid); err != nil { + if _, err := x.Exec(rawSql, false, iid); err != nil { return err } @@ -408,14 +408,14 @@ func UpdateIssueUserPairByAssignee(aid, iid int64) error { return nil } rawSql = "UPDATE `issue_user` SET is_assigned = true WHERE uid = ? AND issue_id = ?" - _, err := orm.Exec(rawSql, aid, iid) + _, err := x.Exec(rawSql, aid, iid) return err } // UpdateIssueUserPairByRead updates issue-user pair for reading. func UpdateIssueUserPairByRead(uid, iid int64) error { rawSql := "UPDATE `issue_user` SET is_read = ? WHERE uid = ? AND issue_id = ?" - _, err := orm.Exec(rawSql, true, uid, iid) + _, err := x.Exec(rawSql, true, uid, iid) return err } @@ -423,16 +423,16 @@ func UpdateIssueUserPairByRead(uid, iid int64) error { func UpdateIssueUserPairsByMentions(uids []int64, iid int64) error { for _, uid := range uids { iu := &IssueUser{Uid: uid, IssueId: iid} - has, err := orm.Get(iu) + has, err := x.Get(iu) if err != nil { return err } iu.IsMentioned = true if has { - _, err = orm.Id(iu.Id).AllCols().Update(iu) + _, err = x.Id(iu.Id).AllCols().Update(iu) } else { - _, err = orm.Insert(iu) + _, err = x.Insert(iu) } if err != nil { return err @@ -467,7 +467,7 @@ func (m *Label) CalOpenIssues() { // NewLabel creates new label of repository. func NewLabel(l *Label) error { - _, err := orm.Insert(l) + _, err := x.Insert(l) return err } @@ -478,7 +478,7 @@ func GetLabelById(id int64) (*Label, error) { } l := &Label{Id: id} - has, err := orm.Get(l) + has, err := x.Get(l) if err != nil { return nil, err } else if !has { @@ -490,13 +490,13 @@ func GetLabelById(id int64) (*Label, error) { // GetLabels returns a list of labels of given repository ID. func GetLabels(repoId int64) ([]*Label, error) { labels := make([]*Label, 0, 10) - err := orm.Where("repo_id=?", repoId).Find(&labels) + err := x.Where("repo_id=?", repoId).Find(&labels) return labels, err } // UpdateLabel updates label information. func UpdateLabel(l *Label) error { - _, err := orm.Id(l.Id).Update(l) + _, err := x.Id(l.Id).Update(l) return err } @@ -516,7 +516,7 @@ func DeleteLabel(repoId int64, strId string) error { return err } - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -569,7 +569,7 @@ func (m *Milestone) CalOpenIssues() { // NewMilestone creates new milestone of repository. func NewMilestone(m *Milestone) (err error) { - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -591,7 +591,7 @@ func NewMilestone(m *Milestone) (err error) { // GetMilestoneById returns the milestone by given ID. func GetMilestoneById(id int64) (*Milestone, error) { m := &Milestone{Id: id} - has, err := orm.Get(m) + has, err := x.Get(m) if err != nil { return nil, err } else if !has { @@ -603,7 +603,7 @@ func GetMilestoneById(id int64) (*Milestone, error) { // GetMilestoneByIndex returns the milestone of given repository and index. func GetMilestoneByIndex(repoId, idx int64) (*Milestone, error) { m := &Milestone{RepoId: repoId, Index: idx} - has, err := orm.Get(m) + has, err := x.Get(m) if err != nil { return nil, err } else if !has { @@ -615,13 +615,13 @@ func GetMilestoneByIndex(repoId, idx int64) (*Milestone, error) { // GetMilestones returns a list of milestones of given repository and status. func GetMilestones(repoId int64, isClosed bool) ([]*Milestone, error) { miles := make([]*Milestone, 0, 10) - err := orm.Where("repo_id=?", repoId).And("is_closed=?", isClosed).Find(&miles) + err := x.Where("repo_id=?", repoId).And("is_closed=?", isClosed).Find(&miles) return miles, err } // UpdateMilestone updates information of given milestone. func UpdateMilestone(m *Milestone) error { - _, err := orm.Id(m.Id).Update(m) + _, err := x.Id(m.Id).Update(m) return err } @@ -632,7 +632,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { return err } - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -658,7 +658,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { // ChangeMilestoneAssign changes assignment of milestone for issue. func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) { - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -717,7 +717,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) { // DeleteMilestone deletes a milestone. func DeleteMilestone(m *Milestone) (err error) { - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -777,7 +777,7 @@ type Comment struct { // CreateComment creates comment of issue or commit. func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, content string) error { - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err @@ -816,6 +816,6 @@ func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, c // GetIssueComments returns list of comment by given issue id. func GetIssueComments(issueId int64) ([]Comment, error) { comments := make([]Comment, 0, 10) - err := orm.Asc("created").Find(&comments, &Comment{IssueId: issueId}) + err := x.Asc("created").Find(&comments, &Comment{IssueId: issueId}) return comments, err } diff --git a/models/login.go b/models/login.go index 863ba44e20..98c5c64e40 100644 --- a/models/login.go +++ b/models/login.go @@ -109,19 +109,19 @@ func (source *LoginSource) BeforeSet(colName string, val xorm.Cell) { } func CreateSource(source *LoginSource) error { - _, err := orm.Insert(source) + _, err := x.Insert(source) return err } func GetAuths() ([]*LoginSource, error) { var auths = make([]*LoginSource, 0, 5) - err := orm.Find(&auths) + err := x.Find(&auths) return auths, err } func GetLoginSourceById(id int64) (*LoginSource, error) { source := new(LoginSource) - has, err := orm.Id(id).Get(source) + has, err := x.Id(id).Get(source) if err != nil { return nil, err } else if !has { @@ -131,19 +131,19 @@ func GetLoginSourceById(id int64) (*LoginSource, error) { } func UpdateSource(source *LoginSource) error { - _, err := orm.Id(source.Id).AllCols().Update(source) + _, err := x.Id(source.Id).AllCols().Update(source) return err } func DelLoginSource(source *LoginSource) error { - cnt, err := orm.Count(&User{LoginSource: source.Id}) + cnt, err := x.Count(&User{LoginSource: source.Id}) if err != nil { return err } if cnt > 0 { return ErrAuthenticationUserUsed } - _, err = orm.Id(source.Id).Delete(&LoginSource{}) + _, err = x.Id(source.Id).Delete(&LoginSource{}) return err } @@ -156,7 +156,7 @@ func UserSignIn(uname, passwd string) (*User, error) { u = &User{LowerName: strings.ToLower(uname)} } - has, err := orm.Get(u) + has, err := x.Get(u) if err != nil { return nil, err } @@ -182,7 +182,7 @@ func UserSignIn(uname, passwd string) (*User, error) { } else { if !has { var sources []LoginSource - if err = orm.UseBool().Find(&sources, + if err = x.UseBool().Find(&sources, &LoginSource{IsActived: true, AllowAutoRegister: true}); err != nil { return nil, err } @@ -209,7 +209,7 @@ func UserSignIn(uname, passwd string) (*User, error) { } var source LoginSource - hasSource, err := orm.Id(u.LoginSource).Get(&source) + hasSource, err := x.Id(u.LoginSource).Get(&source) if err != nil { return nil, err } else if !hasSource { diff --git a/models/models.go b/models/models.go index a59c051712..d6273d7f98 100644 --- a/models/models.go +++ b/models/models.go @@ -18,7 +18,7 @@ import ( ) var ( - orm *xorm.Engine + x *xorm.Engine tables []interface{} HasEngine bool @@ -88,7 +88,7 @@ func NewTestEngine(x *xorm.Engine) (err error) { func SetEngine() (err error) { switch DbCfg.Type { case "mysql": - orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", + x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) case "postgres": var host, port = "127.0.0.1", "5432" @@ -99,11 +99,11 @@ func SetEngine() (err error) { if len(fields) > 1 && len(strings.TrimSpace(fields[1])) > 0 { port = fields[1] } - orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s", + x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s", DbCfg.User, DbCfg.Pwd, host, port, DbCfg.Name, DbCfg.SslMode)) case "sqlite3": os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) - orm, err = xorm.NewEngine("sqlite3", DbCfg.Path) + x, err = xorm.NewEngine("sqlite3", DbCfg.Path) default: return fmt.Errorf("Unknown database type: %s", DbCfg.Type) } @@ -120,11 +120,11 @@ func SetEngine() (err error) { if err != nil { return fmt.Errorf("models.init(fail to create xorm.log): %v", err) } - orm.Logger = xorm.NewSimpleLogger(f) + x.Logger = xorm.NewSimpleLogger(f) - orm.ShowSQL = true - orm.ShowDebug = true - orm.ShowErr = true + x.ShowSQL = true + x.ShowDebug = true + x.ShowErr = true return nil } @@ -132,7 +132,7 @@ func NewEngine() (err error) { if err = SetEngine(); err != nil { return err } - if err = orm.Sync(tables...); err != nil { + if err = x.Sync2(tables...); err != nil { return fmt.Errorf("sync database struct error: %v\n", err) } return nil @@ -147,24 +147,24 @@ type Statistic struct { } func GetStatistic() (stats Statistic) { - stats.Counter.User, _ = orm.Count(new(User)) - stats.Counter.PublicKey, _ = orm.Count(new(PublicKey)) - stats.Counter.Repo, _ = orm.Count(new(Repository)) - stats.Counter.Watch, _ = orm.Count(new(Watch)) - stats.Counter.Action, _ = orm.Count(new(Action)) - stats.Counter.Access, _ = orm.Count(new(Access)) - stats.Counter.Issue, _ = orm.Count(new(Issue)) - stats.Counter.Comment, _ = orm.Count(new(Comment)) - stats.Counter.Mirror, _ = orm.Count(new(Mirror)) - stats.Counter.Oauth, _ = orm.Count(new(Oauth2)) - stats.Counter.Release, _ = orm.Count(new(Release)) - stats.Counter.LoginSource, _ = orm.Count(new(LoginSource)) - stats.Counter.Webhook, _ = orm.Count(new(Webhook)) - stats.Counter.Milestone, _ = orm.Count(new(Milestone)) + stats.Counter.User, _ = x.Count(new(User)) + stats.Counter.PublicKey, _ = x.Count(new(PublicKey)) + stats.Counter.Repo, _ = x.Count(new(Repository)) + stats.Counter.Watch, _ = x.Count(new(Watch)) + stats.Counter.Action, _ = x.Count(new(Action)) + stats.Counter.Access, _ = x.Count(new(Access)) + stats.Counter.Issue, _ = x.Count(new(Issue)) + stats.Counter.Comment, _ = x.Count(new(Comment)) + stats.Counter.Mirror, _ = x.Count(new(Mirror)) + stats.Counter.Oauth, _ = x.Count(new(Oauth2)) + stats.Counter.Release, _ = x.Count(new(Release)) + stats.Counter.LoginSource, _ = x.Count(new(LoginSource)) + stats.Counter.Webhook, _ = x.Count(new(Webhook)) + stats.Counter.Milestone, _ = x.Count(new(Milestone)) return } // DumpDatabase dumps all data from database to file system. func DumpDatabase(filePath string) error { - return orm.DumpAllToFile(filePath) + return x.DumpAllToFile(filePath) } diff --git a/models/oauth2.go b/models/oauth2.go index 61044d6882..4b024a26e4 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -8,16 +8,16 @@ import ( "errors" ) -// OT: Oauth2 Type +type OauthType int + const ( - OT_GITHUB = iota + 1 - OT_GOOGLE - OT_TWITTER - OT_QQ - OT_WEIBO - OT_BITBUCKET - OT_OSCHINA - OT_FACEBOOK + GITHUB OauthType = iota + 1 + GOOGLE + TWITTER + QQ + WEIBO + BITBUCKET + FACEBOOK ) var ( @@ -35,18 +35,18 @@ type Oauth2 struct { } func BindUserOauth2(userId, oauthId int64) error { - _, err := orm.Id(oauthId).Update(&Oauth2{Uid: userId}) + _, err := x.Id(oauthId).Update(&Oauth2{Uid: userId}) return err } func AddOauth2(oa *Oauth2) error { - _, err := orm.Insert(oa) + _, err := x.Insert(oa) return err } func GetOauth2(identity string) (oa *Oauth2, err error) { oa = &Oauth2{Identity: identity} - isExist, err := orm.Get(oa) + isExist, err := x.Get(oa) if err != nil { return } else if !isExist { @@ -60,7 +60,7 @@ func GetOauth2(identity string) (oa *Oauth2, err error) { func GetOauth2ById(id int64) (oa *Oauth2, err error) { oa = new(Oauth2) - has, err := orm.Id(id).Get(oa) + has, err := x.Id(id).Get(oa) if err != nil { return nil, err } else if !has { @@ -71,18 +71,18 @@ func GetOauth2ById(id int64) (oa *Oauth2, err error) { // GetOauthByUserId returns list of oauthes that are releated to given user. func GetOauthByUserId(uid int64) (oas []*Oauth2, err error) { - err = orm.Find(&oas, Oauth2{Uid: uid}) + err = x.Find(&oas, Oauth2{Uid: uid}) return oas, err } // DeleteOauth2ById deletes a oauth2 by ID. func DeleteOauth2ById(id int64) error { - _, err := orm.Delete(&Oauth2{Id: id}) + _, err := x.Delete(&Oauth2{Id: id}) return err } // CleanUnbindOauth deletes all unbind OAuthes. func CleanUnbindOauth() error { - _, err := orm.Delete(&Oauth2{Uid: -1}) + _, err := x.Delete(&Oauth2{Uid: -1}) return err } diff --git a/models/publickey.go b/models/publickey.go index b0021a6880..35768b4893 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -107,7 +107,7 @@ func saveAuthorizedKeyFile(key *PublicKey) error { // AddPublicKey adds new public key to database and authorized_keys file. func AddPublicKey(key *PublicKey) (err error) { - has, err := orm.Get(key) + has, err := x.Get(key) if err != nil { return err } else if has { @@ -130,11 +130,11 @@ func AddPublicKey(key *PublicKey) (err error) { key.Fingerprint = strings.Split(stdout, " ")[1] // Save SSH key. - if _, err = orm.Insert(key); err != nil { + if _, err = x.Insert(key); err != nil { return err } else if err = saveAuthorizedKeyFile(key); err != nil { // Roll back. - if _, err2 := orm.Delete(key); err2 != nil { + if _, err2 := x.Delete(key); err2 != nil { return err2 } return err @@ -146,7 +146,7 @@ func AddPublicKey(key *PublicKey) (err error) { // ListPublicKey returns a list of all public keys that user has. func ListPublicKey(uid int64) ([]PublicKey, error) { keys := make([]PublicKey, 0, 5) - err := orm.Find(&keys, &PublicKey{OwnerId: uid}) + err := x.Find(&keys, &PublicKey{OwnerId: uid}) return keys, err } @@ -205,14 +205,14 @@ func rewriteAuthorizedKeys(key *PublicKey, p, tmpP string) error { // DeletePublicKey deletes SSH key information both in database and authorized_keys file. func DeletePublicKey(key *PublicKey) error { - has, err := orm.Get(key) + has, err := x.Get(key) if err != nil { return err } else if !has { return ErrKeyNotExist } - if _, err = orm.Delete(key); err != nil { + if _, err = x.Delete(key); err != nil { return err } diff --git a/models/release.go b/models/release.go index 32e8c92cc4..3e1a78118c 100644 --- a/models/release.go +++ b/models/release.go @@ -43,7 +43,7 @@ func IsReleaseExist(repoId int64, tagName string) (bool, error) { return false, nil } - return orm.Get(&Release{RepoId: repoId, LowerTagName: strings.ToLower(tagName)}) + return x.Get(&Release{RepoId: repoId, LowerTagName: strings.ToLower(tagName)}) } func createTag(gitRepo *git.Repository, rel *Release) error { @@ -86,7 +86,7 @@ func CreateRelease(gitRepo *git.Repository, rel *Release) error { return err } rel.LowerTagName = strings.ToLower(rel.TagName) - _, err = orm.InsertOne(rel) + _, err = x.InsertOne(rel) return err } @@ -100,13 +100,13 @@ func GetRelease(repoId int64, tagName string) (*Release, error) { } rel := &Release{RepoId: repoId, LowerTagName: strings.ToLower(tagName)} - _, err = orm.Get(rel) + _, err = x.Get(rel) return rel, err } // GetReleasesByRepoId returns a list of releases of repository. func GetReleasesByRepoId(repoId int64) (rels []*Release, err error) { - err = orm.Desc("created").Find(&rels, Release{RepoId: repoId}) + err = x.Desc("created").Find(&rels, Release{RepoId: repoId}) return rels, err } @@ -141,6 +141,6 @@ func UpdateRelease(gitRepo *git.Repository, rel *Release) (err error) { if err = createTag(gitRepo, rel); err != nil { return err } - _, err = orm.Id(rel.Id).AllCols().Update(rel) + _, err = x.Id(rel.Id).AllCols().Update(rel) return err } diff --git a/models/repo.go b/models/repo.go index 6b98d0e409..4ccaccbf81 100644 --- a/models/repo.go +++ b/models/repo.go @@ -147,7 +147,7 @@ func (repo *Repository) GetOwner() (err error) { // IsRepositoryExist returns true if the repository with given name under user has already existed. func IsRepositoryExist(u *User, repoName string) (bool, error) { repo := Repository{OwnerId: u.Id} - has, err := orm.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo) + has, err := x.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo) if err != nil { return has, err } else if !has { @@ -197,7 +197,7 @@ func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) er return errors.New("git clone --mirror: " + stderr) } - if _, err = orm.InsertOne(&Mirror{ + if _, err = x.InsertOne(&Mirror{ RepoId: repoId, RepoName: strings.ToLower(userName + "/" + repoName), Interval: 24, @@ -211,7 +211,7 @@ func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) er func GetMirror(repoId int64) (*Mirror, error) { m := &Mirror{RepoId: repoId} - has, err := orm.Get(m) + has, err := x.Get(m) if err != nil { return nil, err } else if !has { @@ -221,13 +221,13 @@ func GetMirror(repoId int64) (*Mirror, error) { } func UpdateMirror(m *Mirror) error { - _, err := orm.Id(m.Id).Update(m) + _, err := x.Id(m.Id).Update(m) return err } // MirrorUpdate checks and updates mirror repositories. func MirrorUpdate() { - if err := orm.Iterate(new(Mirror), func(idx int, bean interface{}) error { + if err := x.Iterate(new(Mirror), func(idx int, bean interface{}) error { m := bean.(*Mirror) if m.NextUpdate.After(time.Now()) { return nil @@ -481,7 +481,7 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir repoPath := RepoPath(user.Name, repo.Name) - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() sess.Begin() @@ -566,13 +566,13 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir // It also auto-gets corresponding users. func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) { repos := make([]*Repository, 0, num) - if err := orm.Limit(num, offset).Asc("id").Find(&repos); err != nil { + if err := x.Limit(num, offset).Asc("id").Find(&repos); err != nil { return nil, err } for _, repo := range repos { repo.Owner = &User{Id: repo.OwnerId} - has, err := orm.Get(repo.Owner) + has, err := x.Get(repo.Owner) if err != nil { return nil, err } else if !has { @@ -597,11 +597,11 @@ func TransferOwnership(user *User, newOwner string, repo *Repository) (err error // Update accesses. accesses := make([]Access, 0, 10) - if err = orm.Find(&accesses, &Access{RepoName: user.LowerName + "/" + repo.LowerName}); err != nil { + if err = x.Find(&accesses, &Access{RepoName: user.LowerName + "/" + repo.LowerName}); err != nil { return err } - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -662,11 +662,11 @@ func TransferOwnership(user *User, newOwner string, repo *Repository) (err error func ChangeRepositoryName(userName, oldRepoName, newRepoName string) (err error) { // Update accesses. accesses := make([]Access, 0, 10) - if err = orm.Find(&accesses, &Access{RepoName: strings.ToLower(userName + "/" + oldRepoName)}); err != nil { + if err = x.Find(&accesses, &Access{RepoName: strings.ToLower(userName + "/" + oldRepoName)}); err != nil { return err } - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -697,21 +697,21 @@ func UpdateRepository(repo *Repository) error { if len(repo.Website) > 255 { repo.Website = repo.Website[:255] } - _, err := orm.Id(repo.Id).AllCols().Update(repo) + _, err := x.Id(repo.Id).AllCols().Update(repo) return err } // DeleteRepository deletes a repository for a user or orgnaztion. func DeleteRepository(userId, repoId int64, userName string) (err error) { repo := &Repository{Id: repoId, OwnerId: userId} - has, err := orm.Get(repo) + has, err := x.Get(repo) if err != nil { return err } else if !has { return ErrRepoNotExist } - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -750,7 +750,7 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) { } // Delete comments. - if err = orm.Iterate(&Issue{RepoId: repoId}, func(idx int, bean interface{}) error { + if err = x.Iterate(&Issue{RepoId: repoId}, func(idx int, bean interface{}) error { issue := bean.(*Issue) if _, err = sess.Delete(&Comment{IssueId: issue.Id}); err != nil { sess.Rollback() @@ -785,7 +785,7 @@ func GetRepositoryByName(userId int64, repoName string) (*Repository, error) { OwnerId: userId, LowerName: strings.ToLower(repoName), } - has, err := orm.Get(repo) + has, err := x.Get(repo) if err != nil { return nil, err } else if !has { @@ -797,7 +797,7 @@ func GetRepositoryByName(userId int64, repoName string) (*Repository, error) { // GetRepositoryById returns the repository by given id if exists. func GetRepositoryById(id int64) (*Repository, error) { repo := &Repository{} - has, err := orm.Id(id).Get(repo) + has, err := x.Id(id).Get(repo) if err != nil { return nil, err } else if !has { @@ -809,7 +809,7 @@ func GetRepositoryById(id int64) (*Repository, error) { // GetRepositories returns a list of repositories of given user. func GetRepositories(uid int64, private bool) ([]*Repository, error) { repos := make([]*Repository, 0, 10) - sess := orm.Desc("updated") + sess := x.Desc("updated") if !private { sess.Where("is_private=?", false) } @@ -820,19 +820,19 @@ func GetRepositories(uid int64, private bool) ([]*Repository, error) { // GetRecentUpdatedRepositories returns the list of repositories that are recently updated. func GetRecentUpdatedRepositories() (repos []*Repository, err error) { - err = orm.Where("is_private=?", false).Limit(5).Desc("updated").Find(&repos) + err = x.Where("is_private=?", false).Limit(5).Desc("updated").Find(&repos) return repos, err } // GetRepositoryCount returns the total number of repositories of user. func GetRepositoryCount(user *User) (int64, error) { - return orm.Count(&Repository{OwnerId: user.Id}) + return x.Count(&Repository{OwnerId: user.Id}) } // GetCollaboratorNames returns a list of user name of repository's collaborators. func GetCollaboratorNames(repoName string) ([]string, error) { accesses := make([]*Access, 0, 10) - if err := orm.Find(&accesses, &Access{RepoName: strings.ToLower(repoName)}); err != nil { + if err := x.Find(&accesses, &Access{RepoName: strings.ToLower(repoName)}); err != nil { return nil, err } @@ -847,7 +847,7 @@ func GetCollaboratorNames(repoName string) ([]string, error) { func GetCollaborativeRepos(uname string) ([]*Repository, error) { uname = strings.ToLower(uname) accesses := make([]*Access, 0, 10) - if err := orm.Find(&accesses, &Access{UserName: uname}); err != nil { + if err := x.Find(&accesses, &Access{UserName: uname}); err != nil { return nil, err } @@ -876,7 +876,7 @@ func GetCollaborativeRepos(uname string) ([]*Repository, error) { // GetCollaborators returns a list of users of repository's collaborators. func GetCollaborators(repoName string) (us []*User, err error) { accesses := make([]*Access, 0, 10) - if err = orm.Find(&accesses, &Access{RepoName: strings.ToLower(repoName)}); err != nil { + if err = x.Find(&accesses, &Access{RepoName: strings.ToLower(repoName)}); err != nil { return nil, err } @@ -900,18 +900,18 @@ type Watch struct { // Watch or unwatch repository. func WatchRepo(uid, rid int64, watch bool) (err error) { if watch { - if _, err = orm.Insert(&Watch{RepoId: rid, UserId: uid}); err != nil { + if _, err = x.Insert(&Watch{RepoId: rid, UserId: uid}); err != nil { return err } rawSql := "UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?" - _, err = orm.Exec(rawSql, rid) + _, err = x.Exec(rawSql, rid) } else { - if _, err = orm.Delete(&Watch{0, uid, rid}); err != nil { + if _, err = x.Delete(&Watch{0, uid, rid}); err != nil { return err } rawSql := "UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?" - _, err = orm.Exec(rawSql, rid) + _, err = x.Exec(rawSql, rid) } return err } @@ -919,7 +919,7 @@ func WatchRepo(uid, rid int64, watch bool) (err error) { // GetWatchers returns all watchers of given repository. func GetWatchers(rid int64) ([]*Watch, error) { watches := make([]*Watch, 0, 10) - err := orm.Find(&watches, &Watch{RepoId: rid}) + err := x.Find(&watches, &Watch{RepoId: rid}) return watches, err } @@ -933,7 +933,7 @@ func NotifyWatchers(act *Action) error { // Add feed for actioner. act.UserId = act.ActUserId - if _, err = orm.InsertOne(act); err != nil { + if _, err = x.InsertOne(act); err != nil { return errors.New("repo.NotifyWatchers(create action): " + err.Error()) } @@ -944,7 +944,7 @@ func NotifyWatchers(act *Action) error { act.Id = 0 act.UserId = watches[i].UserId - if _, err = orm.InsertOne(act); err != nil { + if _, err = x.InsertOne(act); err != nil { return errors.New("repo.NotifyWatchers(create action): " + err.Error()) } } @@ -953,7 +953,7 @@ func NotifyWatchers(act *Action) error { // IsWatching checks if user has watched given repository. func IsWatching(uid, rid int64) bool { - has, _ := orm.Get(&Watch{0, uid, rid}) + has, _ := x.Get(&Watch{0, uid, rid}) return has } diff --git a/models/user.go b/models/user.go index 04ea1fd692..50d81c942d 100644 --- a/models/user.go +++ b/models/user.go @@ -110,7 +110,7 @@ func IsUserExist(name string) (bool, error) { if len(name) == 0 { return false, nil } - return orm.Get(&User{LowerName: strings.ToLower(name)}) + return x.Get(&User{LowerName: strings.ToLower(name)}) } // IsEmailUsed returns true if the e-mail has been used. @@ -118,7 +118,7 @@ func IsEmailUsed(email string) (bool, error) { if len(email) == 0 { return false, nil } - return orm.Get(&User{Email: email}) + return x.Get(&User{Email: email}) } // GetUserSalt returns a user salt token @@ -153,10 +153,10 @@ func RegisterUser(user *User) (*User, error) { user.Rands = GetUserSalt() user.Salt = GetUserSalt() user.EncodePasswd() - if _, err = orm.Insert(user); err != nil { + if _, err = x.Insert(user); err != nil { return nil, err } else if err = os.MkdirAll(UserPath(user.Name), os.ModePerm); err != nil { - if _, err := orm.Id(user.Id).Delete(&User{}); err != nil { + if _, err := x.Id(user.Id).Delete(&User{}); err != nil { return nil, errors.New(fmt.Sprintf( "both create userpath %s and delete table record faild: %v", user.Name, err)) } @@ -166,7 +166,7 @@ func RegisterUser(user *User) (*User, error) { if user.Id == 1 { user.IsAdmin = true user.IsActive = true - _, err = orm.Id(user.Id).UseBool().Update(user) + _, err = x.Id(user.Id).UseBool().Update(user) } return user, err } @@ -174,7 +174,7 @@ func RegisterUser(user *User) (*User, error) { // GetUsers returns given number of user objects with offset. func GetUsers(num, offset int) ([]User, error) { users := make([]User, 0, num) - err := orm.Limit(num, offset).Asc("id").Find(&users) + err := x.Limit(num, offset).Asc("id").Find(&users) return users, err } @@ -218,11 +218,11 @@ func ChangeUserName(user *User, newUserName string) (err error) { // Update accesses of user. accesses := make([]Access, 0, 10) - if err = orm.Find(&accesses, &Access{UserName: user.LowerName}); err != nil { + if err = x.Find(&accesses, &Access{UserName: user.LowerName}); err != nil { return err } - sess := orm.NewSession() + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err @@ -245,7 +245,7 @@ func ChangeUserName(user *User, newUserName string) (err error) { for i := range repos { accesses = make([]Access, 0, 10) // Update accesses of user repository. - if err = orm.Find(&accesses, &Access{RepoName: user.LowerName + "/" + repos[i].LowerName}); err != nil { + if err = x.Find(&accesses, &Access{RepoName: user.LowerName + "/" + repos[i].LowerName}); err != nil { return err } @@ -278,7 +278,7 @@ func UpdateUser(u *User) (err error) { u.Website = u.Website[:255] } - _, err = orm.Id(u.Id).AllCols().Update(u) + _, err = x.Id(u.Id).AllCols().Update(u) return err } @@ -295,33 +295,33 @@ func DeleteUser(user *User) error { // TODO: check issues, other repos' commits // Delete all followers. - if _, err = orm.Delete(&Follow{FollowId: user.Id}); err != nil { + if _, err = x.Delete(&Follow{FollowId: user.Id}); err != nil { return err } // Delete oauth2. - if _, err = orm.Delete(&Oauth2{Uid: user.Id}); err != nil { + if _, err = x.Delete(&Oauth2{Uid: user.Id}); err != nil { return err } // Delete all feeds. - if _, err = orm.Delete(&Action{UserId: user.Id}); err != nil { + if _, err = x.Delete(&Action{UserId: user.Id}); err != nil { return err } // Delete all watches. - if _, err = orm.Delete(&Watch{UserId: user.Id}); err != nil { + if _, err = x.Delete(&Watch{UserId: user.Id}); err != nil { return err } // Delete all accesses. - if _, err = orm.Delete(&Access{UserName: user.LowerName}); err != nil { + if _, err = x.Delete(&Access{UserName: user.LowerName}); err != nil { return err } // Delete all SSH keys. keys := make([]*PublicKey, 0, 10) - if err = orm.Find(&keys, &PublicKey{OwnerId: user.Id}); err != nil { + if err = x.Find(&keys, &PublicKey{OwnerId: user.Id}); err != nil { return err } for _, key := range keys { @@ -335,7 +335,13 @@ func DeleteUser(user *User) error { return err } - _, err = orm.Delete(user) + _, err = x.Delete(user) + return err +} + +// DeleteInactivateUsers deletes all inactivate users. +func DeleteInactivateUsers() error { + _, err := x.Where("is_active=?", false).Delete(new(User)) return err } @@ -347,7 +353,7 @@ func UserPath(userName string) string { func GetUserByKeyId(keyId int64) (*User, error) { user := new(User) rawSql := "SELECT a.* FROM `user` AS a, public_key AS b WHERE a.id = b.owner_id AND b.id=?" - has, err := orm.Sql(rawSql, keyId).Get(user) + has, err := x.Sql(rawSql, keyId).Get(user) if err != nil { return nil, err } else if !has { @@ -359,7 +365,7 @@ func GetUserByKeyId(keyId int64) (*User, error) { // GetUserById returns the user object by given ID if exists. func GetUserById(id int64) (*User, error) { u := new(User) - has, err := orm.Id(id).Get(u) + has, err := x.Id(id).Get(u) if err != nil { return nil, err } else if !has { @@ -374,7 +380,7 @@ func GetUserByName(name string) (*User, error) { return nil, ErrUserNotExist } user := &User{LowerName: strings.ToLower(name)} - has, err := orm.Get(user) + has, err := x.Get(user) if err != nil { return nil, err } else if !has { @@ -415,7 +421,7 @@ func GetUserByEmail(email string) (*User, error) { return nil, ErrUserNotExist } user := &User{Email: strings.ToLower(email)} - has, err := orm.Get(user) + has, err := x.Get(user) if err != nil { return nil, err } else if !has { @@ -439,7 +445,7 @@ func SearchUserByName(key string, limit int) (us []*User, err error) { key = strings.ToLower(key) us = make([]*User, 0, limit) - err = orm.Limit(limit).Where("lower_name like '%" + key + "%'").Find(&us) + err = x.Limit(limit).Where("lower_name like '%" + key + "%'").Find(&us) return us, err } @@ -452,7 +458,7 @@ type Follow struct { // FollowUser marks someone be another's follower. func FollowUser(userId int64, followId int64) (err error) { - session := orm.NewSession() + session := x.NewSession() defer session.Close() session.Begin() @@ -477,7 +483,7 @@ func FollowUser(userId int64, followId int64) (err error) { // UnFollowUser unmarks someone be another's follower. func UnFollowUser(userId int64, unFollowId int64) (err error) { - session := orm.NewSession() + session := x.NewSession() defer session.Close() session.Begin() diff --git a/models/webhook.go b/models/webhook.go index ffd47c8f9b..9044befba2 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -68,14 +68,14 @@ func (w *Webhook) HasPushEvent() bool { // CreateWebhook creates a new web hook. func CreateWebhook(w *Webhook) error { - _, err := orm.Insert(w) + _, err := x.Insert(w) return err } // GetWebhookById returns webhook by given ID. func GetWebhookById(hookId int64) (*Webhook, error) { w := &Webhook{Id: hookId} - has, err := orm.Get(w) + has, err := x.Get(w) if err != nil { return nil, err } else if !has { @@ -86,25 +86,25 @@ func GetWebhookById(hookId int64) (*Webhook, error) { // GetActiveWebhooksByRepoId returns all active webhooks of repository. func GetActiveWebhooksByRepoId(repoId int64) (ws []*Webhook, err error) { - err = orm.Find(&ws, &Webhook{RepoId: repoId, IsActive: true}) + err = x.Find(&ws, &Webhook{RepoId: repoId, IsActive: true}) return ws, err } // GetWebhooksByRepoId returns all webhooks of repository. func GetWebhooksByRepoId(repoId int64) (ws []*Webhook, err error) { - err = orm.Find(&ws, &Webhook{RepoId: repoId}) + err = x.Find(&ws, &Webhook{RepoId: repoId}) return ws, err } // UpdateWebhook updates information of webhook. func UpdateWebhook(w *Webhook) error { - _, err := orm.AllCols().Update(w) + _, err := x.AllCols().Update(w) return err } // DeleteWebhook deletes webhook of repository. func DeleteWebhook(hookId int64) error { - _, err := orm.Delete(&Webhook{Id: hookId}) + _, err := x.Delete(&Webhook{Id: hookId}) return err } @@ -174,20 +174,20 @@ func CreateHookTask(t *HookTask) error { return err } t.PayloadContent = string(data) - _, err = orm.Insert(t) + _, err = x.Insert(t) return err } // UpdateHookTask updates information of hook task. func UpdateHookTask(t *HookTask) error { - _, err := orm.AllCols().Update(t) + _, err := x.AllCols().Update(t) return err } // DeliverHooks checks and delivers undelivered hooks. func DeliverHooks() { timeout := time.Duration(setting.WebhookDeliverTimeout) * time.Second - orm.Where("is_deliveried=?", false).Iterate(new(HookTask), + x.Where("is_deliveried=?", false).Iterate(new(HookTask), func(idx int, bean interface{}) error { t := bean.(*HookTask) // Only support JSON now. |