Переглянути джерело

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

Apparently, AfterDelete has ID=0
Unknwon 6 роки тому
батько
коміт
de10d9be08
4 змінених файлів з 8 додано та 13 видалено
  1. 1 1
      gogs.go
  2. 0 2
      models/attachment.go
  3. 6 9
      models/comment.go
  4. 1 1
      templates/.VERSION

+ 1 - 1
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

+ 0 - 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
 	}

+ 6 - 9
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 {

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.11.60.0814
+0.11.61.0816