summaryrefslogtreecommitdiffstats
path: root/models/repo_mirror.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo_mirror.go')
-rw-r--r--models/repo_mirror.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/models/repo_mirror.go b/models/repo_mirror.go
index cd1f74cb24..b086b87cf1 100644
--- a/models/repo_mirror.go
+++ b/models/repo_mirror.go
@@ -8,6 +8,7 @@ package models
import (
"time"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
@@ -37,6 +38,10 @@ type Mirror struct {
Address string `xorm:"-"`
}
+func init() {
+ db.RegisterModel(new(Mirror))
+}
+
// BeforeInsert will be invoked by XORM before inserting a record
func (m *Mirror) BeforeInsert() {
if m != nil {
@@ -77,7 +82,7 @@ func (m *Mirror) ScheduleNextUpdate() {
}
}
-func getMirrorByRepoID(e Engine, repoID int64) (*Mirror, error) {
+func getMirrorByRepoID(e db.Engine, repoID int64) (*Mirror, error) {
m := &Mirror{RepoID: repoID}
has, err := e.Get(m)
if err != nil {
@@ -90,28 +95,28 @@ func getMirrorByRepoID(e Engine, repoID int64) (*Mirror, error) {
// GetMirrorByRepoID returns mirror information of a repository.
func GetMirrorByRepoID(repoID int64) (*Mirror, error) {
- return getMirrorByRepoID(x, repoID)
+ return getMirrorByRepoID(db.DefaultContext().Engine(), repoID)
}
-func updateMirror(e Engine, m *Mirror) error {
+func updateMirror(e db.Engine, m *Mirror) error {
_, err := e.ID(m.ID).AllCols().Update(m)
return err
}
// UpdateMirror updates the mirror
func UpdateMirror(m *Mirror) error {
- return updateMirror(x, m)
+ return updateMirror(db.DefaultContext().Engine(), m)
}
// DeleteMirrorByRepoID deletes a mirror by repoID
func DeleteMirrorByRepoID(repoID int64) error {
- _, err := x.Delete(&Mirror{RepoID: repoID})
+ _, err := db.DefaultContext().Engine().Delete(&Mirror{RepoID: repoID})
return err
}
// MirrorsIterate iterates all mirror repositories.
func MirrorsIterate(f func(idx int, bean interface{}) error) error {
- return x.
+ return db.DefaultContext().Engine().
Where("next_update_unix<=?", time.Now().Unix()).
And("next_update_unix!=0").
Iterate(new(Mirror), f)
@@ -119,6 +124,6 @@ func MirrorsIterate(f func(idx int, bean interface{}) error) error {
// InsertMirror inserts a mirror to database
func InsertMirror(mirror *Mirror) error {
- _, err := x.Insert(mirror)
+ _, err := db.DefaultContext().Engine().Insert(mirror)
return err
}