Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15452802
D20125.id48044.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D20125.id48044.diff
View Options
diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
--- a/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
+++ b/src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
@@ -37,6 +37,19 @@
$method = $poll->getMethod();
$is_plurality = ($method == PhabricatorSlowvotePoll::METHOD_PLURALITY);
+ if (!$votes) {
+ if ($is_plurality) {
+ $message = pht('You must vote for something.');
+ } else {
+ $message = pht('You must vote for at least one option.');
+ }
+
+ return $this->newDialog()
+ ->setTitle(pht('Stand For Something'))
+ ->appendParagraph($message)
+ ->addCancelButton($poll->getURI());
+ }
+
if ($is_plurality && count($votes) > 1) {
throw new Exception(
pht('In this poll, you may only vote for one option.'));
@@ -52,23 +65,39 @@
}
}
- foreach ($old_votes as $old_vote) {
- if (!idx($votes, $old_vote->getOptionID(), false)) {
+ $poll->openTransaction();
+ $poll->beginReadLocking();
+
+ $poll->reload();
+
+ $old_votes = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
+ 'pollID = %d AND authorPHID = %s',
+ $poll->getID(),
+ $viewer->getPHID());
+ $old_votes = mpull($old_votes, null, 'getOptionID');
+
+ foreach ($old_votes as $old_vote) {
+ if (idx($votes, $old_vote->getOptionID())) {
+ continue;
+ }
+
$old_vote->delete();
}
- }
- foreach ($votes as $vote) {
- if (idx($old_votes, $vote, false)) {
- continue;
+ foreach ($votes as $vote) {
+ if (idx($old_votes, $vote)) {
+ continue;
+ }
+
+ id(new PhabricatorSlowvoteChoice())
+ ->setAuthorPHID($viewer->getPHID())
+ ->setPollID($poll->getID())
+ ->setOptionID($vote)
+ ->save();
}
- id(new PhabricatorSlowvoteChoice())
- ->setAuthorPHID($viewer->getPHID())
- ->setPollID($poll->getID())
- ->setOptionID($vote)
- ->save();
- }
+ $poll->endReadLocking();
+ $poll->saveTransaction();
return id(new AphrontRedirectResponse())
->setURI($poll->getURI());
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 30, 7:22 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7726812
Default Alt Text
D20125.id48044.diff (2 KB)
Attached To
Mode
D20125: Fix two very, very minor correctness issues in Slowvote
Attached
Detach File
Event Timeline
Log In to Comment