[BugFix] Fix comment broken issue ref dependence (#12651)
* deleteIssuesByRepoID: delete related CommentTypeRemoveDependency & CommentTypeAddDependency comments too * Ignore ErrIssueNotExist on comment.LoadDepIssueDetails() * Add migration * Ignore 'dependent_issue_id = 0' case * exchange as per @lunny Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
		
							parent
							
								
									42a5e39b3b
								
							
						
					
					
						commit
						6c5266c9ca
					
				| @ -1978,6 +1978,11 @@ func deleteIssuesByRepoID(sess Engine, repoID int64) (attachmentPaths []string, | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if _, err = sess.In("dependent_issue_id", deleteCond). | ||||||
|  | 		Delete(&Comment{}); err != nil { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	var attachments []*Attachment | 	var attachments []*Attachment | ||||||
| 	if err = sess.In("issue_id", deleteCond). | 	if err = sess.In("issue_id", deleteCond). | ||||||
| 		Find(&attachments); err != nil { | 		Find(&attachments); err != nil { | ||||||
|  | |||||||
| @ -228,6 +228,8 @@ var migrations = []Migration{ | |||||||
| 	NewMigration("Add projects info to repository table", addProjectsInfo), | 	NewMigration("Add projects info to repository table", addProjectsInfo), | ||||||
| 	// v147 -> v148
 | 	// v147 -> v148
 | ||||||
| 	NewMigration("create review for 0 review id code comments", createReviewsForCodeComments), | 	NewMigration("create review for 0 review id code comments", createReviewsForCodeComments), | ||||||
|  | 	// v148 -> v149
 | ||||||
|  | 	NewMigration("remove issue dependency comments who refer to non existing issues", purgeInvalidDependenciesComments), | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // GetCurrentDBVersion returns the current db version
 | // GetCurrentDBVersion returns the current db version
 | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								models/migrations/v148.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								models/migrations/v148.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | // Copyright 2020 The Gitea Authors. All rights reserved.
 | ||||||
|  | // Use of this source code is governed by a MIT-style
 | ||||||
|  | // license that can be found in the LICENSE file.
 | ||||||
|  | 
 | ||||||
|  | package migrations | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"xorm.io/xorm" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func purgeInvalidDependenciesComments(x *xorm.Engine) error { | ||||||
|  | 	_, err := x.Exec("DELETE FROM comment WHERE dependent_issue_id != 0 AND dependent_issue_id NOT IN (SELECT id FROM issue)") | ||||||
|  | 	return err | ||||||
|  | } | ||||||
| @ -1079,9 +1079,11 @@ func ViewIssue(ctx *context.Context) { | |||||||
| 			} | 			} | ||||||
| 		} else if comment.Type == models.CommentTypeRemoveDependency || comment.Type == models.CommentTypeAddDependency { | 		} else if comment.Type == models.CommentTypeRemoveDependency || comment.Type == models.CommentTypeAddDependency { | ||||||
| 			if err = comment.LoadDepIssueDetails(); err != nil { | 			if err = comment.LoadDepIssueDetails(); err != nil { | ||||||
|  | 				if !models.IsErrIssueNotExist(err) { | ||||||
| 					ctx.ServerError("LoadDepIssueDetails", err) | 					ctx.ServerError("LoadDepIssueDetails", err) | ||||||
| 					return | 					return | ||||||
| 				} | 				} | ||||||
|  | 			} | ||||||
| 		} else if comment.Type == models.CommentTypeCode || comment.Type == models.CommentTypeReview { | 		} else if comment.Type == models.CommentTypeCode || comment.Type == models.CommentTypeReview { | ||||||
| 			comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink, | 			comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink, | ||||||
| 				ctx.Repo.Repository.ComposeMetas())) | 				ctx.Repo.Repository.ComposeMetas())) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user