1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00

Update issue-user when change milestone

This commit is contained in:
Unknown 2014-05-15 12:08:53 -04:00
parent f4486f3eec
commit db6b71ad03
2 changed files with 43 additions and 4 deletions

View File

@ -161,6 +161,13 @@ func GetIssueCountByPoster(uid, rid int64, isClosed bool) int64 {
return count
}
// .___ ____ ___
// | | ______ ________ __ ____ | | \______ ___________
// | |/ ___// ___/ | \_/ __ \| | / ___// __ \_ __ \
// | |\___ \ \___ \| | /\ ___/| | /\___ \\ ___/| | \/
// |___/____ >____ >____/ \___ >______//____ >\___ >__|
// \/ \/ \/ \/ \/
// IssueUser represents an issue-user relation.
type IssueUser struct {
Id int64
@ -404,6 +411,13 @@ type Label struct {
NumOpenIssues int `xorm:"-"`
}
// _____ .__.__ __
// / \ |__| | ____ _______/ |_ ____ ____ ____
// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
// \/ \/ \/ \/ \/
// Milestone represents a milestone of repository.
type Milestone struct {
Id int64
@ -517,7 +531,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
}
// ChangeMilestoneAssign changes assignment of milestone for issue.
func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
sess := orm.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
@ -531,7 +545,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
}
m.NumIssues--
if isIssueClosed {
if issue.IsClosed {
m.NumClosedIssues--
}
if m.NumIssues > 0 {
@ -543,6 +557,12 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
sess.Rollback()
return err
}
rawSql := "UPDATE `issue_user` SET milestone_id = 0 WHERE issue_id = ?"
if _, err = sess.Exec(rawSql, issue.Id); err != nil {
sess.Rollback()
return err
}
}
if mid > 0 {
@ -551,7 +571,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
return err
}
m.NumIssues++
if isIssueClosed {
if issue.IsClosed {
m.NumClosedIssues++
}
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
@ -559,6 +579,12 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
sess.Rollback()
return err
}
rawSql := "UPDATE `issue_user` SET milestone_id = ? WHERE issue_id = ?"
if _, err = sess.Exec(rawSql, m.Id, issue.Id); err != nil {
sess.Rollback()
return err
}
}
return sess.Commit()
}
@ -587,9 +613,22 @@ func DeleteMilestone(m *Milestone) (err error) {
sess.Rollback()
return err
}
rawSql = "UPDATE `issue_user` SET milestone_id = 0 WHERE milestone_id = ?"
if _, err = sess.Exec(rawSql, m.Id); err != nil {
sess.Rollback()
return err
}
return sess.Commit()
}
// _________ __
// \_ ___ \ ____ _____ _____ ____ _____/ |_
// / \ \/ / _ \ / \ / \_/ __ \ / \ __\
// \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
// \______ /\____/|__|_| /__|_| /\___ >___| /__|
// \/ \/ \/ \/ \/
// Issue types.
const (
IT_PLAIN = iota // Pure comment.

View File

@ -426,7 +426,7 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
// Not check for invalid milestone id and give responsibility to owners.
issue.MilestoneId = mid
if err = models.ChangeMilestoneAssign(oldMid, mid, issue.IsClosed); err != nil {
if err = models.ChangeMilestoneAssign(oldMid, mid, issue); err != nil {
ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err)
return
} else if err = models.UpdateIssue(issue); err != nil {