mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 12:22:11 +00:00
[BUG] Ensure HasIssueContentHistory
takes into account comment_id
- The content history table contains the content history of issues and comments. For issues they are saved with an comment id of zero. - If you want to check if the issue has an content history, it should take into account that SQL has `comment_id = 0`, as it otherwise could return incorrect results when for example the issue already has an comment that has an content history. - Fix the code of `HasIssueContentHistory` to take this into account, it relied on XORM to generate the SQL from the non-default values of the struct, this wouldn't generate the `comment_id = 0` SQL as `0` is the default value of an integer. - Remove an unncessary log (it's not the responsibility of `models` code to do logging). - Adds unit test. - Resolves #2513
This commit is contained in:
parent
d0e5af7079
commit
331fa44956
2 changed files with 14 additions and 9 deletions
|
@ -172,15 +172,7 @@ func FetchIssueContentHistoryList(dbCtx context.Context, issueID, commentID int6
|
|||
|
||||
// HasIssueContentHistory check if a ContentHistory entry exists
|
||||
func HasIssueContentHistory(dbCtx context.Context, issueID, commentID int64) (bool, error) {
|
||||
exists, err := db.GetEngine(dbCtx).Cols("id").Exist(&ContentHistory{
|
||||
IssueID: issueID,
|
||||
CommentID: commentID,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("can not fetch issue content history. err=%v", err)
|
||||
return false, err
|
||||
}
|
||||
return exists, err
|
||||
return db.GetEngine(dbCtx).Where("issue_id = ? AND comment_id = ?", issueID, commentID).Exist(new(ContentHistory))
|
||||
}
|
||||
|
||||
// SoftDeleteIssueContentHistory soft delete
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue