diff options
Diffstat (limited to 'models/issue_project.go')
-rw-r--r-- | models/issue_project.go | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/models/issue_project.go b/models/issue_project.go index 0e993b39c5..0f8c61977b 100644 --- a/models/issue_project.go +++ b/models/issue_project.go @@ -15,13 +15,13 @@ import ( // LoadProject load the project the issue was assigned to func (i *Issue) LoadProject() (err error) { - return i.loadProject(db.GetEngine(db.DefaultContext)) + return i.loadProject(db.DefaultContext) } -func (i *Issue) loadProject(e db.Engine) (err error) { +func (i *Issue) loadProject(ctx context.Context) (err error) { if i.Project == nil { var p project_model.Project - if _, err = e.Table("project"). + if _, err = db.GetEngine(ctx).Table("project"). Join("INNER", "project_issue", "project.id=project_issue.project_id"). Where("project_issue.issue_id = ?", i.ID). Get(&p); err != nil { @@ -34,12 +34,12 @@ func (i *Issue) loadProject(e db.Engine) (err error) { // ProjectID return project id if issue was assigned to one func (i *Issue) ProjectID() int64 { - return i.projectID(db.GetEngine(db.DefaultContext)) + return i.projectID(db.DefaultContext) } -func (i *Issue) projectID(e db.Engine) int64 { +func (i *Issue) projectID(ctx context.Context) int64 { var ip project_model.ProjectIssue - has, err := e.Where("issue_id=?", i.ID).Get(&ip) + has, err := db.GetEngine(ctx).Where("issue_id=?", i.ID).Get(&ip) if err != nil || !has { return 0 } @@ -48,12 +48,12 @@ func (i *Issue) projectID(e db.Engine) int64 { // ProjectBoardID return project board id if issue was assigned to one func (i *Issue) ProjectBoardID() int64 { - return i.projectBoardID(db.GetEngine(db.DefaultContext)) + return i.projectBoardID(db.DefaultContext) } -func (i *Issue) projectBoardID(e db.Engine) int64 { +func (i *Issue) projectBoardID(ctx context.Context) int64 { var ip project_model.ProjectIssue - has, err := e.Where("issue_id=?", i.ID).Get(&ip) + has, err := db.GetEngine(ctx).Where("issue_id=?", i.ID).Get(&ip) if err != nil || !has { return 0 } @@ -122,10 +122,9 @@ func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64 } func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error { - e := db.GetEngine(ctx) - oldProjectID := issue.projectID(e) + oldProjectID := issue.projectID(ctx) - if _, err := e.Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil { + if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil { return err } @@ -146,11 +145,10 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U } } - _, err := e.Insert(&project_model.ProjectIssue{ + return db.Insert(ctx, &project_model.ProjectIssue{ IssueID: issue.ID, ProjectID: newProjectID, }) - return err } // MoveIssueAcrossProjectBoards move a card from one board to another |