mirror of
https://github.com/go-gitea/gitea
synced 2024-11-02 01:34:21 +01:00
Move deletebeans into models/db (#18781)
This commit is contained in:
parent
bd71245c53
commit
397d2ac303
@ -148,6 +148,17 @@ func DeleteByBean(ctx context.Context, bean interface{}) (int64, error) {
|
||||
return GetEngine(ctx).Delete(bean)
|
||||
}
|
||||
|
||||
// DeleteBeans deletes all given beans, beans should contain delete conditions.
|
||||
func DeleteBeans(ctx context.Context, beans ...interface{}) (err error) {
|
||||
e := GetEngine(ctx)
|
||||
for i := range beans {
|
||||
if _, err = e.Delete(beans[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountByBean counts the number of database records according non-empty fields of the bean as conditions.
|
||||
func CountByBean(ctx context.Context, bean interface{}) (int64, error) {
|
||||
return GetEngine(ctx).Count(bean)
|
||||
|
@ -331,9 +331,7 @@ func DeleteOrganization(ctx context.Context, org *Organization) error {
|
||||
return fmt.Errorf("%s is a user not an organization", org.Name)
|
||||
}
|
||||
|
||||
e := db.GetEngine(ctx)
|
||||
|
||||
if err := deleteBeans(e,
|
||||
if err := db.DeleteBeans(ctx,
|
||||
&Team{OrgID: org.ID},
|
||||
&OrgUser{OrgID: org.ID},
|
||||
&TeamUser{OrgID: org.ID},
|
||||
@ -342,7 +340,7 @@ func DeleteOrganization(ctx context.Context, org *Organization) error {
|
||||
return fmt.Errorf("deleteBeans: %v", err)
|
||||
}
|
||||
|
||||
if _, err := e.ID(org.ID).Delete(new(user_model.User)); err != nil {
|
||||
if _, err := db.GetEngine(ctx).ID(org.ID).Delete(new(user_model.User)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
}
|
||||
|
||||
|
@ -765,7 +765,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := deleteBeans(sess,
|
||||
if err := db.DeleteBeans(ctx,
|
||||
&Access{RepoID: repo.ID},
|
||||
&Action{RepoID: repo.ID},
|
||||
&Collaboration{RepoID: repoID},
|
||||
|
@ -29,16 +29,6 @@ func GetOrganizationCount(ctx context.Context, u *user_model.User) (int64, error
|
||||
Count(new(OrgUser))
|
||||
}
|
||||
|
||||
// deleteBeans deletes all given beans, beans should contain delete conditions.
|
||||
func deleteBeans(e db.Engine, beans ...interface{}) (err error) {
|
||||
for i := range beans {
|
||||
if _, err = e.Delete(beans[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUser deletes models associated to an user.
|
||||
func DeleteUser(ctx context.Context, u *user_model.User) (err error) {
|
||||
e := db.GetEngine(ctx)
|
||||
@ -82,7 +72,7 @@ func DeleteUser(ctx context.Context, u *user_model.User) (err error) {
|
||||
}
|
||||
// ***** END: Follow *****
|
||||
|
||||
if err = deleteBeans(e,
|
||||
if err = db.DeleteBeans(ctx,
|
||||
&AccessToken{UID: u.ID},
|
||||
&Collaboration{UserID: u.ID},
|
||||
&Access{UserID: u.ID},
|
||||
|
Loading…
Reference in New Issue
Block a user