forked from forgejo/forgejo
[FEAT] allow setting the update date on issues and comments (squash) apply the 'update_at' value to the cross-ref comments (#1676)
[this is a follow-up to PR #764] When a comment of issue A referencing issue B is added with a forced 'updated_at' date, that date has to be applied to the comment created in issue B. ----- Comment: While trying my 'RoundUp migration script', I found that this case was forgotten in PR #764 - my apologies... I'll try to write a functional test, base on models/issues/issue_xref_test.go Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1676 Co-authored-by: fluzz <fluzz@freedroid.org> Co-committed-by: fluzz <fluzz@freedroid.org>
This commit is contained in:
parent
25e96cfcb2
commit
ac4f727f63
3 changed files with 115 additions and 8 deletions
|
@ -818,6 +818,9 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
|
|||
Invalidated: opts.Invalidated,
|
||||
}
|
||||
if opts.Issue.NoAutoTime {
|
||||
// Preload the comment with the Issue containing the forced update
|
||||
// date. This is needed to propagate those data in AddCrossReferences()
|
||||
comment.Issue = opts.Issue
|
||||
comment.CreatedUnix = opts.Issue.UpdatedUnix
|
||||
comment.UpdatedUnix = opts.Issue.UpdatedUnix
|
||||
e.NoAutoTime()
|
||||
|
@ -1101,21 +1104,22 @@ func UpdateComment(ctx context.Context, c *Comment, doer *user_model.User) error
|
|||
}
|
||||
defer committer.Close()
|
||||
|
||||
if err := c.LoadIssue(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sess := db.GetEngine(ctx).ID(c.ID).AllCols()
|
||||
if c.Issue.NoAutoTime {
|
||||
// update the DataBase
|
||||
sess = sess.NoAutoTime().SetExpr("updated_unix", c.Issue.UpdatedUnix)
|
||||
// the UpdatedUnix value of the Comment also has to be set,
|
||||
// to return the adequate valuè
|
||||
// to return the adequate value
|
||||
// see https://codeberg.org/forgejo/forgejo/pulls/764#issuecomment-1023801
|
||||
c.UpdatedUnix = c.Issue.UpdatedUnix
|
||||
}
|
||||
if _, err := sess.Update(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.LoadIssue(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.AddCrossReferences(ctx, doer, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -46,11 +46,15 @@ func neuterCrossReferences(ctx context.Context, issueID, commentID int64) error
|
|||
for i, c := range active {
|
||||
ids[i] = c.ID
|
||||
}
|
||||
return neuterCrossReferencesIds(ctx, ids)
|
||||
return neuterCrossReferencesIds(ctx, nil, ids)
|
||||
}
|
||||
|
||||
func neuterCrossReferencesIds(ctx context.Context, ids []int64) error {
|
||||
_, err := db.GetEngine(ctx).In("id", ids).Cols("`ref_action`").Update(&Comment{RefAction: references.XRefActionNeutered})
|
||||
func neuterCrossReferencesIds(stdCtx context.Context, ctx *crossReferencesContext, ids []int64) error {
|
||||
sess := db.GetEngine(stdCtx).In("id", ids).Cols("`ref_action`")
|
||||
if ctx != nil && ctx.OrigIssue.NoAutoTime {
|
||||
sess.SetExpr("updated_unix", ctx.OrigIssue.UpdatedUnix).NoAutoTime()
|
||||
}
|
||||
_, err := sess.Update(&Comment{RefAction: references.XRefActionNeutered})
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -100,7 +104,7 @@ func (issue *Issue) createCrossReferences(stdCtx context.Context, ctx *crossRefe
|
|||
}
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
if err = neuterCrossReferencesIds(stdCtx, ids); err != nil {
|
||||
if err = neuterCrossReferencesIds(stdCtx, ctx, ids); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue