Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting external contest source with contest.yaml #2208

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
2 changes: 1 addition & 1 deletion webapp/src/Entity/ExternalContestSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getSource(): string

public function setSource(string $source): ExternalContestSource
{
if (str_ends_with($source, '/')) {
while (str_ends_with($source, '/')) {
$source = substr($source, 0, -1);
}
$this->source = $source;
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
Loading