Skip to content

Commit 03d3d18

Browse files
author
epriestley
committedMay 26, 2022
Update Slowvote voting methods to use sensible string constants
Summary: Ref T13682. Use API-friendly string constants instead of opaque integers in Slowvote voting methods. Test Plan: Created, edited, and voted in polls with various voting methods. Examined database after migrations. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13682 Differential Revision: https://secure.phabricator.com/D21846
1 parent 9dad494 commit 03d3d18

File tree

6 files changed

+16
-5
lines changed

6 files changed

+16
-5
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll
2+
CHANGE method method VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
2+
SET method = 'plurality' WHERE method = '0';
3+
4+
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
5+
SET method = 'approval' WHERE method = '1';

‎src/applications/slowvote/constants/SlowvotePollVotingMethod.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
final class SlowvotePollVotingMethod
44
extends Phobject {
55

6-
const METHOD_PLURALITY = 0;
7-
const METHOD_APPROVAL = 1;
6+
const METHOD_PLURALITY = 'plurality';
7+
const METHOD_APPROVAL = 'approval';
88

99
private $key;
1010

‎src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function handleRequest(AphrontRequest $request) {
5757
$v_space = $request->getStr('spacePHID');
5858

5959
if ($is_new) {
60-
$poll->setMethod($request->getInt('method'));
60+
$poll->setMethod($request->getStr('method'));
6161
}
6262

6363
if (!strlen($v_question)) {

‎src/applications/slowvote/storage/PhabricatorSlowvotePoll.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function getConfiguration() {
5454
'question' => 'text255',
5555
'responseVisibility' => 'text32',
5656
'shuffle' => 'bool',
57-
'method' => 'uint32',
57+
'method' => 'text32',
5858
'description' => 'text',
5959
'isClosed' => 'bool',
6060
),

‎src/applications/slowvote/view/SlowvoteEmbedView.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,17 @@ private function renderStatus(PhabricatorSlowvoteOption $option) {
301301

302302
$percent = sprintf('%d%%', $count ? 100 * $choices / $count : 0);
303303

304-
switch ($poll->getMethod()) {
304+
$method = $poll->getMethod();
305+
switch ($method) {
305306
case SlowvotePollVotingMethod::METHOD_PLURALITY:
306307
$status = pht('%s (%d / %d)', $percent, $choices, $count);
307308
break;
308309
case SlowvotePollVotingMethod::METHOD_APPROVAL:
309310
$status = pht('%s Approval (%d / %d)', $percent, $choices, $count);
310311
break;
312+
default:
313+
$status = pht('Unknown ("%s")', $method);
314+
break;
311315
}
312316

313317
return phutil_tag(

0 commit comments

Comments
 (0)
Failed to load comments.