Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion webapp/src/Command/CallApiActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\User;
use App\Service\DOMJudgeService;
use App\Utils\Utils;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -114,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($json = $input->getOption('json')) {
$data = array_merge($data, $this->dj->jsonDecode($json));
$data = array_merge($data, Utils::jsonDecode($json));
}

foreach ($input->getOption('file') as $fileItem) {
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/Controller/API/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function addContestAction(Request $request): string
return $cid;
}
} elseif ($jsonFile) {
$data = $this->dj->jsonDecode(file_get_contents($jsonFile->getRealPath()));
$data = Utils::jsonDecode(file_get_contents($jsonFile->getRealPath()));
if ($this->importExportService->importContestData($data, $message, $cid)) {
return $cid;
}
Expand Down Expand Up @@ -870,7 +870,7 @@ public function getEventFeedAction(
$result['time'] = Utils::absTime($event->getEventtime());
}

echo $this->dj->jsonEncode($result) . "\n";
echo Utils::jsonEncode($result) . "\n";
ob_flush();
flush();
$lastUpdate = Utils::now();
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ public function internalErrorAction(Request $request): ?int
}
}

$disabled = $this->dj->jsonDecode($disabled);
$disabled = Utils::jsonDecode($disabled);

/** @var Contest|null $contest */
$contest = null;
Expand Down Expand Up @@ -770,7 +770,7 @@ public function internalErrorAction(Request $request): ?int
->andWhere('e.disabled = :disabled')
->andWhere('e.status = :status')
->setParameter('description', $description)
->setParameter('disabled', $this->dj->jsonEncode($disabled))
->setParameter('disabled', Utils::jsonEncode($disabled))
->setParameter('status', 'open')
->setMaxResults(1);

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/API/JudgementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
) {
parent::__construct($entityManager, $DOMJudgeService, $config, $eventLogService);

$this->verdicts = $this->dj->getVerdicts(['final', 'error']);
$this->verdicts = $this->config->getVerdicts(['final', 'error']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/API/JudgementTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function singleAction(Request $request, string $id): JudgementType
*/
protected function getJudgementTypes(?array $filteredOn = null): array
{
$verdicts = $this->dj->getVerdicts(['final', 'external']);
$verdicts = $this->config->getVerdicts(['final', 'external']);

$result = [];
foreach ($verdicts as $name => $label) {
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/Controller/API/LanguageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\ExecutableFile;
use App\Entity\ImmutableExecutable;
use App\Entity\Language;
use App\Utils\Utils;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\QueryBuilder;
use FOS\RestBundle\Controller\Annotations as Rest;
Expand Down Expand Up @@ -139,7 +140,7 @@ public function configureLanguagesAction(Request $request): Response
if (!$jsonFile) {
throw new BadRequestHttpException('No JSON file supplied.');
}
$newLanguages = $this->dj->jsonDecode(file_get_contents($jsonFile->getRealPath()));
$newLanguages = Utils::jsonDecode(file_get_contents($jsonFile->getRealPath()));

// Disable submission for all current languages, we will enable it for all new languages below.
$curLanguages = $this->em->getRepository(Language::class)->findAll();
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/Controller/API/ProblemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Service\EventLogService;
use App\Service\ImportExportService;
use App\Service\ImportProblemService;
use App\Utils\Utils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\QueryBuilder;
Expand Down Expand Up @@ -108,7 +109,7 @@ public function addProblemsAction(Request $request): array
}
$message = "Error while adding problems";
if (!empty($messages)) {
$message .= ': ' . $this->dj->jsonEncode($messages);
$message .= ': ' . Utils::jsonEncode($messages);
}
throw new BadRequestHttpException($message);
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/API/RunController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
parent::__construct($entityManager, $DOMJudgeService, $config,
$eventLogService);

$this->verdicts = $this->dj->getVerdicts();
$this->verdicts = $this->config->getVerdicts();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/Controller/Jury/BalloonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Service\ConfigurationService;
use App\Service\DOMJudgeService;
use App\Service\EventLogService;
use App\Utils\Utils;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\ExpressionLanguage\Expression;
Expand Down Expand Up @@ -77,7 +78,7 @@ public function indexAction(BalloonService $balloonService): Response
}

// Load preselected filters
$filters = $this->dj->jsonDecode((string)$this->dj->getCookie('domjudge_balloonsfilter') ?: '[]');
$filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_balloonsfilter') ?: '[]');
$haveFilters = $this->dj->getCookie('domjudge_balloonsfilter') != null;
$filteredAffiliations = [];
$filteredLocations = [];
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/Controller/Jury/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ public function prefetchAction(Request $request, int $contestId): Response
// TODO: dedup here?
$compareExec = $this->dj->getImmutableCompareExecutable($contestProblem);
$runExec = $this->dj->getImmutableRunExecutable($contestProblem);
$runConfig = $this->dj->jsonEncode(
$runConfig = Utils::jsonEncode(
[
'hash' => $runExec->getHash(),
'combined_run_compare' => $problem->getCombinedRunCompare(),
Expand All @@ -720,7 +720,7 @@ public function prefetchAction(Request $request, int $contestId): Response
->setJudgehost($judgehost)
->setPriority(JudgeTask::PRIORITY_DEFAULT)
->setCompareScriptId($compareExec->getImmutableExecId())
->setCompareConfig($this->dj->jsonEncode(['hash' => $compareExec->getHash()]))
->setCompareConfig(Utils::jsonEncode(['hash' => $compareExec->getHash()]))
->setRunScriptId($runExec->getImmutableExecId())
->setRunConfig($runConfig);
$this->em->persist($judgeTask);
Expand All @@ -741,7 +741,7 @@ public function prefetchAction(Request $request, int $contestId): Response
->setJudgehost($judgehost)
->setPriority(JudgeTask::PRIORITY_DEFAULT)
->setCompileScriptId($compileExec->getImmutableExecId())
->setCompileConfig($this->dj->jsonEncode(['hash' => $compileExec->getHash()]));
->setCompileConfig(Utils::jsonEncode(['hash' => $compileExec->getHash()]));
$this->em->persist($judgeTask);
$cnt++;
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/ExternalContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function indexAction(Request $request): Response
$this->sourceService->setSource($externalContestSource);

// Load preselected filters
$filters = $this->dj->jsonDecode((string)$this->dj->getCookie('domjudge_external_source_filter') ?: '[]');
$filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_external_source_filter') ?: '[]');

// Build the filter form.
$form = $this->createForm(ExternalSourceWarningsFilterType::class, $filters);
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/InternalErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function handleAction(Request $request, ?Profiler $profiler, int $errorId
if ($request->isXmlHttpRequest()) {
$profiler?->disable();
$progressReporter = function (int $progress, string $log, ?string $message = null) {
echo $this->dj->jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => $message]);
echo Utils::jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => $message]);
ob_flush();
flush();
};
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/Controller/Jury/JuryMiscController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Service\DOMJudgeService;
use App\Service\EventLogService;
use App\Service\ScoreboardService;
use App\Utils\Utils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Expr\Join;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
Expand Down Expand Up @@ -213,7 +214,7 @@ public function refreshCacheAction(Request $request, ScoreboardService $scoreboa

if ($request->isXmlHttpRequest() && $request->isMethod('POST')) {
$progressReporter = function (int $progress, string $log, ?string $message = null) {
echo $this->dj->jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => $message]);
echo Utils::jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => $message]);
ob_flush();
flush();
};
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/Controller/Jury/RejudgingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function viewAction(
$todo = $todoAndDone['todo'];
$done = $todoAndDone['done'];

$verdicts = $this->dj->getVerdicts(['final', 'error']);
$verdicts = $this->config->getVerdicts(['final', 'error']);
$verdicts[''] = 'JE'; /* happens for aborted judgings */

$used = [];
Expand Down Expand Up @@ -449,7 +449,7 @@ public function finishAction(

if ($request->isXmlHttpRequest()) {
$progressReporter = function (int $progress, string $log, ?string $message = null) {
echo $this->dj->jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => htmlspecialchars($message ?? '')]);
echo Utils::jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'message' => htmlspecialchars($message ?? '')]);
ob_flush();
flush();
};
Expand Down Expand Up @@ -537,7 +537,7 @@ public function addAction(Request $request, FormFactoryInterface $formFactory):
}
if ($isCreateRejudgingAjax) {
$progressReporter = function (int $progress, string $log, ?string $redirect = null) {
echo $this->dj->jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'redirect' => $redirect]);
echo Utils::jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'redirect' => $redirect]);
ob_flush();
flush();
};
Expand Down Expand Up @@ -722,7 +722,7 @@ public function createAction(Request $request): Response
}

