From de10d9be08034ff285480c14b86be0c1824df16b Mon Sep 17 00:00:00 2001 From: Unknwon <u@gogs.io> Date: Thu, 16 Aug 2018 20:17:19 +0800 Subject: models: fix delete undesired release attachments when delete a comment (#4627) Apparently, AfterDelete has ID=0 --- models/comment.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'models/comment.go') diff --git a/models/comment.go b/models/comment.go index 447c15db..66531bbb 100644 --- a/models/comment.go +++ b/models/comment.go @@ -132,14 +132,6 @@ func (c *Comment) LoadAttributes() error { return c.loadAttributes(x) } -func (c *Comment) AfterDelete() { - _, err := DeleteAttachmentsByComment(c.ID, true) - - if err != nil { - log.Info("Could not delete files for comment %d on issue #%d: %s", c.ID, c.IssueID, err) - } -} - func (c *Comment) HTMLURL() string { return fmt.Sprintf("%s#issuecomment-%d", c.Issue.HTMLURL(), c.ID) } @@ -519,7 +511,12 @@ func DeleteCommentByID(doer *User, id int64) error { } if err = sess.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("commit: %v", err) + } + + _, err = DeleteAttachmentsByComment(comment.ID, true) + if err != nil { + log.Error(2, "Failed to delete attachments by comment[%d]: %v", comment.ID, err) } if err = comment.Issue.LoadAttributes(); err != nil { -- cgit v1.2.3