aboutsummaryrefslogtreecommitdiff
path: root/models/issue_comment.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r--models/issue_comment.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go
index faa25778..e9857b42 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -345,3 +345,29 @@ func UpdateComment(c *Comment) error {
_, err := x.Id(c.ID).AllCols().Update(c)
return err
}
+
+// DeleteCommentByID deletes a comment by given ID.
+func DeleteCommentByID(id int64) error {
+ comment, err := GetCommentByID(id)
+ if err != nil {
+ return err
+ }
+
+ sess := x.NewSession()
+ defer sessionRelease(sess)
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ if _, err = sess.Id(comment.ID).Delete(new(Comment)); err != nil {
+ return err
+ }
+
+ if comment.Type == COMMENT_TYPE_COMMENT {
+ if _, err = sess.Exec("UPDATE `issue` SET num_comments = num_comments - 1 WHERE id = ?", comment.IssueID); err != nil {
+ return err
+ }
+ }
+
+ return sess.Commit()
+}