diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-21 23:41:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-21 23:41:00 +0800 |
commit | d710af6669654f27f02b69d7ef1ba563e7d58a90 (patch) | |
tree | 9727f468a570106293dc90beb70035180bbb7e8e /models/webhook | |
parent | 0add627182388ac63fd04b94cdf912fb87fd0326 (diff) | |
download | gitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.tar.gz gitea-d710af6669654f27f02b69d7ef1ba563e7d58a90.zip |
Remove NewSession method from db.Engine interface (#17577)
* Remove NewSession method from db.Engine interface
* Fix bug
* Some improvements
* Fix bug
* Fix test
* Use XXXBean instead of XXXExample
Diffstat (limited to 'models/webhook')
-rw-r--r-- | models/webhook/webhook.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go index de8bd5e338..d01f548eed 100644 --- a/models/webhook/webhook.go +++ b/models/webhook/webhook.go @@ -507,21 +507,21 @@ func UpdateWebhookLastStatus(w *Webhook) error { // deleteWebhook uses argument bean as query condition, // ID must be specified and do not assign unnecessary fields. func deleteWebhook(bean *Webhook) (err error) { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err = sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() - if count, err := sess.Delete(bean); err != nil { + if count, err := db.DeleteByBean(ctx, bean); err != nil { return err } else if count == 0 { return ErrWebhookNotExist{ID: bean.ID} - } else if _, err = sess.Delete(&HookTask{HookID: bean.ID}); err != nil { + } else if _, err = db.DeleteByBean(ctx, &HookTask{HookID: bean.ID}); err != nil { return err } - return sess.Commit() + return committer.Commit() } // DeleteWebhookByRepoID deletes webhook of repository by given ID. @@ -542,13 +542,13 @@ func DeleteWebhookByOrgID(orgID, id int64) error { // DeleteDefaultSystemWebhook deletes an admin-configured default or system webhook (where Org and Repo ID both 0) func DeleteDefaultSystemWebhook(id int64) error { - sess := db.NewSession(db.DefaultContext) - defer sess.Close() - if err := sess.Begin(); err != nil { + ctx, committer, err := db.TxContext() + if err != nil { return err } + defer committer.Close() - count, err := sess. + count, err := db.GetEngine(ctx). Where("repo_id=? AND org_id=?", 0, 0). Delete(&Webhook{ID: id}) if err != nil { @@ -557,11 +557,11 @@ func DeleteDefaultSystemWebhook(id int64) error { return ErrWebhookNotExist{ID: id} } - if _, err := sess.Delete(&HookTask{HookID: id}); err != nil { + if _, err := db.DeleteByBean(ctx, &HookTask{HookID: id}); err != nil { return err } - return sess.Commit() + return committer.Commit() } // CopyDefaultWebhooksToRepo creates copies of the default webhooks in a new repo |