[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:
fluzz 2023-10-31 17:01:03 +00:00 committed by Earl Warren
parent 25e96cfcb2
commit ac4f727f63
3 changed files with 115 additions and 8 deletions

View file

@ -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
}