1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

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
This commit is contained in:
epriestley 2022-05-26 10:19:50 -07:00
parent 9dad49472c
commit 03d3d1889d
6 changed files with 16 additions and 5 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll
CHANGE method method VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};

View file

@ -0,0 +1,5 @@
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
SET method = 'plurality' WHERE method = '0';
UPDATE {$NAMESPACE}_slowvote.slowvote_poll
SET method = 'approval' WHERE method = '1';

View file

@ -3,8 +3,8 @@
final class SlowvotePollVotingMethod final class SlowvotePollVotingMethod
extends Phobject { extends Phobject {
const METHOD_PLURALITY = 0; const METHOD_PLURALITY = 'plurality';
const METHOD_APPROVAL = 1; const METHOD_APPROVAL = 'approval';
private $key; private $key;

View file

@ -57,7 +57,7 @@ final class PhabricatorSlowvoteEditController
$v_space = $request->getStr('spacePHID'); $v_space = $request->getStr('spacePHID');
if ($is_new) { if ($is_new) {
$poll->setMethod($request->getInt('method')); $poll->setMethod($request->getStr('method'));
} }
if (!strlen($v_question)) { if (!strlen($v_question)) {

View file

@ -54,7 +54,7 @@ final class PhabricatorSlowvotePoll
'question' => 'text255', 'question' => 'text255',
'responseVisibility' => 'text32', 'responseVisibility' => 'text32',
'shuffle' => 'bool', 'shuffle' => 'bool',
'method' => 'uint32', 'method' => 'text32',
'description' => 'text', 'description' => 'text',
'isClosed' => 'bool', 'isClosed' => 'bool',
), ),

View file

@ -301,13 +301,17 @@ final class SlowvoteEmbedView extends AphrontView {
$percent = sprintf('%d%%', $count ? 100 * $choices / $count : 0); $percent = sprintf('%d%%', $count ? 100 * $choices / $count : 0);
switch ($poll->getMethod()) { $method = $poll->getMethod();
switch ($method) {
case SlowvotePollVotingMethod::METHOD_PLURALITY: case SlowvotePollVotingMethod::METHOD_PLURALITY:
$status = pht('%s (%d / %d)', $percent, $choices, $count); $status = pht('%s (%d / %d)', $percent, $choices, $count);
break; break;
case SlowvotePollVotingMethod::METHOD_APPROVAL: case SlowvotePollVotingMethod::METHOD_APPROVAL:
$status = pht('%s Approval (%d / %d)', $percent, $choices, $count); $status = pht('%s Approval (%d / %d)', $percent, $choices, $count);
break; break;
default:
$status = pht('Unknown ("%s")', $method);
break;
} }
return phutil_tag( return phutil_tag(