summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2017-02-04 14:55:02 -0200
committerGitHub <noreply@github.com>2017-02-04 14:55:02 -0200
commit7c3dc51655c0bbafb2b84d1d6a1042b10142dcd4 (patch)
tree9e2f58017e6a3ca7dd6ee50ddd3eb5ea06c54989
parent5fd19a45b79dc3fc4fd0f3390e5c25c0848a9feb (diff)
parentf82ea42679eaa220ab39d1e4d70e2ed4cbaf0fa7 (diff)
downloadgitea-7c3dc51655c0bbafb2b84d1d6a1042b10142dcd4.tar.gz
gitea-7c3dc51655c0bbafb2b84d1d6a1042b10142dcd4.zip
Merge pull request #839 from ethantkoenig/fix/remove_org_repo
Fix bug in removeOrgRepo
-rw-r--r--models/models.go2
-rw-r--r--models/org.go22
2 files changed, 22 insertions, 2 deletions
diff --git a/models/models.go b/models/models.go
index 624badda17..ec93d4c12b 100644
--- a/models/models.go
+++ b/models/models.go
@@ -30,12 +30,14 @@ import (
// Engine represents a xorm engine or session.
type Engine interface {
+ Decr(column string, arg ...interface{}) *xorm.Session
Delete(interface{}) (int64, error)
Exec(string, ...interface{}) (sql.Result, error)
Find(interface{}, ...interface{}) error
Get(interface{}) (bool, error)
Id(interface{}) *xorm.Session
In(string, ...interface{}) *xorm.Session
+ Incr(column string, arg ...interface{}) *xorm.Session
Insert(...interface{}) (int64, error)
InsertOne(interface{}) (int64, error)
Iterate(interface{}, xorm.IterFunc) error
diff --git a/models/org.go b/models/org.go
index 40f34a4f09..f68c2b9fcb 100644
--- a/models/org.go
+++ b/models/org.go
@@ -526,10 +526,28 @@ func RemoveOrgUser(orgID, userID int64) error {
}
func removeOrgRepo(e Engine, orgID, repoID int64) error {
- _, err := e.Delete(&TeamRepo{
+ teamRepos := make([]*TeamRepo, 0, 10)
+ if err := e.Find(&teamRepos, &TeamRepo{OrgID: orgID, RepoID: repoID}); err != nil {
+ return err
+ }
+
+ if len(teamRepos) == 0 {
+ return nil
+ }
+
+ if _, err := e.Delete(&TeamRepo{
OrgID: orgID,
RepoID: repoID,
- })
+ }); err != nil {
+ return err
+ }
+
+ teamIDs := make([]int64, len(teamRepos))
+ for i, teamRepo := range teamRepos {
+ teamIDs[i] = teamRepo.ID
+ }
+
+ _, err := x.Decr("num_repos").In("id", teamIDs).Update(new(Team))
return err
}