$progressReporter = function (int $progress, string $log, ?string $redirect = null) {
echo $this->dj->jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'redirect' => $redirect]);
echo Utils::jsonEncode(['progress' => $progress, 'log' => htmlspecialchars($log), 'redirect' => $redirect]);
ob_flush();
flush();
};
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/ShadowDifferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function indexAction(
$this->requestStack->getSession()->save();

$contest = $this->dj->getCurrentContest();
$verdicts = $this->dj->getVerdicts(['final', 'error', 'external', 'in_progress']);
$verdicts = $this->config->getVerdicts(['final', 'error', 'external', 'in_progress']);

$used = [];
$verdictTable = [];
Expand Down
16 changes: 8 additions & 8 deletions webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public function indexAction(
}

// Load preselected filters
$filters = $this->dj->jsonDecode((string)$this->dj->getCookie('domjudge_submissionsfilter') ?: '[]');
$filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_submissionsfilter') ?: '[]');

$results = array_keys($this->dj->getVerdicts(['final', 'in_progress']));
$results = array_keys($this->config->getVerdicts(['final', 'in_progress']));

$data = [
'refresh' => $refresh,
Expand Down Expand Up @@ -257,7 +257,7 @@ public function viewAction(
->getQuery()
->getResult();
$timelimits = array_map(function (JudgeTask $task) {
return $this->dj->jsonDecode($task->getRunConfig())['time_limit'];
return Utils::jsonDecode($task->getRunConfig())['time_limit'];
}, $judgeTasks);
}

Expand Down Expand Up @@ -397,7 +397,7 @@ public function viewAction(
$runs[] = $runResult[0];
unset($runResult[0]);
if (!empty($runResult['metadata'])) {
$metadata = $this->dj->parseMetadata($runResult['metadata']);
$metadata = Utils::parseMetadata($runResult['metadata']);
$runResult['output_limit'] = $metadata['output-truncated'] ?? 'n/a';
}
$runResult['terminated'] = preg_match('/timelimit exceeded.*hard (wall|cpu) time/',
Expand Down Expand Up @@ -626,7 +626,7 @@ public function requestFullDebug(Request $request, Judging $jid): RedirectRespon
->setJobId($jid->getJudgingid())
->setUuid($jid->getUuid())
->setRunScriptId($executable->getImmutableExecId())
->setRunConfig($this->dj->jsonEncode(['hash' => $executable->getHash()]));
->setRunConfig(Utils::jsonEncode(['hash' => $executable->getHash()]));
$this->em->persist($judgeTask);
}
$this->em->flush();
Expand Down Expand Up @@ -1257,8 +1257,8 @@ public function createJudgeTasks(string $submitId): RedirectResponse
*/
private function maybeGetErrors(string $type, string $expectedConfigString, string $observedConfigString, array &$allErrors): void
{
$expectedConfig = $this->dj->jsonDecode($expectedConfigString);
$observedConfig = $this->dj->jsonDecode($observedConfigString);
$expectedConfig = Utils::jsonDecode($expectedConfigString);
$observedConfig = Utils::jsonDecode($observedConfigString);
$errors = [];
foreach (array_keys($expectedConfig) as $k) {
if (!array_key_exists($k, $observedConfig)) {
Expand All @@ -1271,7 +1271,7 @@ private function maybeGetErrors(string $type, string $expectedConfigString, stri
// Silently ignore.
} else {
$errors[] = '- ' . preg_replace('/_/', ' ', $k) . ': '
. $this->dj->jsonEncode($observedConfig[$k]) . ' → ' . $this->dj->jsonEncode($expectedConfig[$k]);
. Utils::jsonEncode($observedConfig[$k]) . ' → ' . Utils::jsonEncode($expectedConfig[$k]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Form/Type/RejudgingType.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->orderBy('j.hostname'),
]);

$verdicts = array_keys($this->dj->getVerdicts());
$verdicts = array_keys($this->config->getVerdicts());
$builder->add('verdicts', ChoiceType::class, [
'label' => 'Verdict',
'multiple' => true,
Expand Down
11 changes: 7 additions & 4 deletions webapp/src/Form/Type/SubmissionsFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Entity\Team;
use App\Entity\TeamAffiliation;
use App\Entity\TeamCategory;
use App\Service\ConfigurationService;
use App\Service\DOMJudgeService;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
Expand All @@ -18,9 +19,11 @@

class SubmissionsFilterType extends AbstractType
{
public function __construct(protected readonly DOMJudgeService $dj, protected readonly EntityManagerInterface $em)
{
}
public function __construct(
protected readonly ConfigurationService $config,
protected readonly DOMJudgeService $dj,
protected readonly EntityManagerInterface $em,
) {}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
Expand Down Expand Up @@ -115,7 +118,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
"attr" => ["data-filter-field" => "team-id"],
]);

$verdicts = array_keys($this->dj->getVerdicts(['final', 'error', 'in_progress']));
$verdicts = array_keys($this->config->getVerdicts(['final', 'error', 'in_progress']));
$builder->add("result", ChoiceType::class, [
"label" => "Filter on result(s)",
"multiple" => true,
Expand Down
Loading
Loading