File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -291,7 +291,17 @@ func CountNullArchivedRepository() (int64, error) {
291291
292292// FixNullArchivedRepository sets is_archived to false where it is null
293293func FixNullArchivedRepository () (int64 , error ) {
294- return x .Where (builder.IsNull {"is_archived" }).Cols ("is_archived" ).Update (& Repository {
294+ return x .Where (builder.IsNull {"is_archived" }).Cols ("is_archived" ).NoAutoTime (). Update (& Repository {
295295 IsArchived : false ,
296296 })
297297}
298+
299+ // CountWrongUserType count OrgUser who have wrong type
300+ func CountWrongUserType () (int64 , error ) {
301+ return x .Where (builder.Eq {"type" : 0 }.And (builder.Neq {"num_teams" : 0 })).Count (new (User ))
302+ }
303+
304+ // FixWrongUserType fix OrgUser who have wrong type
305+ func FixWrongUserType () (int64 , error ) {
306+ return x .Where (builder.Eq {"type" : 0 }.And (builder.Neq {"num_teams" : 0 })).Cols ("type" ).NoAutoTime ().Update (& User {Type : 1 })
307+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2021 The Gitea Authors. All rights reserved.
2+ // Use of this source code is governed by a MIT-style
3+ // license that can be found in the LICENSE file.
4+
5+ package doctor
6+
7+ import (
8+ "code.gitea.io/gitea/models"
9+ "code.gitea.io/gitea/modules/log"
10+ )
11+
12+ func checkUserType (logger log.Logger , autofix bool ) error {
13+ count , err := models .CountWrongUserType ()
14+ if err != nil {
15+ logger .Critical ("Error: %v whilst counting wrong user types" )
16+ return err
17+ }
18+ if count > 0 {
19+ if autofix {
20+ if count , err = models .FixWrongUserType (); err != nil {
21+ logger .Critical ("Error: %v whilst fixing wrong user types" )
22+ return err
23+ }
24+ logger .Info ("%d users with wrong type fixed" , count )
25+ } else {
26+ logger .Warn ("%d users with wrong type exist" , count )
27+ }
28+ }
29+ return nil
30+ }
31+
32+ func init () {
33+ Register (& Check {
34+ Title : "Check if user with wrong type exist" ,
35+ Name : "check-user-type" ,
36+ IsDefault : true ,
37+ Run : checkUserType ,
38+ Priority : 3 ,
39+ })
40+ }
You can’t perform that action at this time.
0 commit comments