diff options
Diffstat (limited to 'models/project.go')
-rw-r--r-- | models/project.go | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/models/project.go b/models/project.go index 7c976711be..1e520b877e 100644 --- a/models/project.go +++ b/models/project.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" @@ -55,6 +56,10 @@ type Project struct { ClosedDateUnix timeutil.TimeStamp } +func init() { + db.RegisterModel(new(Project)) +} + // GetProjectsConfig retrieves the types of configurations projects could have func GetProjectsConfig() []ProjectsConfig { return []ProjectsConfig{ @@ -85,10 +90,10 @@ type ProjectSearchOptions struct { // GetProjects returns a list of all projects that have been created in the repository func GetProjects(opts ProjectSearchOptions) ([]*Project, int64, error) { - return getProjects(x, opts) + return getProjects(db.DefaultContext().Engine(), opts) } -func getProjects(e Engine, opts ProjectSearchOptions) ([]*Project, int64, error) { +func getProjects(e db.Engine, opts ProjectSearchOptions) ([]*Project, int64, error) { projects := make([]*Project, 0, setting.UI.IssuePagingNum) var cond builder.Cond = builder.Eq{"repo_id": opts.RepoID} @@ -138,7 +143,7 @@ func NewProject(p *Project) error { return errors.New("project type is not valid") } - sess := x.NewSession() + sess := db.DefaultContext().NewSession() defer sess.Close() if err := sess.Begin(); err != nil { @@ -162,10 +167,10 @@ func NewProject(p *Project) error { // GetProjectByID returns the projects in a repository func GetProjectByID(id int64) (*Project, error) { - return getProjectByID(x, id) + return getProjectByID(db.DefaultContext().Engine(), id) } -func getProjectByID(e Engine, id int64) (*Project, error) { +func getProjectByID(e db.Engine, id int64) (*Project, error) { p := new(Project) has, err := e.ID(id).Get(p) @@ -180,10 +185,10 @@ func getProjectByID(e Engine, id int64) (*Project, error) { // UpdateProject updates project properties func UpdateProject(p *Project) error { - return updateProject(x, p) + return updateProject(db.DefaultContext().Engine(), p) } -func updateProject(e Engine, p *Project) error { +func updateProject(e db.Engine, p *Project) error { _, err := e.ID(p.ID).Cols( "title", "description", @@ -191,7 +196,7 @@ func updateProject(e Engine, p *Project) error { return err } -func updateRepositoryProjectCount(e Engine, repoID int64) error { +func updateRepositoryProjectCount(e db.Engine, repoID int64) error { if _, err := e.Exec(builder.Update( builder.Eq{ "`num_projects`": builder.Select("count(*)").From("`project`"). @@ -215,7 +220,7 @@ func updateRepositoryProjectCount(e Engine, repoID int64) error { // ChangeProjectStatusByRepoIDAndID toggles a project between opened and closed func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) error { - sess := x.NewSession() + sess := db.DefaultContext().NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err @@ -239,7 +244,7 @@ func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) er // ChangeProjectStatus toggle a project between opened and closed func ChangeProjectStatus(p *Project, isClosed bool) error { - sess := x.NewSession() + sess := db.DefaultContext().NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err @@ -252,7 +257,7 @@ func ChangeProjectStatus(p *Project, isClosed bool) error { return sess.Commit() } -func changeProjectStatus(e Engine, p *Project, isClosed bool) error { +func changeProjectStatus(e db.Engine, p *Project, isClosed bool) error { p.IsClosed = isClosed p.ClosedDateUnix = timeutil.TimeStampNow() count, err := e.ID(p.ID).Where("repo_id = ? AND is_closed = ?", p.RepoID, !isClosed).Cols("is_closed", "closed_date_unix").Update(p) @@ -268,7 +273,7 @@ func changeProjectStatus(e Engine, p *Project, isClosed bool) error { // DeleteProjectByID deletes a project from a repository. func DeleteProjectByID(id int64) error { - sess := x.NewSession() + sess := db.DefaultContext().NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err @@ -281,7 +286,7 @@ func DeleteProjectByID(id int64) error { return sess.Commit() } -func deleteProjectByID(e Engine, id int64) error { +func deleteProjectByID(e db.Engine, id int64) error { p, err := getProjectByID(e, id) if err != nil { if IsErrProjectNotExist(err) { |