avoid 409 error by same vote answer as already stored

Signed-off-by: dartcafe <github@dartcafe.de>
This commit is contained in:
dartcafe 2024-08-31 10:31:11 +02:00
Родитель 54334fe4e7
Коммит 2c9a0df448
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CCE73CEF3035D3C8
1 изменённых файлов: 11 добавлений и 6 удалений

Просмотреть файл

@ -72,16 +72,21 @@ class VoteService {
$option = $this->optionMapper->find($optionId);
$poll = $this->pollMapper->find($option->getPollId());
$poll->request(Poll::PERMISSION_VOTE_EDIT);
if ($setTo === Vote::VOTE_YES) {
$this->checkLimits($option);
}
// delete no votes, if poll setting is set to useNo === 0
$deleteVoteInsteadOfNoVote = in_array(trim($setTo), [Vote::VOTE_NO, '']) && !boolval($poll->getUseNo());
try {
$this->vote = $this->voteMapper->findSingleVote($poll->getId(), $option->getPollOptionText(), $this->acl->getCurrentUserId());
if ($setTo === $this->vote->getVoteAnswer()) {
return $this->vote;
}
if ($setTo === Vote::VOTE_YES) {
$this->checkLimits($option);
}
// delete no votes, if poll setting is set to useNo === 0
$deleteVoteInsteadOfNoVote = in_array(trim($setTo), [Vote::VOTE_NO, '']) && !boolval($poll->getUseNo());
if ($deleteVoteInsteadOfNoVote) {
$this->vote->setVoteAnswer('');
$this->voteMapper->delete($this->vote);