Browse Source

models: fix delete undesired release attachments when delete a comment (#4627)

Apparently, AfterDelete has ID=0
pull/5388/head
Unknwon 6 years ago
parent
commit
de10d9be08
No known key found for this signature in database
GPG Key ID: 7A02C406FAC875A2
  1. 2
      gogs.go
  2. 2
      models/attachment.go
  3. 15
      models/comment.go
  4. 2
      templates/.VERSION

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogs/gogs/pkg/setting"
)
const APP_VER = "0.11.60.0814"
const APP_VER = "0.11.61.0816"
func init() {
setting.AppVer = APP_VER

2
models/attachment.go

@ -165,7 +165,6 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
func DeleteAttachmentsByIssue(issueId int64, remove bool) (int, error) {
attachments, err := GetAttachmentsByIssueID(issueId)
if err != nil {
return 0, err
}
@ -176,7 +175,6 @@ func DeleteAttachmentsByIssue(issueId int64, remove bool) (int, error) {
// DeleteAttachmentsByComment deletes all attachments associated with the given comment.
func DeleteAttachmentsByComment(commentId int64, remove bool) (int, error) {
attachments, err := GetAttachmentsByCommentID(commentId)
if err != nil {
return 0, err
}

15
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 {

2
templates/.VERSION

@ -1 +1 @@
0.11.60.0814
0.11.61.0816

Loading…
Cancel
Save