aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-13 19:46:48 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-13 19:46:48 -0400
commit5ed5aa5228feba935679df8cb676af62018cc25d (patch)
tree91eab6292ed10c2e0bfe606ae972d9a03c1cb3e3 /models
parent33ec0632ffd9e770793eba57393f27385d5f392d (diff)
downloadgitea-5ed5aa5228feba935679df8cb676af62018cc25d.tar.gz
gitea-5ed5aa5228feba935679df8cb676af62018cc25d.zip
Finish milestone
Diffstat (limited to 'models')
-rw-r--r--models/issue.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go
index dad89f56c4..e708e54311 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -471,6 +471,64 @@ func UpdateMilestone(m *Milestone) error {
return err
}
+// ChangeMilestoneStatus changes the milestone open/closed status.
+func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
+ repo, err := GetRepositoryById(m.RepoId)
+ if err != nil {
+ return err
+ }
+
+ sess := orm.NewSession()
+ defer sess.Close()
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ m.IsClosed = isClosed
+ if _, err = sess.Id(m.Id).AllCols().Update(m); err != nil {
+ sess.Rollback()
+ return err
+ }
+
+ if isClosed {
+ repo.NumClosedMilestones++
+ } else {
+ repo.NumClosedMilestones--
+ }
+ if _, err = sess.Id(repo.Id).Update(repo); err != nil {
+ sess.Rollback()
+ return err
+ }
+ return sess.Commit()
+}
+
+// DeleteMilestone deletes a milestone.
+func DeleteMilestone(m *Milestone) (err error) {
+ sess := orm.NewSession()
+ defer sess.Close()
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ if _, err = sess.Delete(m); err != nil {
+ sess.Rollback()
+ return err
+ }
+
+ rawSql := "UPDATE `repository` SET num_milestones = num_milestones - 1 WHERE id = ?"
+ if _, err = sess.Exec(rawSql, m.RepoId); err != nil {
+ sess.Rollback()
+ return err
+ }
+
+ rawSql = "UPDATE `issue` SET milestone_id = 0 WHERE milestone_id = ?"
+ if _, err = sess.Exec(rawSql, m.Id); err != nil {
+ sess.Rollback()
+ return err
+ }
+ return sess.Commit()
+}
+
// Issue types.
const (
IT_PLAIN = iota // Pure comment.