Skip to content
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
18 changes: 6 additions & 12 deletions app/V1Module/presenters/AssignmentsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@
namespace App\V1Module\Presenters;

use App\Exceptions\BadRequestException;
use App\Exceptions\ExerciseConfigException;
use App\Exceptions\ForbiddenRequestException;
use App\Exceptions\InvalidArgumentException;
use App\Exceptions\InvalidStateException;

use App\Helpers\EvaluationPointsLoader;
use App\Helpers\Localizations;
use App\Helpers\Notifications\AssignmentEmailsSender;
use App\Model\Entity\Exercise;
use App\Model\Entity\Group;
use App\Model\Entity\AssignmentSolution;
use App\Model\Entity\Assignment;
use App\Model\Entity\LocalizedExercise;

use App\Helpers\ExerciseConfig\Loader as ExerciseConfigLoader;
use App\Helpers\ScoreCalculatorAccessor;

use App\Model\Repository\Assignments;
use App\Model\Repository\Exercises;
use App\Model\Repository\Groups;
use App\Model\Repository\SolutionEvaluations;
use App\Model\Repository\AssignmentSolutions;

use App\Security\ACL\IAssignmentPermissions;
use App\Security\ACL\IGroupPermissions;
use App\Security\ACL\IAssignmentSolutionPermissions;
Expand Down Expand Up @@ -113,6 +106,7 @@ class AssignmentsPresenter extends BasePresenter {
/**
* Get a list of all assignments
* @GET
* @throws ForbiddenRequestException
*/
public function actionDefault() {
if (!$this->assignmentAcl->canViewAll()) {
Expand All @@ -131,8 +125,6 @@ public function actionDefault() {
*/
public function actionDetail(string $id) {
$assignment = $this->assignments->findOrThrow($id);
$user = $this->getCurrentUser();

if (!$this->assignmentAcl->canViewDetail($assignment)) {
throw new ForbiddenRequestException("You cannot view this assignment.");
}
Expand Down Expand Up @@ -194,7 +186,7 @@ public function actionUpdateDetail(string $id) {
$secondDeadlineTimestamp = $req->getPost("secondDeadline") ?: 0;

$assignment->incrementVersion();
$assignment->setUpdatedAt(new \DateTime);
$assignment->updatedNow();
$assignment->setIsPublic($isPublic);
$assignment->setFirstDeadline(DateTime::createFromFormat('U', $firstDeadlineTimestamp));
$assignment->setSecondDeadline(DateTime::createFromFormat('U', $secondDeadlineTimestamp));
Expand Down Expand Up @@ -285,6 +277,9 @@ public function actionValidate($id) {
* @POST
* @Param(type="post", name="exerciseId", description="Identifier of the exercise")
* @Param(type="post", name="groupId", description="Identifier of the group")
* @throws ForbiddenRequestException
* @throws BadRequestException
* @throws InvalidStateException
*/
public function actionCreate() {
$req = $this->getRequest();
Expand Down Expand Up @@ -341,15 +336,14 @@ public function actionRemove(string $id) {
* @param string $id Identifier of the exercise that should be synchronized
* @POST
* @throws ForbiddenRequestException
* @throws BadRequestException
*/
public function actionSyncWithExercise($id) {
$assignment = $this->assignments->findOrThrow($id);

if (!$this->assignmentAcl->canUpdate($assignment)) {
throw new ForbiddenRequestException("You cannot sync this assignment.");
}

$assignment->updatedNow();
$assignment->syncWithExercise();
$this->assignments->flush();
$this->sendSuccessResponse($assignment);
Expand Down
17 changes: 13 additions & 4 deletions app/V1Module/presenters/ExercisesConfigPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public function actionUpdateEnvironmentConfigs(string $id) {
}

// make changes and updates to database entity
$exercise->updatedNow();
$exercise->setRuntimeEnvironments($runtimeEnvironments);
$this->exercises->replaceEnvironmentConfigs($exercise, $configs, false);
$this->exerciseConfigUpdater->environmentsUpdated($exercise, $this->getCurrentUser(), false);
Expand Down Expand Up @@ -272,6 +273,7 @@ public function actionSetConfiguration(string $id) {
$newConfig = new ExerciseConfig((string) $exerciseConfig, $this->getCurrentUser(), $oldConfig);

// set new exercise configuration into exercise and flush changes
$exercise->updatedNow();
$exercise->setExerciseConfig($newConfig);
$this->exercises->flush();

Expand Down Expand Up @@ -399,6 +401,8 @@ public function actionSetLimits(string $id, string $runtimeEnvironmentId) {
$exercise->addHardwareGroup($hwGroup);
}

// update and return
$exercise->updatedNow();
$this->exercises->flush();
$this->sendSuccessResponse($exerciseLimits->toArray());
}
Expand Down Expand Up @@ -482,8 +486,10 @@ public function actionSetHardwareGroupLimits(string $id, string $runtimeEnvironm
$exercise->addExerciseLimits($newLimits);
$exercise->removeHardwareGroup($hwGroup); // if there was one before
$exercise->addHardwareGroup($hwGroup);
$this->exercises->flush();

// update and return
$exercise->updatedNow();
$this->exercises->flush();
$this->sendSuccessResponse($newLimits->getParsedLimits());
}

Expand Down Expand Up @@ -515,8 +521,9 @@ public function actionRemoveHardwareGroupLimits(string $id, string $runtimeEnvir
// make changes persistent
$exercise->removeExerciseLimits($limits);
$exercise->removeHardwareGroup($hwGroup);
$this->exercises->flush();

$exercise->updatedNow();
$this->exercises->flush();
$this->sendSuccessResponse("OK");
}

Expand Down Expand Up @@ -559,6 +566,7 @@ public function actionSetScoreConfig(string $id) {
throw new ExerciseConfigException("Exercise score configuration is not valid");
}

$exercise->updatedNow();
$exercise->setScoreConfig($config);
$this->exercises->flush();
$this->sendSuccessResponse($exercise->getScoreConfig());
Expand Down Expand Up @@ -620,7 +628,7 @@ public function actionSetTests(string $id) {
// update of existing exercise test with all appropriate fields
$testEntity->setName(trim($name));
$testEntity->setDescription($description);
$testEntity->setUpdatedAt(new DateTime);
$testEntity->updatedNow();
}


Expand All @@ -644,8 +652,9 @@ public function actionSetTests(string $id) {

// update exercise configuration and test in here
$this->exerciseConfigUpdater->testsUpdated($exercise, $this->getCurrentUser(), false);
$this->exercises->flush();

$exercise->updatedNow();
$this->exercises->flush();
$this->sendSuccessResponse($exercise->getExerciseTests()->getValues());
}

Expand Down
3 changes: 2 additions & 1 deletion app/V1Module/presenters/ExercisesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function actionUpdateDetail(string $id) {
// make changes to newly created exercise
$exercise->setDifficulty($difficulty);
$exercise->setIsPublic($isPublic);
$exercise->setUpdatedAt(new \DateTime);
$exercise->updatedNow();
$exercise->incrementVersion();
$exercise->setLocked($isLocked);

Expand Down Expand Up @@ -240,6 +240,7 @@ public function actionGetPipelines(string $id) {
* Exercise detail can be then changed in appropriate endpoint.
* @POST
* @Param(type="post", name="groupId", required=FALSE, description="Identifier of the group to which exercise belongs to")
* @throws ForbiddenRequestException
*/
public function actionCreate() {
$user = $this->getCurrentUser();
Expand Down
2 changes: 1 addition & 1 deletion app/V1Module/presenters/PipelinesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function actionUpdatePipeline(string $id) {
$description = $req->getPost("description");
$pipeline->setName($name);
$pipeline->setDescription($description);
$pipeline->setUpdatedAt(new \DateTime);
$pipeline->updatedNow();
$pipeline->incrementVersion();

// get new configuration from parameters, parse it and check for format errors
Expand Down
16 changes: 3 additions & 13 deletions app/model/entity/Assignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*
* @method string getId()
* @method DateTime getDeletedAt()
* @method Collection getRuntimeEnvironments()
* @method int getPointsPercentualThreshold()
* @method int getSubmissionsCountLimit()
Expand All @@ -37,7 +36,6 @@
* @method int getVersion()
* @method setFirstDeadline(DateTime $deadline)
* @method setSecondDeadline(DateTime $deadline)
* @method setUpdatedAt(DateTime $date)
* @method setIsPublic(bool $public)
* @method setMaxPointsBeforeFirstDeadline(int $points)
* @method setMaxPointsBeforeSecondDeadline(int $points)
Expand All @@ -51,6 +49,8 @@ class Assignment implements JsonSerializable, IExercise
{
use MagicAccessors;
use ExerciseData;
use UpdateableEntity;
use DeleteableEntity;

private function __construct(
DateTime $firstDeadline,
Expand Down Expand Up @@ -167,16 +167,6 @@ public function isPublic() {
*/
protected $createdAt;

/**
* @ORM\Column(type="datetime")
*/
protected $updatedAt;

/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $deletedAt;

/**
* @ORM\Column(type="smallint")
*/
Expand Down Expand Up @@ -362,7 +352,7 @@ function ($key, RuntimeEnvironment $env) {
"exerciseSynchronizationInfo" => [
"updatedAt" => [
"assignment" => $this->updatedAt->getTimestamp(),
"exercise" => $this->getExercise()->updatedAt->getTimestamp(),
"exercise" => $this->getExercise()->getUpdatedAt()->getTimestamp(),
],
"exerciseConfig" => [
"upToDate" => $this->getExerciseConfig() === $this->getExercise()->getExerciseConfig(),
Expand Down
15 changes: 3 additions & 12 deletions app/model/entity/Exercise.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
/**
* @ORM\Entity
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*
* @method string getId()
* @method Collection getRuntimeEnvironments()
* @method Collection getExerciseLimits()
* @method Collection getExerciseEnvironmentConfigs()
* @method \DateTime getDeletedAt()
* @method User getAuthor()
* @method int getVersion()
* @method void setScoreConfig(string $scoreConfig)
* @method void setDifficulty(string $difficulty)
* @method void setIsPublic(bool $isPublic)
* @method void setUpdatedAt(DateTime $date)
* @method void setExerciseConfig(ExerciseConfig $exerciseConfig)
* @method setConfigurationType($type)
*/
class Exercise implements JsonSerializable, IExercise
{
use \Kdyby\Doctrine\MagicAccessors\MagicAccessors;
use ExerciseData;
use UpdateableEntity;
use DeleteableEntity;

/**
* @ORM\Id
Expand All @@ -60,16 +61,6 @@ public function incrementVersion() {
*/
protected $createdAt;

/**
* @ORM\Column(type="datetime")
*/
protected $updatedAt;

/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $deletedAt;

/**
* @ORM\Column(type="string")
*/
Expand Down
7 changes: 1 addition & 6 deletions app/model/entity/ExerciseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
* @method DateTime getCreatedAt()
* @method string setName(string $name)
* @method string setDescription(string $description)
* @method void setUpdatedAt(DateTime $date)
*/
class ExerciseTest implements JsonSerializable
{
use \Kdyby\Doctrine\MagicAccessors\MagicAccessors;
use UpdateableEntity;

/**
* @ORM\Id
Expand Down Expand Up @@ -51,11 +51,6 @@ class ExerciseTest implements JsonSerializable
*/
protected $createdAt;

/**
* @ORM\Column(type="datetime")
*/
protected $updatedAt;

/**
* ExerciseTest constructor.
* @param string $name
Expand Down
7 changes: 1 addition & 6 deletions app/model/entity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*
* @method string getId()
* @method DateTime getDeletedAt()
* @method addAssignment(Assignment $assignment)
* @method addChildGroup(Group $group)
* @method string getExternalId()
Expand All @@ -32,6 +31,7 @@
class Group implements JsonSerializable
{
use \Kdyby\Doctrine\MagicAccessors\MagicAccessors;
use DeleteableEntity;

public function __construct(
string $externalId,
Expand Down Expand Up @@ -109,11 +109,6 @@ public function statsArePublic(): bool {
return $this->publicStats;
}

/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $deletedAt;

/**
* @ORM\ManyToOne(targetEntity="Group", inversedBy="childGroups")
*/
Expand Down
12 changes: 2 additions & 10 deletions app/model/entity/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
class Instance implements JsonSerializable
{
use MagicAccessors;
use UpdateableEntity;
use DeleteableEntity;

/**
* @ORM\Id
Expand All @@ -44,16 +46,6 @@ class Instance implements JsonSerializable
*/
protected $createdAt;

/**
* @ORM\Column(type="datetime")
*/
protected $updatedAt;

/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $deletedAt;

/**
* @ORM\ManyToOne(targetEntity="User")
*/
Expand Down
Loading