diff options
Diffstat (limited to 'models/project_board.go')
-rw-r--r-- | models/project_board.go | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/models/project_board.go b/models/project_board.go index 4b313ed8f0..901850e511 100644 --- a/models/project_board.go +++ b/models/project_board.go @@ -5,6 +5,7 @@ package models import ( + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" @@ -47,6 +48,10 @@ type ProjectBoard struct { Issues []*Issue `xorm:"-"` } +func init() { + db.RegisterModel(new(ProjectBoard)) +} + // IsProjectBoardTypeValid checks if the project board type is valid func IsProjectBoardTypeValid(p ProjectBoardType) bool { switch p { @@ -95,13 +100,13 @@ func createBoardsForProjectsType(sess *xorm.Session, project *Project) error { // NewProjectBoard adds a new project board to a given project func NewProjectBoard(board *ProjectBoard) error { - _, err := x.Insert(board) + _, err := db.DefaultContext().Engine().Insert(board) return err } // DeleteProjectBoardByID removes all issues references to the project board. func DeleteProjectBoardByID(boardID int64) error { - sess := x.NewSession() + sess := db.DefaultContext().NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err @@ -114,7 +119,7 @@ func DeleteProjectBoardByID(boardID int64) error { return sess.Commit() } -func deleteProjectBoardByID(e Engine, boardID int64) error { +func deleteProjectBoardByID(e db.Engine, boardID int64) error { board, err := getProjectBoard(e, boardID) if err != nil { if IsErrProjectBoardNotExist(err) { @@ -134,17 +139,17 @@ func deleteProjectBoardByID(e Engine, boardID int64) error { return nil } -func deleteProjectBoardByProjectID(e Engine, projectID int64) error { +func deleteProjectBoardByProjectID(e db.Engine, projectID int64) error { _, err := e.Where("project_id=?", projectID).Delete(&ProjectBoard{}) return err } // GetProjectBoard fetches the current board of a project func GetProjectBoard(boardID int64) (*ProjectBoard, error) { - return getProjectBoard(x, boardID) + return getProjectBoard(db.DefaultContext().Engine(), boardID) } -func getProjectBoard(e Engine, boardID int64) (*ProjectBoard, error) { +func getProjectBoard(e db.Engine, boardID int64) (*ProjectBoard, error) { board := new(ProjectBoard) has, err := e.ID(boardID).Get(board) @@ -159,10 +164,10 @@ func getProjectBoard(e Engine, boardID int64) (*ProjectBoard, error) { // UpdateProjectBoard updates a project board func UpdateProjectBoard(board *ProjectBoard) error { - return updateProjectBoard(x, board) + return updateProjectBoard(db.DefaultContext().Engine(), board) } -func updateProjectBoard(e Engine, board *ProjectBoard) error { +func updateProjectBoard(e db.Engine, board *ProjectBoard) error { var fieldToUpdate []string if board.Sorting != 0 { @@ -181,10 +186,10 @@ func updateProjectBoard(e Engine, board *ProjectBoard) error { // GetProjectBoards fetches all boards related to a project // if no default board set, first board is a temporary "Uncategorized" board func GetProjectBoards(projectID int64) (ProjectBoardList, error) { - return getProjectBoards(x, projectID) + return getProjectBoards(db.DefaultContext().Engine(), projectID) } -func getProjectBoards(e Engine, projectID int64) ([]*ProjectBoard, error) { +func getProjectBoards(e db.Engine, projectID int64) ([]*ProjectBoard, error) { boards := make([]*ProjectBoard, 0, 5) if err := e.Where("project_id=? AND `default`=?", projectID, false).OrderBy("Sorting").Find(&boards); err != nil { @@ -200,7 +205,7 @@ func getProjectBoards(e Engine, projectID int64) ([]*ProjectBoard, error) { } // getDefaultBoard return default board and create a dummy if none exist -func getDefaultBoard(e Engine, projectID int64) (*ProjectBoard, error) { +func getDefaultBoard(e db.Engine, projectID int64) (*ProjectBoard, error) { var board ProjectBoard exist, err := e.Where("project_id=? AND `default`=?", projectID, true).Get(&board) if err != nil { @@ -221,9 +226,7 @@ func getDefaultBoard(e Engine, projectID int64) (*ProjectBoard, error) { // SetDefaultBoard represents a board for issues not assigned to one // if boardID is 0 unset default func SetDefaultBoard(projectID, boardID int64) error { - sess := x - - _, err := sess.Where(builder.Eq{ + _, err := db.DefaultContext().Engine().Where(builder.Eq{ "project_id": projectID, "`default`": true, }).Cols("`default`").Update(&ProjectBoard{Default: false}) @@ -232,7 +235,7 @@ func SetDefaultBoard(projectID, boardID int64) error { } if boardID > 0 { - _, err = sess.ID(boardID).Where(builder.Eq{"project_id": projectID}). + _, err = db.DefaultContext().Engine().ID(boardID).Where(builder.Eq{"project_id": projectID}). Cols("`default`").Update(&ProjectBoard{Default: true}) } @@ -290,7 +293,7 @@ func (bs ProjectBoardList) LoadIssues() (IssueList, error) { // UpdateProjectBoardSorting update project board sorting func UpdateProjectBoardSorting(bs ProjectBoardList) error { for i := range bs { - _, err := x.ID(bs[i].ID).Cols( + _, err := db.DefaultContext().Engine().ID(bs[i].ID).Cols( "sorting", ).Update(bs[i]) if err != nil { |