@@ -296,6 +296,64 @@ public function viewAction(Request $request, int $judgehostid): Response
296296 }
297297 }
298298
299+ private function helperGenericTask (int $ execid , ?JudgeHost $ judgehost = null ): void {
300+ $ executable = $ this ->em ->getRepository (Executable::class)->findOneBy (['execid ' => $ execid ]);
301+ if (!$ executable ) {
302+ throw new NotFoundHttpException (sprintf ('Executable with ID %d not found ' , $ execid ));
303+ }
304+
305+ $ executable = $ executable ->getImmutableExecutable ();
306+
307+ $ judgehosts = [];
308+ if ($ judgehost ) {
309+ $ judgehosts [] = $ judgehost ;
310+ } else {
311+ /** @var Judgehost[] $judgehosts */
312+ $ judgehosts = $ this ->em ->createQueryBuilder ()
313+ ->from (Judgehost::class, 'j ' )
314+ ->select ('j ' )
315+ ->andWhere ('j.hidden = 0 ' )
316+ ->getQuery ()->getResult ();
317+ }
318+ foreach ($ judgehosts as $ judgehost ) {
319+ $ judgeTask = new JudgeTask ();
320+ $ judgeTask
321+ ->setType (JudgeTaskType::GENERIC_TASK )
322+ ->setPriority (JudgeTask::PRIORITY_HIGH )
323+ ->setRunScriptId ($ executable ->getImmutableExecId ())
324+ ->setRunConfig (Utils::jsonEncode (['hash ' => $ executable ->getHash ()]));
325+ $ this ->em ->persist ($ judgeTask );
326+ }
327+ $ this ->em ->flush ();
328+ }
329+
330+ #[IsGranted('ROLE_ADMIN ' )]
331+ #[Route(path: '/{judgehostid}/request-generic-task/{execid} ' , name: 'jury_request_judgehost_generic ' )]
332+ public function requestGenericTaskJudgehost (Request $ request , int $ judgehostid , int $ execid ): RedirectResponse
333+ {
334+ $ judgehost = $ this ->em ->getRepository (Judgehost::class)->find ($ judgehostid );
335+ if (!$ judgehost ) {
336+ throw new NotFoundHttpException (sprintf ('Judgehost with ID %d not found ' , $ judgehostid ));
337+ }
338+
339+ $ this ->helperGenericTask ($ execid , $ judgehost );
340+
341+ return $ this ->redirectToRoute ('jury_judgehost ' , [
342+ 'judgehostid ' => $ judgehostid
343+ ]);
344+ }
345+
346+ // TODO: Does the ordering matter in the file.
347+ #[IsGranted('ROLE_ADMIN ' )]
348+ #[Route(path: '/request-generic-task/{execid} ' , name: 'jury_request_generic ' )]
349+ public function requestGenericTask (Request $ request , int $ execid ): RedirectResponse
350+ {
351+ $ this ->helperGenericTask ($ execid );
352+ return $ this ->redirectToRoute ('jury_judgehost ' , [
353+ 'judgehostid ' => $ judgehostid
354+ ]);
355+ }
356+
299357 /**
300358 * @throws DBALException
301359 * @throws NoResultException
0 commit comments