mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 02:08:36 +00:00
Improvements to content history (#17746)
* Improvements to content history * initialize content history when making an edit to an old item created before the introduction of content history * show edit history for code comments on pull request files tab * Fix a flaw in keepLimitedContentHistory Fix a flaw in keepLimitedContentHistory, the first and the last should never be deleted * Remove obsolete eager initialization of content history
This commit is contained in:
@@ -824,14 +824,25 @@ func (issue *Issue) UpdateAttachments(uuids []string) (err error) {
|
||||
|
||||
// ChangeContent changes issue content, as the given user.
|
||||
func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
||||
issue.Content = content
|
||||
|
||||
ctx, committer, err := db.TxContext()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
|
||||
hasContentHistory, err := issues.HasIssueContentHistory(ctx, issue.ID, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("HasIssueContentHistory: %v", err)
|
||||
}
|
||||
if !hasContentHistory {
|
||||
if err = issues.SaveIssueContentHistory(db.GetEngine(ctx), issue.PosterID, issue.ID, 0,
|
||||
issue.CreatedUnix, issue.Content, true); err != nil {
|
||||
return fmt.Errorf("SaveIssueContentHistory: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
issue.Content = content
|
||||
|
||||
if err = updateIssueCols(db.GetEngine(ctx), issue, "content"); err != nil {
|
||||
return fmt.Errorf("UpdateIssueCols: %v", err)
|
||||
}
|
||||
@@ -1012,11 +1023,6 @@ func newIssue(ctx context.Context, doer *User, opts NewIssueOptions) (err error)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = issues.SaveIssueContentHistory(e, doer.ID, opts.Issue.ID, 0,
|
||||
timeutil.TimeStampNow(), opts.Issue.Content, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return opts.Issue.addCrossReferences(ctx, doer, false)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user