Skip to content

Commit

Permalink
Allow setting externalContestSource for contests
Browse files Browse the repository at this point in the history
Useful for mostly us but documented in the manual. Doing this in the API
doc is non trivial for now.

Co-authored-by: Nicky Gerritsen <[email protected]>
  • Loading branch information
vmcj and nickygerritsen committed Nov 7, 2023
1 parent 254feab commit 66aedef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions doc/manual/shadow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ In the DOMjudge admin interface, go to the *External Contest Sources* page and
create an external contest source. Select the contest to import into and enter
the source you want to import from.

Another alternative is to use these DOMjudge only keys in the `contest.yaml`::

shadow:
type: contest-api
source: http(s)://url_to_external_system/api/contests/<contest_id>
username: user_in_external_system
password: password_for_user

or::

shadow:
type: contest-archive
source: /path/on/domjudge/filestem/to/clics/compliant/archive

Running the event feed import command
-------------------------------------

Expand Down
17 changes: 17 additions & 0 deletions webapp/src/Service/ImportExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\Configuration;
use App\Entity\Contest;
use App\Entity\ContestProblem;
use App\Entity\ExternalContestSource;
use App\Entity\Problem;
use App\Entity\Role;
use App\Entity\Team;
Expand Down Expand Up @@ -251,6 +252,22 @@ public function importContestData(mixed $data, ?string &$errorMessage = null, st
}

$this->em->persist($contest);

$shadow = $data['shadow'] ?? null;
if ($shadow) {
$externalSource = $this->em->getRepository(ExternalContestSource::class)->findOneBy(['contest' => $contest]) ?: new ExternalContestSource();
$externalSource->setContest($contest);
foreach ($shadow as $field => $value) {
// Overwrite the existing value if the property is defined in the data: $externalSource-setSource($data['shadow']['source'])
$fieldFunc = 'set'.ucwords($field);
$fieldArgs = [$value];
if (method_exists($externalSource, $fieldFunc)) {
$externalSource->$fieldFunc(...$fieldArgs);
}
}
$this->em->persist($externalSource);
}

$this->em->flush();

$penaltyTime = $data['penalty_time'] ?? $data['penalty-time'] ?? $data['penalty'] ?? null;
Expand Down

0 comments on commit 66aedef

Please sign in to comment.