Skip to content

Commit 69dc368

Browse files
committed
Fixing recent exceptions in assignment-solutions presenter (a situation when no best solution exists).
1 parent e1422e1 commit 69dc368

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

app/V1Module/presenters/AssignmentSolutionsPresenter.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,12 @@ public function actionSetBonusPoints(string $id)
390390
$changedSolutions[] = $this->assignmentSolutionViewFactory->getSolutionData($solution);
391391
if ($assignment) {
392392
$best = $this->assignmentSolutions->findBestSolution($assignment, $author);
393-
if ($best->getId() !== $oldBest->getId()) {
393+
if (!$best || !$oldBest || $best->getId() !== $oldBest->getId()) {
394394
// best solution has changed, we need to report this
395-
if ($best->getId() !== $id) {
395+
if ($best && $best->getId() !== $id) {
396396
$changedSolutions[] = $this->assignmentSolutionViewFactory->getSolutionData($best);
397397
}
398-
if ($oldBest->getId() !== $id) {
398+
if ($oldBest && $oldBest->getId() !== $id) {
399399
$changedSolutions[] = $this->assignmentSolutionViewFactory->getSolutionData($oldBest);
400400
}
401401
}
@@ -498,7 +498,9 @@ public function actionSetFlag(string $id, string $flag)
498498

499499
// finally flush all changed to the database
500500
$this->assignmentSolutions->flush();
501-
$this->assignmentSolutions->refresh($oldBestSolution);
501+
if ($oldBestSolution) {
502+
$this->assignmentSolutions->refresh($oldBestSolution);
503+
}
502504

503505
// send notification email
504506
$notificationMethod = $flag . 'FlagChanged';
@@ -512,7 +514,6 @@ public function actionSetFlag(string $id, string $flag)
512514
}
513515

514516
// assemble response (all entities and stats that may have changed)
515-
$assignmentId = $solution->getAssignment()->getId();
516517
$groupOfSolution = $solution->getAssignment()->getGroup();
517518
if ($groupOfSolution === null) {
518519
throw new NotFoundException("Group for assignment '$id' was not found");
@@ -528,12 +529,16 @@ public function actionSetFlag(string $id, string $flag)
528529
$solution->getAssignment(),
529530
$solution->getSolution()->getAuthor()
530531
);
531-
if ($oldBestSolution->getId() !== $bestSolution->getId()) {
532+
if (!$oldBestSolution || !$bestSolution || $oldBestSolution->getId() !== $bestSolution->getId()) {
532533
// add old and current best solutions as well (since they have changed)
533-
$resSolutions[$oldBestSolution->getId()] =
534-
$this->assignmentSolutionViewFactory->getSolutionData($oldBestSolution);
535-
$resSolutions[$bestSolution->getId()] =
536-
$this->assignmentSolutionViewFactory->getSolutionData($bestSolution);
534+
if ($oldBestSolution) {
535+
$resSolutions[$oldBestSolution->getId()] =
536+
$this->assignmentSolutionViewFactory->getSolutionData($oldBestSolution);
537+
}
538+
if ($bestSolution) {
539+
$resSolutions[$bestSolution->getId()] =
540+
$this->assignmentSolutionViewFactory->getSolutionData($bestSolution);
541+
}
537542
}
538543

539544
$this->sendSuccessResponse([

recodex-api.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
%define short_name api
33
%define install_dir /opt/%{name}
44
%define version 2.16.1
5-
%define unmangled_version 9f2e984f03086c228016bc7e420bfa23d8c7e8b9
6-
%define release 1
5+
%define unmangled_version 1e145d5253dacbe64a8ed1050883834b05a8deeb
6+
%define release 2
77

88
Summary: ReCodEx core API component
99
Name: %{name}

0 commit comments

Comments
 (0)