Skip to content

Commit 5d96aab

Browse files
meisterTvmcj
authored andcommitted
Clean up message handling after importing a zipped problem.
Nowadays, the messages is a keyed array with the keys being the warning level. Previously, it was a flat data structure and apparently we didn't clean up all of them. There is still a code duplication between the two controller, but moving this to the Utils class is ugly because it would require passing in the controller. Fixes #2633. (cherry picked from commit a6640d5)
1 parent 6a91641 commit 5d96aab

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

webapp/src/Controller/Jury/ImportExportController.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function indexAction(Request $request): Response
184184
$this->dj->auditlog('problem', $newProblem->getProbid(), 'upload zip',
185185
$clientName);
186186
} else {
187-
$this->addFlash('danger', implode("\n", $allMessages));
187+
$this->postMessages($allMessages);
188188
return $this->redirectToRoute('jury_problems');
189189
}
190190
} catch (Exception $e) {
@@ -194,12 +194,7 @@ public function indexAction(Request $request): Response
194194
$zip->close();
195195
}
196196
}
197-
198-
foreach (['info', 'warning', 'danger'] as $type) {
199-
if (!empty($allMessages[$type])) {
200-
$this->addFlash($type, implode("\n", $allMessages[$type]));
201-
}
202-
}
197+
$this->postMessages($allMessages);
203198

204199
if ($newProblem !== null) {
205200
return $this->redirectToRoute('jury_problem', ['probId' => $newProblem->getProbid()]);
@@ -575,4 +570,16 @@ protected function getClarificationsHtml(): Response
575570
'problems' => $contestProblems,
576571
]);
577572
}
573+
574+
/**
575+
* @param array<string, string[]> $allMessages
576+
*/
577+
private function postMessages(array $allMessages): void
578+
{
579+
foreach (['info', 'warning', 'danger'] as $type) {
580+
if (!empty($allMessages[$type])) {
581+
$this->addFlash($type, implode("\n", $allMessages[$type]));
582+
}
583+
}
584+
}
578585
}

webapp/src/Controller/Jury/ProblemController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,7 @@ public function editAction(Request $request, int $probId): Response
972972
$zip->close();
973973
}
974974
}
975-
976-
foreach (['info', 'warning', 'danger'] as $type) {
977-
if (!empty($messages[$type])) {
978-
$this->addFlash($type, implode("\n", $messages[$type]));
979-
}
980-
}
975+
$this->postMessages($messages);
981976

982977
return $this->redirectToRoute('jury_problem', ['probId' => $problem->getProbid()]);
983978
}
@@ -1172,4 +1167,16 @@ public function requestRemainingRunsWholeProblemAction(string $probId): Redirect
11721167
$this->judgeRemaining($judgings);
11731168
return $this->redirect($this->generateUrl('jury_problem', ['probId' => $probId]));
11741169
}
1170+
1171+
/**
1172+
* @param array<string, string[]> $allMessages
1173+
*/
1174+
private function postMessages(array $allMessages): void
1175+
{
1176+
foreach (['info', 'warning', 'danger'] as $type) {
1177+
if (!empty($allMessages[$type])) {
1178+
$this->addFlash($type, implode("\n", $allMessages[$type]));
1179+
}
1180+
}
1181+
}
11751182
}

0 commit comments

Comments
 (0)