8
8
"errors"
9
9
"fmt"
10
10
"net/http"
11
- "strconv"
12
11
"strings"
13
12
"time"
14
13
@@ -298,8 +297,8 @@ func SettingsPost(ctx *context.Context) {
298
297
return
299
298
}
300
299
301
- m , err := selectPushMirrorByForm (ctx , form , repo )
302
- if err ! = nil {
300
+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
301
+ if m = = nil {
303
302
ctx .NotFound ("" , nil )
304
303
return
305
304
}
@@ -325,15 +324,13 @@ func SettingsPost(ctx *context.Context) {
325
324
return
326
325
}
327
326
328
- id , err := strconv . ParseInt ( form .PushMirrorID , 10 , 64 )
329
- if err ! = nil {
330
- ctx .ServerError ( "UpdatePushMirrorIntervalPushMirrorID " , err )
327
+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID ( ctx , form .PushMirrorID , repo . ID )
328
+ if m = = nil {
329
+ ctx .NotFound ( " " , nil )
331
330
return
332
331
}
333
- m := & repo_model.PushMirror {
334
- ID : id ,
335
- Interval : interval ,
336
- }
332
+
333
+ m .Interval = interval
337
334
if err := repo_model .UpdatePushMirrorInterval (ctx , m ); err != nil {
338
335
ctx .ServerError ("UpdatePushMirrorInterval" , err )
339
336
return
@@ -342,7 +339,10 @@ func SettingsPost(ctx *context.Context) {
342
339
// If we observed its implementation in the context of `push-mirror-sync` where it
343
340
// is evident that pushing to the queue is necessary for updates.
344
341
// So, there are updates within the given interval, it is necessary to update the queue accordingly.
345
- mirror_service .AddPushMirrorToQueue (m .ID )
342
+ if ! ctx .FormBool ("push_mirror_defer_sync" ) {
343
+ // push_mirror_defer_sync is mainly for testing purpose, we do not really want to sync the push mirror immediately
344
+ mirror_service .AddPushMirrorToQueue (m .ID )
345
+ }
346
346
ctx .Flash .Success (ctx .Tr ("repo.settings.update_settings_success" ))
347
347
ctx .Redirect (repo .Link () + "/settings" )
348
348
@@ -356,18 +356,18 @@ func SettingsPost(ctx *context.Context) {
356
356
// as an error on the UI for this action
357
357
ctx .Data ["Err_RepoName" ] = nil
358
358
359
- m , err := selectPushMirrorByForm (ctx , form , repo )
360
- if err ! = nil {
359
+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
360
+ if m = = nil {
361
361
ctx .NotFound ("" , nil )
362
362
return
363
363
}
364
364
365
- if err = mirror_service .RemovePushMirrorRemote (ctx , m ); err != nil {
365
+ if err : = mirror_service .RemovePushMirrorRemote (ctx , m ); err != nil {
366
366
ctx .ServerError ("RemovePushMirrorRemote" , err )
367
367
return
368
368
}
369
369
370
- if err = repo_model .DeletePushMirrors (ctx , repo_model.PushMirrorOptions {ID : m .ID , RepoID : m .RepoID }); err != nil {
370
+ if err : = repo_model .DeletePushMirrors (ctx , repo_model.PushMirrorOptions {ID : m .ID , RepoID : m .RepoID }); err != nil {
371
371
ctx .ServerError ("DeletePushMirrorByID" , err )
372
372
return
373
373
}
@@ -970,24 +970,3 @@ func handleSettingRemoteAddrError(ctx *context.Context, err error, form *forms.R
970
970
}
971
971
ctx .RenderWithErr (ctx .Tr ("repo.mirror_address_url_invalid" ), tplSettingsOptions , form )
972
972
}
973
-
974
- func selectPushMirrorByForm (ctx * context.Context , form * forms.RepoSettingForm , repo * repo_model.Repository ) (* repo_model.PushMirror , error ) {
975
- id , err := strconv .ParseInt (form .PushMirrorID , 10 , 64 )
976
- if err != nil {
977
- return nil , err
978
- }
979
-
980
- pushMirrors , _ , err := repo_model .GetPushMirrorsByRepoID (ctx , repo .ID , db.ListOptions {})
981
- if err != nil {
982
- return nil , err
983
- }
984
-
985
- for _ , m := range pushMirrors {
986
- if m .ID == id {
987
- m .Repo = repo
988
- return m , nil
989
- }
990
- }
991
-
992
- return nil , fmt .Errorf ("PushMirror[%v] not associated to repository %v" , id , repo )
993
- }
0 commit comments