fix: address CodeRabbit review findings

- Use FlashType enum in clearQuiz/finalizeQuiz/unfinalizeQuiz (was raw 'success'/'error' strings)
- Catch UniqueConstraintViolationException in addLabel to handle concurrent duplicate inserts
- Wrap assignToQuiz in a transaction with PESSIMISTIC_WRITE lock to serialise concurrent assignments of the same BankQuestion
This commit is contained in:
2026-07-04 22:07:13 +02:00
parent 8304d8680b
commit 5d51885c82
3 changed files with 39 additions and 28 deletions
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tvdt\Controller\Backoffice;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -215,9 +216,13 @@ class QuestionBankController extends AbstractController
$exists = $season->questionLabels->exists(static fn (int $key, QuestionLabel $label): bool => $label->name === $name);
if (!$exists) {
$season->addQuestionLabel(new QuestionLabel($name));
$this->em->flush();
$this->addFlash(FlashType::Success, $this->translator->trans('Label added'));
try {
$season->addQuestionLabel(new QuestionLabel($name));
$this->em->flush();
$this->addFlash(FlashType::Success, $this->translator->trans('Label added'));
} catch (UniqueConstraintViolationException) {
// Concurrent request already inserted the same label; treat as a no-op
}
}
return $this->redirectToRoute('tvdt_backoffice_question_bank', ['seasonCode' => $season->seasonCode]);