summaryrefslogtreecommitdiffstats
path: root/models/project_issue.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/project_issue.go')
-rw-r--r--models/project_issue.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/models/project_issue.go b/models/project_issue.go
index e35307158d..acc0a31e1e 100644
--- a/models/project_issue.go
+++ b/models/project_issue.go
@@ -7,6 +7,8 @@ package models
import (
"fmt"
+ "code.gitea.io/gitea/models/db"
+
"xorm.io/xorm"
)
@@ -20,7 +22,11 @@ type ProjectIssue struct {
ProjectBoardID int64 `xorm:"INDEX"`
}
-func deleteProjectIssuesByProjectID(e Engine, projectID int64) error {
+func init() {
+ db.RegisterModel(new(ProjectIssue))
+}
+
+func deleteProjectIssuesByProjectID(e db.Engine, projectID int64) error {
_, err := e.Where("project_id=?", projectID).Delete(&ProjectIssue{})
return err
}
@@ -33,10 +39,10 @@ func deleteProjectIssuesByProjectID(e Engine, projectID int64) error {
// LoadProject load the project the issue was assigned to
func (i *Issue) LoadProject() (err error) {
- return i.loadProject(x)
+ return i.loadProject(db.DefaultContext().Engine())
}
-func (i *Issue) loadProject(e Engine) (err error) {
+func (i *Issue) loadProject(e db.Engine) (err error) {
if i.Project == nil {
var p Project
if _, err = e.Table("project").
@@ -52,10 +58,10 @@ func (i *Issue) loadProject(e Engine) (err error) {
// ProjectID return project id if issue was assigned to one
func (i *Issue) ProjectID() int64 {
- return i.projectID(x)
+ return i.projectID(db.DefaultContext().Engine())
}
-func (i *Issue) projectID(e Engine) int64 {
+func (i *Issue) projectID(e db.Engine) int64 {
var ip ProjectIssue
has, err := e.Where("issue_id=?", i.ID).Get(&ip)
if err != nil || !has {
@@ -66,10 +72,10 @@ func (i *Issue) projectID(e Engine) int64 {
// ProjectBoardID return project board id if issue was assigned to one
func (i *Issue) ProjectBoardID() int64 {
- return i.projectBoardID(x)
+ return i.projectBoardID(db.DefaultContext().Engine())
}
-func (i *Issue) projectBoardID(e Engine) int64 {
+func (i *Issue) projectBoardID(e db.Engine) int64 {
var ip ProjectIssue
has, err := e.Where("issue_id=?", i.ID).Get(&ip)
if err != nil || !has {
@@ -87,7 +93,7 @@ func (i *Issue) projectBoardID(e Engine) int64 {
// NumIssues return counter of all issues assigned to a project
func (p *Project) NumIssues() int {
- c, err := x.Table("project_issue").
+ c, err := db.DefaultContext().Engine().Table("project_issue").
Where("project_id=?", p.ID).
GroupBy("issue_id").
Cols("issue_id").
@@ -100,7 +106,7 @@ func (p *Project) NumIssues() int {
// NumClosedIssues return counter of closed issues assigned to a project
func (p *Project) NumClosedIssues() int {
- c, err := x.Table("project_issue").
+ c, err := db.DefaultContext().Engine().Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, true).
Cols("issue_id").
@@ -113,7 +119,7 @@ func (p *Project) NumClosedIssues() int {
// NumOpenIssues return counter of open issues assigned to a project
func (p *Project) NumOpenIssues() int {
- c, err := x.Table("project_issue").
+ c, err := db.DefaultContext().Engine().Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, false).Count("issue.id")
if err != nil {
@@ -124,7 +130,7 @@ func (p *Project) NumOpenIssues() int {
// ChangeProjectAssign changes the project associated with an issue
func ChangeProjectAssign(issue *Issue, doer *User, newProjectID int64) error {
- sess := x.NewSession()
+ sess := db.DefaultContext().NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
@@ -177,7 +183,7 @@ func addUpdateIssueProject(e *xorm.Session, issue *Issue, doer *User, newProject
// MoveIssueAcrossProjectBoards move a card from one board to another
func MoveIssueAcrossProjectBoards(issue *Issue, board *ProjectBoard) error {
- sess := x.NewSession()
+ sess := db.DefaultContext().NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
@@ -201,7 +207,7 @@ func MoveIssueAcrossProjectBoards(issue *Issue, board *ProjectBoard) error {
return sess.Commit()
}
-func (pb *ProjectBoard) removeIssues(e Engine) error {
+func (pb *ProjectBoard) removeIssues(e db.Engine) error {
_, err := e.Exec("UPDATE `project_issue` SET project_board_id = 0 WHERE project_board_id = ? ", pb.ID)
return err
}