@@ -70,106 +70,6 @@ public function indexAction(Request $request): Response
70
70
{
71
71
$ em = $ this ->em ;
72
72
73
- if ($ doNow = $ request ->request ->all ('donow ' )) {
74
- $ times = ['activate ' , 'start ' , 'freeze ' , 'end ' ,
75
- 'unfreeze ' , 'finalize ' , 'deactivate ' ];
76
- $ start_actions = ['delay_start ' , 'resume_start ' ];
77
- $ actions = array_merge ($ times , $ start_actions );
78
-
79
- if (!$ this ->isGranted ('ROLE_ADMIN ' )) {
80
- throw new AccessDeniedHttpException ();
81
- }
82
- $ contest = $ em ->getRepository (Contest::class)->find ($ request ->request ->get ('contest ' ));
83
- if (!$ contest ) {
84
- throw new NotFoundHttpException ('Contest not found ' );
85
- }
86
-
87
- $ time = key ($ doNow );
88
- if (!in_array ($ time , $ actions , true )) {
89
- throw new BadRequestHttpException (
90
- sprintf ("Unknown value '%s' for timetype " , $ time )
91
- );
92
- }
93
-
94
- if ($ time === 'finalize ' ) {
95
- return $ this ->redirectToRoute (
96
- 'jury_contest_finalize ' ,
97
- ['contestId ' => $ contest ->getCid ()]
98
- );
99
- }
100
-
101
- $ now = (int )floor (Utils::now ());
102
- $ nowstring = date ('Y-m-d H:i:s ' , $ now ) . date_default_timezone_get ();
103
- $ this ->dj ->auditlog ('contest ' , $ contest ->getCid (), $ time . ' now ' , $ nowstring );
104
-
105
- // Special case delay/resume start (only sets/unsets starttime_undefined).
106
- $ maxSeconds = Contest::STARTTIME_UPDATE_MIN_SECONDS_BEFORE ;
107
- if (in_array ($ time , $ start_actions , true )) {
108
- $ enabled = $ time !== 'delay_start ' ;
109
- if (Utils::difftime ((float )$ contest ->getStarttime (false ), $ now ) <= $ maxSeconds ) {
110
- $ this ->addFlash (
111
- 'error ' ,
112
- sprintf ("Cannot %s less than %d seconds before contest start. " ,
113
- $ time , $ maxSeconds )
114
- );
115
- return $ this ->redirectToRoute ('jury_contests ' );
116
- }
117
- $ contest ->setStarttimeEnabled ($ enabled );
118
- $ em ->flush ();
119
- $ this ->eventLogService ->log (
120
- 'contest ' ,
121
- $ contest ->getCid (),
122
- EventLogService::ACTION_UPDATE ,
123
- $ contest ->getCid ()
124
- );
125
- $ this ->addFlash ('scoreboard_refresh ' ,
126
- 'After changing the contest start time, it may be ' .
127
- 'necessary to recalculate any cached scoreboards. ' );
128
- return $ this ->redirectToRoute ('jury_contests ' );
129
- }
130
-
131
- $ juryTimeData = $ contest ->getDataForJuryInterface ();
132
- if (!$ juryTimeData [$ time ]['show_button ' ]) {
133
- throw new BadRequestHttpException (
134
- sprintf ('Cannot update %s time at this moment ' , $ time )
135
- );
136
- }
137
-
138
- // starttime is special because other, relative times depend on it.
139
- if ($ time == 'start ' ) {
140
- if ($ contest ->getStarttimeEnabled () &&
141
- Utils::difftime ((float )$ contest ->getStarttime (false ),
142
- $ now ) <= $ maxSeconds ) {
143
- $ this ->addFlash (
144
- 'danger ' ,
145
- sprintf ("Cannot update starttime less than %d seconds before contest start. " ,
146
- $ maxSeconds )
147
- );
148
- return $ this ->redirectToRoute ('jury_contests ' );
149
- }
150
- $ contest
151
- ->setStarttime ($ now )
152
- ->setStarttimeString ($ nowstring )
153
- ->setStarttimeEnabled (true );
154
- $ em ->flush ();
155
-
156
- $ this ->addFlash ('scoreboard_refresh ' ,
157
- 'After changing the contest start time, it may be ' .
158
- 'necessary to recalculate any cached scoreboards. ' );
159
- } else {
160
- $ method = sprintf ('set%stimeString ' , $ time );
161
- $ contest ->{$ method }($ nowstring );
162
- $ em ->flush ();
163
- }
164
- $ this ->eventLogService ->log (
165
- 'contest ' ,
166
- $ contest ->getCid (),
167
- EventLogService::ACTION_UPDATE ,
168
- $ contest ->getCid ()
169
- );
170
- return $ this ->redirectToRoute ('jury_contests ' );
171
- }
172
-
173
73
/** @var Contest[] $contests */
174
74
$ contests = $ em ->createQueryBuilder ()
175
75
->select ('c ' )
@@ -872,6 +772,102 @@ public function finalizeAction(Request $request, int $contestId): Response
872
772
]);
873
773
}
874
774
775
+ #[IsGranted('ROLE_ADMIN ' )]
776
+ #[Route(path: '/{contestId<\d+>}/{time}/doNow ' , name: 'jury_contest_donow ' )]
777
+ public function doNowAction (Request $ request , int $ contestId , string $ time ): Response
778
+ {
779
+ $ times = ['activate ' , 'start ' , 'freeze ' , 'end ' , 'unfreeze ' , 'finalize ' , 'deactivate ' ];
780
+ $ start_actions = ['delay_start ' , 'resume_start ' ];
781
+ $ actions = array_merge ($ times , $ start_actions );
782
+
783
+ $ contest = $ this ->em ->getRepository (Contest::class)->find ($ contestId );
784
+ if (!$ contest ) {
785
+ throw new NotFoundHttpException (sprintf ('Contest with ID %s not found ' , $ contestId ));
786
+ }
787
+
788
+ if (!in_array ($ time , $ actions , true )) {
789
+ throw new BadRequestHttpException (sprintf ("Unknown value '%s' for timetype " , $ time ));
790
+ }
791
+
792
+ if ($ time === 'finalize ' ) {
793
+ return $ this ->redirectToRoute ('jury_contest_finalize ' , ['contestId ' => $ contest ->getCid ()]);
794
+ }
795
+
796
+ $ now = (int )floor (Utils::now ());
797
+ $ nowstring = date ('Y-m-d H:i:s ' , $ now ) . date_default_timezone_get ();
798
+ $ this ->dj ->auditlog ('contest ' , $ contest ->getCid (), $ time . ' now ' , $ nowstring );
799
+
800
+ // Special case delay/resume start (only sets/unsets starttime_undefined).
801
+ $ maxSeconds = Contest::STARTTIME_UPDATE_MIN_SECONDS_BEFORE ;
802
+ if (in_array ($ time , $ start_actions , true )) {
803
+ $ enabled = $ time !== 'delay_start ' ;
804
+ if (Utils::difftime ((float )$ contest ->getStarttime (false ), $ now ) <= $ maxSeconds ) {
805
+ $ this ->addFlash (
806
+ 'error ' ,
807
+ sprintf ("Cannot '%s' less than %d seconds before contest start. " ,
808
+ $ time , $ maxSeconds )
809
+ );
810
+ return $ this ->redirectToRoute ('jury_contests ' );
811
+ }
812
+ $ contest ->setStarttimeEnabled ($ enabled );
813
+ $ this ->em ->flush ();
814
+ $ this ->eventLogService ->log (
815
+ 'contest ' ,
816
+ $ contest ->getCid (),
817
+ EventLogService::ACTION_UPDATE ,
818
+ $ contest ->getCid ()
819
+ );
820
+ $ this ->addFlash ('scoreboard_refresh ' , 'After changing the contest start time, it may be '
821
+ . 'necessary to recalculate any cached scoreboards. ' );
822
+ return $ this ->redirectToRoute ('jury_contests ' );
823
+ }
824
+
825
+ $ juryTimeData = $ contest ->getDataForJuryInterface ();
826
+ if (!$ juryTimeData [$ time ]['show_button ' ]) {
827
+ throw new BadRequestHttpException (
828
+ sprintf ("Cannot update '%s' time at this moment " , $ time )
829
+ );
830
+ }
831
+
832
+ // starttime is special because other, relative times depend on it.
833
+ if ($ time == 'start ' ) {
834
+ if ($ contest ->getStarttimeEnabled () &&
835
+ Utils::difftime ((float )$ contest ->getStarttime (false ),
836
+ $ now ) <= $ maxSeconds ) {
837
+ $ this ->addFlash (
838
+ 'danger ' ,
839
+ sprintf ("Cannot update starttime less than %d seconds before contest start. " ,
840
+ $ maxSeconds )
841
+ );
842
+ return $ this ->redirectToRoute ('jury_contests ' );
843
+ }
844
+ $ contest
845
+ ->setStarttime ($ now )
846
+ ->setStarttimeString ($ nowstring )
847
+ ->setStarttimeEnabled (true );
848
+ $ this ->em ->flush ();
849
+
850
+ $ this ->addFlash ('scoreboard_refresh ' , 'After changing the contest start time, it may be '
851
+ . 'necessary to recalculate any cached scoreboards. ' );
852
+ } else {
853
+ $ method = sprintf ('set%stimeString ' , $ time );
854
+ $ contest ->{$ method }($ nowstring );
855
+ $ this ->em ->flush ();
856
+ }
857
+ $ this ->eventLogService ->log (
858
+ 'contest ' ,
859
+ $ contest ->getCid (),
860
+ EventLogService::ACTION_UPDATE ,
861
+ $ contest ->getCid ()
862
+ );
863
+
864
+ $ referer = $ request ->headers ->get ('referer ' );
865
+ if ($ referer ) {
866
+ return $ this ->redirect ($ referer );
867
+ }
868
+ return $ this ->redirectToRoute ('jury_contests ' );
869
+ }
870
+
875
871
#[Route(path: '/{contestId<\d+>}/request-remaining ' , name: 'jury_contest_request_remaining ' )]
876
872
public function requestRemainingRunsWholeContestAction (int $ contestId ): RedirectResponse
877
873
{
0 commit comments