diff options
Diffstat (limited to 'models/issue_milestone.go')
-rw-r--r-- | models/issue_milestone.go | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/models/issue_milestone.go b/models/issue_milestone.go index fd5d052cbd..de4e13b4bb 100644 --- a/models/issue_milestone.go +++ b/models/issue_milestone.go @@ -85,22 +85,22 @@ func (m *Milestone) State() api.StateType { // NewMilestone creates new milestone of repository. func NewMilestone(m *Milestone) (err error) { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err = sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() m.Name = strings.TrimSpace(m.Name) - if _, err = sess.Insert(m); err != nil { + if err = db.Insert(ctx, m); err != nil { return err } - if _, err = sess.Exec("UPDATE `repository` SET num_milestones = num_milestones + 1 WHERE id = ?", m.RepoID); err != nil { + if _, err = db.Exec(ctx, "UPDATE `repository` SET num_milestones = num_milestones + 1 WHERE id = ?", m.RepoID); err != nil { return err } - return sess.Commit() + return committer.Commit() } func getMilestoneByRepoID(e db.Engine, repoID, id int64) (*Milestone, error) { @@ -150,11 +150,13 @@ func getMilestoneByID(e db.Engine, id int64) (*Milestone, error) { // UpdateMilestone updates information of given milestone. func UpdateMilestone(m *Milestone, oldIsClosed bool) error { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() + + sess := db.GetEngine(ctx) if m.IsClosed && !oldIsClosed { m.ClosedDateUnix = timeutil.TimeStampNow() @@ -171,7 +173,7 @@ func UpdateMilestone(m *Milestone, oldIsClosed bool) error { } } - return sess.Commit() + return committer.Commit() } func updateMilestone(e db.Engine, m *Milestone) error { @@ -207,11 +209,13 @@ func updateMilestoneCounters(e db.Engine, id int64) error { // ChangeMilestoneStatusByRepoIDAndID changes a milestone open/closed status if the milestone ID is in the repo. func ChangeMilestoneStatusByRepoIDAndID(repoID, milestoneID int64, isClosed bool) error { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() + + sess := db.GetEngine(ctx) m := &Milestone{ ID: milestoneID, @@ -229,22 +233,22 @@ func ChangeMilestoneStatusByRepoIDAndID(repoID, milestoneID int64, isClosed bool return err } - return sess.Commit() + return committer.Commit() } // ChangeMilestoneStatus changes the milestone open/closed status. func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err = sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() - if err := changeMilestoneStatus(sess, m, isClosed); err != nil { + if err := changeMilestoneStatus(db.GetEngine(ctx), m, isClosed); err != nil { return err } - return sess.Commit() + return committer.Commit() } func changeMilestoneStatus(e db.Engine, m *Milestone, isClosed bool) error { @@ -335,11 +339,13 @@ func DeleteMilestoneByRepoID(repoID, id int64) error { return err } - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err = sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() + + sess := db.GetEngine(ctx) if _, err = sess.ID(m.ID).Delete(new(Milestone)); err != nil { return err @@ -360,10 +366,10 @@ func DeleteMilestoneByRepoID(repoID, id int64) error { return err } - if _, err = sess.Exec("UPDATE `issue` SET milestone_id = 0 WHERE milestone_id = ?", m.ID); err != nil { + if _, err = db.Exec(ctx, "UPDATE `issue` SET milestone_id = 0 WHERE milestone_id = ?", m.ID); err != nil { return err } - return sess.Commit() + return committer.Commit() } // MilestoneList is a list of milestones offering additional functionality |