@@ -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 ([
0 commit comments