2017-02-07 12:47:55 +01:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2021-09-19 13:49:59 +02:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-12-10 02:27:50 +01:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-05-10 02:49:01 +02:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-11-12 01:56:45 +01:00
|
|
|
|
2020-05-29 15:24:15 +02:00
|
|
|
"xorm.io/builder"
|
2017-02-07 12:47:55 +01:00
|
|
|
)
|
|
|
|
|
2020-06-11 22:18:11 +02:00
|
|
|
// CountNullArchivedRepository counts the number of repositories with is_archived is null
|
|
|
|
func CountNullArchivedRepository() (int64, error) {
|
2021-12-10 02:27:50 +01:00
|
|
|
return db.GetEngine(db.DefaultContext).Where(builder.IsNull{"is_archived"}).Count(new(repo_model.Repository))
|
2020-06-11 22:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// FixNullArchivedRepository sets is_archived to false where it is null
|
|
|
|
func FixNullArchivedRepository() (int64, error) {
|
2021-12-10 02:27:50 +01:00
|
|
|
return db.GetEngine(db.DefaultContext).Where(builder.IsNull{"is_archived"}).Cols("is_archived").NoAutoTime().Update(&repo_model.Repository{
|
2020-06-11 22:18:11 +02:00
|
|
|
IsArchived: false,
|
|
|
|
})
|
|
|
|
}
|
2021-01-29 19:30:43 +01:00
|
|
|
|
|
|
|
// CountWrongUserType count OrgUser who have wrong type
|
|
|
|
func CountWrongUserType() (int64, error) {
|
2021-11-24 10:49:20 +01:00
|
|
|
return db.GetEngine(db.DefaultContext).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Count(new(user_model.User))
|
2021-01-29 19:30:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// FixWrongUserType fix OrgUser who have wrong type
|
|
|
|
func FixWrongUserType() (int64, error) {
|
2021-11-24 10:49:20 +01:00
|
|
|
return db.GetEngine(db.DefaultContext).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Cols("type").NoAutoTime().Update(&user_model.User{Type: 1})
|
2021-01-29 19:30:43 +01:00
|
|
|
}
|
2021-02-10 03:50:44 +01:00
|
|
|
|
2022-05-10 02:49:01 +02:00
|
|
|
// CountActionCreatedUnixString count actions where created_unix is an empty string
|
|
|
|
func CountActionCreatedUnixString() (int64, error) {
|
|
|
|
if setting.Database.UseSQLite3 {
|
|
|
|
return db.GetEngine(db.DefaultContext).Where(`created_unix = ""`).Count(new(Action))
|
|
|
|
}
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FixActionCreatedUnixString set created_unix to zero if it is an empty string
|
|
|
|
func FixActionCreatedUnixString() (int64, error) {
|
|
|
|
if setting.Database.UseSQLite3 {
|
|
|
|
res, err := db.GetEngine(db.DefaultContext).Exec(`UPDATE action SET created_unix = 0 WHERE created_unix = ""`)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return res.RowsAffected()
|
|
|
|
}
|
|
|
|
return 0, nil
|
|
|
|
}
|