summaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
authorJimmy Praet <jimmy.praet@telenet.be>2021-11-22 13:20:16 +0100
committerGitHub <noreply@github.com>2021-11-22 20:20:16 +0800
commita3efd048a7770aff898096df55eda76e80a4972e (patch)
treeaea86e365fed219016a2d2e106572fde6a5b7e84 /models/issue.go
parent49b2cb998b6ebaf98e89dd9dba8ba9d46d2fd82c (diff)
downloadgitea-a3efd048a7770aff898096df55eda76e80a4972e.tar.gz
gitea-a3efd048a7770aff898096df55eda76e80a4972e.zip
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
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/models/issue.go b/models/issue.go
index 6de7c3204b..7aab8b9399 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -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)
}