Skip to content

Commit 6de89bc

Browse files
committed
Enabling partial assignment sync from the exercise.
1 parent 07da7f3 commit 6de89bc

File tree

3 files changed

+88
-42
lines changed

3 files changed

+88
-42
lines changed

app/V1Module/presenters/AssignmentsPresenter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,17 @@ public function checkSyncWithExercise(string $id)
645645
* @throws NotFoundException
646646
*/
647647
#[Path("id", new VUuid(), "Identifier of the assignment that should be synchronized", required: true)]
648+
#[Post("syncOptions", new VArray(new VString(
649+
1,
650+
32,
651+
'/^(configurationType|exerciseConfig|exerciseEnvironmentConfigs|exerciseTests|files|fileLinks|hardwareGroups'
652+
. '|limits|localizedTexts|mergeJudgeLogs|runtimeEnvironments|scoreConfig)$/'
653+
)), "List of options what to synchronize (if missing, everything is synchronized)", required: false)]
648654
public function actionSyncWithExercise($id)
649655
{
650656
$assignment = $this->assignments->findOrThrow($id);
651657
$exercise = $assignment->getExercise();
658+
$syncOptions = $this->getRequest()->getPost("syncOptions") ?? [];
652659

653660
if ($exercise === null) {
654661
throw new NotFoundException("Exercise for assignment '{$id}' was deleted");
@@ -661,7 +668,7 @@ public function actionSyncWithExercise($id)
661668
}
662669

663670
$assignment->updatedNow();
664-
$assignment->syncWithExercise();
671+
$assignment->syncWithExercise($syncOptions);
665672
$this->assignments->flush();
666673
$this->sendSuccessResponse($this->assignmentViewFactory->getAssignment($assignment));
667674
}

app/model/entity/Assignment.php

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\Common\Collections\Criteria;
1313
use Gedmo\Mapping\Annotation as Gedmo;
1414
use DateTime;
15+
use InvalidArgumentException;
1516

