88	"errors" 
99	"fmt" 
1010	"net/http" 
11- 	"strconv" 
1211	"strings" 
1312	"time" 
1413
@@ -290,8 +289,8 @@ func SettingsPost(ctx *context.Context) {
290289			return 
291290		}
292291
293- 		m , err   :=  selectPushMirrorByForm (ctx , form , repo )
294- 		if  err   ! =nil  {
292+ 		m , _ ,  _   :=  repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
293+ 		if  m   = =nil  {
295294			ctx .NotFound ("" , nil )
296295			return 
297296		}
@@ -317,15 +316,13 @@ func SettingsPost(ctx *context.Context) {
317316			return 
318317		}
319318
320- 		id ,  err   :=  strconv . ParseInt ( form .PushMirrorID , 10 ,  64 )
321- 		if  err   ! =nil  {
322- 			ctx .ServerError ( "UpdatePushMirrorIntervalPushMirrorID "err )
319+ 		m ,  _ ,  _   :=  repo_model . GetPushMirrorByIDAndRepoID ( ctx ,  form .PushMirrorID , repo . ID )
320+ 		if  m   = =nil  {
321+ 			ctx .NotFound ( " "nil )
323322			return 
324323		}
325- 		m  :=  & repo_model.PushMirror {
326- 			ID :       id ,
327- 			Interval : interval ,
328- 		}
324+ 
325+ 		m .Interval  =  interval 
329326		if  err  :=  repo_model .UpdatePushMirrorInterval (ctx , m ); err  !=  nil  {
330327			ctx .ServerError ("UpdatePushMirrorInterval" , err )
331328			return 
@@ -334,7 +331,10 @@ func SettingsPost(ctx *context.Context) {
334331		// If we observed its implementation in the context of `push-mirror-sync` where it 
335332		// is evident that pushing to the queue is necessary for updates. 
336333		// So, there are updates within the given interval, it is necessary to update the queue accordingly. 
337- 		mirror_service .AddPushMirrorToQueue (m .ID )
334+ 		if  ! ctx .FormBool ("push_mirror_defer_sync" ) {
335+ 			// push_mirror_defer_sync is mainly for testing purpose, we do not really want to sync the push mirror immediately 
336+ 			mirror_service .AddPushMirrorToQueue (m .ID )
337+ 		}
338338		ctx .Flash .Success (ctx .Tr ("repo.settings.update_settings_success" ))
339339		ctx .Redirect (repo .Link () +  "/settings" )
340340
@@ -348,18 +348,18 @@ func SettingsPost(ctx *context.Context) {
348348		// as an error on the UI for this action 
349349		ctx .Data ["Err_RepoName" ] =  nil 
350350
351- 		m , err   :=  selectPushMirrorByForm (ctx , form , repo )
352- 		if  err   ! =nil  {
351+ 		m , _ ,  _   :=  repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
352+ 		if  m   = =nil  {
353353			ctx .NotFound ("" , nil )
354354			return 
355355		}
356356
357- 		if  err  =  mirror_service .RemovePushMirrorRemote (ctx , m ); err  !=  nil  {
357+ 		if  err  : =mirror_service .RemovePushMirrorRemote (ctx , m ); err  !=  nil  {
358358			ctx .ServerError ("RemovePushMirrorRemote" , err )
359359			return 
360360		}
361361
362- 		if  err  =  repo_model .DeletePushMirrors (ctx , repo_model.PushMirrorOptions {ID : m .ID , RepoID : m .RepoID }); err  !=  nil  {
362+ 		if  err  : =repo_model .DeletePushMirrors (ctx , repo_model.PushMirrorOptions {ID : m .ID , RepoID : m .RepoID }); err  !=  nil  {
363363			ctx .ServerError ("DeletePushMirrorByID" , err )
364364			return 
365365		}
@@ -995,24 +995,3 @@ func handleSettingRemoteAddrError(ctx *context.Context, err error, form *forms.R
995995	}
996996	ctx .RenderWithErr (ctx .Tr ("repo.mirror_address_url_invalid" ), tplSettingsOptions , form )
997997}
998- 
999- func  selectPushMirrorByForm (ctx  * context.Context , form  * forms.RepoSettingForm , repo  * repo_model.Repository ) (* repo_model.PushMirror , error ) {
1000- 	id , err  :=  strconv .ParseInt (form .PushMirrorID , 10 , 64 )
1001- 	if  err  !=  nil  {
1002- 		return  nil , err 
1003- 	}
1004- 
1005- 	pushMirrors , _ , err  :=  repo_model .GetPushMirrorsByRepoID (ctx , repo .ID , db.ListOptions {})
1006- 	if  err  !=  nil  {
1007- 		return  nil , err 
1008- 	}
1009- 
1010- 	for  _ , m  :=  range  pushMirrors  {
1011- 		if  m .ID  ==  id  {
1012- 			m .Repo  =  repo 
1013- 			return  m , nil 
1014- 		}
1015- 	}
1016- 
1017- 	return  nil , fmt .Errorf ("PushMirror[%v] not associated to repository %v" , id , repo )
1018- }
0 commit comments