Skip to content

Commit

Permalink
Clean up message handling after importing a zipped problem.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
meisterT committed Nov 24, 2023
1 parent 7112ab3 commit 68c660a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
21 changes: 14 additions & 7 deletions webapp/src/Controller/Jury/ImportExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function indexAction(Request $request): Response
$this->dj->auditlog('problem', $newProblem->getProbid(), 'upload zip',
$clientName);
} else {
$this->addFlash('danger', implode("\n", $allMessages));
$this->postMessages($allMessages);
return $this->redirectToRoute('jury_problems');
}
} catch (Exception $e) {
Expand All @@ -174,12 +174,7 @@ public function indexAction(Request $request): Response
$zip->close();
}
}

foreach (['info', 'warning', 'danger'] as $type) {
if (!empty($allMessages[$type])) {
$this->addFlash($type, implode("\n", $allMessages[$type]));
}
}
$this->postMessages($allMessages);

if ($newProblem !== null) {
return $this->redirectToRoute('jury_problem', ['probId' => $newProblem->getProbid()]);
Expand Down Expand Up @@ -561,4 +556,16 @@ protected function getClarificationsHtml(): Response
'problems' => $contestProblems,
]);
}

/**
* @param array<string, string[]> $allMessages
*/
private function postMessages(array $allMessages): void
{
foreach (['info', 'warning', 'danger'] as $type) {
if (!empty($allMessages[$type])) {
$this->addFlash($type, implode("\n", $allMessages[$type]));
}
}
}
}
19 changes: 13 additions & 6 deletions webapp/src/Controller/Jury/ProblemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,7 @@ public function editAction(Request $request, int $probId): Response
$zip->close();
}
}

foreach (['info', 'warning', 'danger'] as $type) {
if (!empty($messages[$type])) {
$this->addFlash($type, implode("\n", $messages[$type]));
}
}
$this->postMessages($messages);

return $this->redirectToRoute('jury_problem', ['probId' => $problem->getProbid()]);
}
Expand Down Expand Up @@ -1102,4 +1097,16 @@ public function requestRemainingRunsWholeProblemAction(string $probId): Redirect
$this->judgeRemaining($judgings);
return $this->redirectToRoute('jury_problem', ['probId' => $probId]);
}

/**
* @param array<string, string[]> $allMessages
*/
private function postMessages(array $allMessages): void
{
foreach (['info', 'warning', 'danger'] as $type) {
if (!empty($allMessages[$type])) {
$this->addFlash($type, implode("\n", $allMessages[$type]));
}
}
}
}

0 comments on commit 68c660a

Please sign in to comment.