1617
/**
1718
* @ORM\Entity
@@ -535,64 +536,110 @@ function ($key, RuntimeEnvironment $env) use ($exercise) {
535536
);
536537
}
537538

538-
public function syncWithExercise()
539+
public function syncWithExercise(array $options = []): void
539540
{
540541
$exercise = $this->getExercise();
541542
if ($exercise === null) {
542543
// cannot sync exercise was deleted
543544
return;
544545
}
545546

546-
$this->mergeJudgeLogs = $exercise->getMergeJudgeLogs();
547+
// figure out which parts to sync (all are synced if no options are given)
548+
$syncOptions = [
549+
"configurationType" => !$options,
550+
"exerciseConfig" => !$options,
551+
"exerciseEnvironmentConfigs" => !$options,
552+
"exerciseTests" => !$options,
553+
"files" => !$options,
554+
"fileLinks" => !$options,
555+
"hardwareGroups" => !$options,
556+
"limits" => !$options,
557+
"localizedTexts" => !$options,
558+
"mergeJudgeLogs" => !$options,
559+
"runtimeEnvironments" => !$options,
560+
"scoreConfig" => !$options,
561+
];
562+
563+
foreach ($options as $option) {
564+
if (!array_key_exists($option, $syncOptions)) {
565+
throw new InvalidArgumentException("Unknown sync option: $option");
566+
}
567+
$syncOptions[$option] = true;
568+
}
547569

548-
$this->hardwareGroups->clear();
549-
foreach ($exercise->getHardwareGroups() as $group) {
550-
$this->hardwareGroups->add($group);
570+
$syncOptions = (object)$syncOptions;
571+
572+
if ($syncOptions->configurationType) {
573+
$this->configurationType = $exercise->getConfigurationType();
551574
}
552575

553-
$this->localizedTexts->clear();
554-
foreach ($exercise->getLocalizedTexts() as $text) {
555-
$this->localizedTexts->add($text);
576+
if ($syncOptions->exerciseConfig) {
577+
$this->exerciseConfig = $exercise->getExerciseConfig();
556578
}
557579

558-
$this->exerciseConfig = $exercise->getExerciseConfig();
559-
$this->configurationType = $exercise->getConfigurationType();
560-
$this->scoreConfig = $exercise->getScoreConfig();
580+
if ($syncOptions->exerciseEnvironmentConfigs) {
581+
$this->exerciseEnvironmentConfigs->clear();
582+
foreach ($exercise->getExerciseEnvironmentConfigs() as $config) {
583+
$this->exerciseEnvironmentConfigs->add($config);
584+
}
585+
}
561586

562-
$this->exerciseEnvironmentConfigs->clear();
563-
foreach ($exercise->getExerciseEnvironmentConfigs() as $config) {
564-
$this->exerciseEnvironmentConfigs->add($config);
587+
if ($syncOptions->exerciseTests) {
588+
$this->exerciseTests->clear();
589+
foreach ($exercise->getExerciseTests() as $test) {
590+
$this->exerciseTests->add($test);
591+
}
565592
}
566593

567-
$this->exerciseLimits->clear();
568-
foreach ($exercise->getExerciseLimits() as $limits) {
569-
$this->exerciseLimits->add($limits);
594+
if ($syncOptions->files) {
595+
$this->exerciseFiles->clear();
596+
foreach ($exercise->getExerciseFiles() as $file) {
597+
$this->exerciseFiles->add($file);
598+
}
570599
}
571600

572-
$this->exerciseTests->clear();
573-
foreach ($exercise->getExerciseTests() as $test) {
574-
$this->exerciseTests->add($test);
601+
if ($syncOptions->fileLinks) {
602+
$this->fileLinks->clear();
603+
foreach ($exercise->getFileLinks() as $link) {
604+
$newLink = ExerciseFileLink::copyForAssignment($link, $this);
605+
$this->fileLinks->add($newLink);
606+
}
575607
}
576608

577-
$this->exerciseFiles->clear();
578-
foreach ($exercise->getExerciseFiles() as $file) {
579-
$this->exerciseFiles->add($file);
609+
if ($syncOptions->hardwareGroups) {
610+
$this->hardwareGroups->clear();
611+
foreach ($exercise->getHardwareGroups() as $group) {
612+
$this->hardwareGroups->add($group);
613+
}
580614
}
581615

582-
$this->attachmentFiles->clear();
583-
foreach ($exercise->getAttachmentFiles() as $file) {
584-
$this->attachmentFiles->add($file);
616+
if ($syncOptions->limits) {
617+
$this->exerciseLimits->clear();
618+
foreach ($exercise->getExerciseLimits() as $limits) {
619+
$this->exerciseLimits->add($limits);
620+
}
585621
}
586622

587-
$this->fileLinks->clear();
588-
foreach ($exercise->getFileLinks() as $link) {
589-
$newLink = ExerciseFileLink::copyForAssignment($link, $this);
590-
$this->fileLinks->add($newLink);
623+
if ($syncOptions->localizedTexts) {
624+
$this->localizedTexts->clear();
625+
foreach ($exercise->getLocalizedTexts() as $text) {
626+
$this->localizedTexts->add($text);
627+
}
628+
}
629+
630+
if ($syncOptions->mergeJudgeLogs) {
631+
$this->mergeJudgeLogs = $exercise->getMergeJudgeLogs();
632+
}
633+
634+
if ($syncOptions->runtimeEnvironments) {
635+
$this->runtimeEnvironments->clear();
636+
foreach ($exercise->getRuntimeEnvironments() as $env) {
637+
$this->runtimeEnvironments->add($env);
638+
}
591639
}
592640

593-
$this->runtimeEnvironments->clear();
594-
foreach ($exercise->getRuntimeEnvironments() as $env) {
595-
$this->runtimeEnvironments->add($env);
641+
if ($syncOptions->scoreConfig) {
642+
$this->scoreConfig = $exercise->getScoreConfig();
596643
}
597644

598645
$this->syncedAt = new DateTime();

app/model/view/AssignmentViewFactory.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ function (LocalizedExercise $text) use ($assignment) {
117117
"mergeJudgeLogs" => [
118118
"upToDate" => $exercise && $assignment->getMergeJudgeLogs() === $exercise->getMergeJudgeLogs(),
119119
],
120-
121-
// DEPRECATED fields (will be removed in future)
122-
"supplementaryFiles" => [
123-
"upToDate" => $assignment->areExerciseFilesInSync()
124-
],
125-
"attachmentFiles" => [
126-
"upToDate" => $assignment->areAttachmentFilesInSync()
127-
],
128120
],
129121
"solutionFilesLimit" => $assignment->getSolutionFilesLimit(),
130122
"solutionSizeLimit" => $assignment->getSolutionSizeLimit(),

0 commit comments

Comments
 (0)