diff --git a/doc/manual/shadow.rst b/doc/manual/shadow.rst index 5e504b8785..d5e9f0d850 100644 --- a/doc/manual/shadow.rst +++ b/doc/manual/shadow.rst @@ -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/ + 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 ------------------------------------- diff --git a/webapp/src/Service/ImportExportService.php b/webapp/src/Service/ImportExportService.php index a642bbf883..61d53337d3 100644 --- a/webapp/src/Service/ImportExportService.php +++ b/webapp/src/Service/ImportExportService.php @@ -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; @@ -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;