diff --git a/models/issues/comment.go b/models/issues/comment.go index da91a83384ec2..6a4d2088589bc 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -871,6 +871,9 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment } fallthrough case CommentTypeComment: + if err = updateAttachments(ctx, opts, comment); err != nil { + return err + } if _, err = db.Exec(ctx, "UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", opts.Issue.ID); err != nil { return err } @@ -896,8 +899,7 @@ func updateAttachments(ctx context.Context, opts *CreateCommentOptions, comment for i := range attachments { attachments[i].IssueID = opts.Issue.ID attachments[i].CommentID = comment.ID - // No assign value could be 0, so ignore AllCols(). - if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil { + if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Cols("issue_id", "comment_id").Update(attachments[i]); err != nil { return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err) } } diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go index b258dc882cb2c..43d26fcb741fa 100644 --- a/models/issues/issue_update.go +++ b/models/issues/issue_update.go @@ -282,7 +282,6 @@ type NewIssueOptions struct { // NewIssueWithIndex creates issue with given index func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssueOptions) (err error) { - e := db.GetEngine(ctx) opts.Issue.Title = strings.TrimSpace(opts.Issue.Title) if opts.Issue.MilestoneID > 0 { @@ -306,7 +305,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue return fmt.Errorf("issue exist") } - if _, err := e.Insert(opts.Issue); err != nil { + if err := db.Insert(ctx, opts.Issue); err != nil { return err } @@ -336,7 +335,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue // During the session, SQLite3 driver cannot handle retrieve objects after update something. // So we have to get all needed labels first. labels := make([]*Label, 0, len(opts.LabelIDs)) - if err = e.In("id", opts.LabelIDs).Find(&labels); err != nil { + if err = db.GetEngine(ctx).In("id", opts.LabelIDs).Find(&labels); err != nil { return fmt.Errorf("find all labels [label_ids: %v]: %w", opts.LabelIDs, err) } @@ -368,8 +367,8 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue for i := 0; i < len(attachments); i++ { attachments[i].IssueID = opts.Issue.ID - if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil { - return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) + if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Cols("issue_id").Update(attachments[i]); err != nil { + return fmt.Errorf("update attachment issue_id [id: %d]: %w", attachments[i].ID, err) } } } diff --git a/services/repository/repository.go b/services/repository/repository.go index d28200c0adc5d..a4c8d23487e4f 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -124,7 +124,7 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili // LinkedRepository returns the linked repo if any func LinkedRepository(ctx context.Context, a *repo_model.Attachment) (*repo_model.Repository, unit.Type, error) { - if a.IssueID != 0 { + if a.IssueID != 0 { // attachment for issues or comments iss, err := issues_model.GetIssueByID(ctx, a.IssueID) if err != nil { return nil, unit.TypeIssues, err @@ -135,13 +135,16 @@ func LinkedRepository(ctx context.Context, a *repo_model.Attachment) (*repo_mode unitType = unit.TypePullRequests } return repo, unitType, err - } else if a.ReleaseID != 0 { + } else if a.ReleaseID != 0 { // attachment for releases rel, err := repo_model.GetReleaseByID(ctx, a.ReleaseID) if err != nil { return nil, unit.TypeReleases, err } repo, err := repo_model.GetRepositoryByID(ctx, rel.RepoID) return repo, unit.TypeReleases, err + } else if a.RepoID > 0 { // attachment for repository upload + repo, err := repo_model.GetRepositoryByID(ctx, a.RepoID) + return repo, unit.TypeCode, err } return nil, -1, nil }