From 03d3d1889d60939704bdeea0cacf9e33d3616546 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 26 May 2022 10:19:50 -0700 Subject: [PATCH] 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 --- .../sql/autopatches/20220525.slowvote.06.method-type.sql | 2 ++ .../sql/autopatches/20220525.slowvote.07.method-value.sql | 5 +++++ .../slowvote/constants/SlowvotePollVotingMethod.php | 4 ++-- .../controller/PhabricatorSlowvoteEditController.php | 2 +- .../slowvote/storage/PhabricatorSlowvotePoll.php | 2 +- src/applications/slowvote/view/SlowvoteEmbedView.php | 6 +++++- 6 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 resources/sql/autopatches/20220525.slowvote.06.method-type.sql create mode 100644 resources/sql/autopatches/20220525.slowvote.07.method-value.sql diff --git a/resources/sql/autopatches/20220525.slowvote.06.method-type.sql b/resources/sql/autopatches/20220525.slowvote.06.method-type.sql new file mode 100644 index 0000000000..e2af0643bc --- /dev/null +++ b/resources/sql/autopatches/20220525.slowvote.06.method-type.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll + CHANGE method method VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT}; diff --git a/resources/sql/autopatches/20220525.slowvote.07.method-value.sql b/resources/sql/autopatches/20220525.slowvote.07.method-value.sql new file mode 100644 index 0000000000..04d0f6f430 --- /dev/null +++ b/resources/sql/autopatches/20220525.slowvote.07.method-value.sql @@ -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'; diff --git a/src/applications/slowvote/constants/SlowvotePollVotingMethod.php b/src/applications/slowvote/constants/SlowvotePollVotingMethod.php index 5707cd257f..f0f18641e3 100644 --- a/src/applications/slowvote/constants/SlowvotePollVotingMethod.php +++ b/src/applications/slowvote/constants/SlowvotePollVotingMethod.php @@ -3,8 +3,8 @@ final class SlowvotePollVotingMethod extends Phobject { - const METHOD_PLURALITY = 0; - const METHOD_APPROVAL = 1; + const METHOD_PLURALITY = 'plurality'; + const METHOD_APPROVAL = 'approval'; private $key; diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php index 3cafb03a41..48639ffde6 100644 --- a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php @@ -57,7 +57,7 @@ final class PhabricatorSlowvoteEditController $v_space = $request->getStr('spacePHID'); if ($is_new) { - $poll->setMethod($request->getInt('method')); + $poll->setMethod($request->getStr('method')); } if (!strlen($v_question)) { diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php index 419605e2d8..7c44f5ea4d 100644 --- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php +++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php @@ -54,7 +54,7 @@ final class PhabricatorSlowvotePoll 'question' => 'text255', 'responseVisibility' => 'text32', 'shuffle' => 'bool', - 'method' => 'uint32', + 'method' => 'text32', 'description' => 'text', 'isClosed' => 'bool', ), diff --git a/src/applications/slowvote/view/SlowvoteEmbedView.php b/src/applications/slowvote/view/SlowvoteEmbedView.php index eaf1d2cc93..fcc0ae9d28 100644 --- a/src/applications/slowvote/view/SlowvoteEmbedView.php +++ b/src/applications/slowvote/view/SlowvoteEmbedView.php @@ -301,13 +301,17 @@ final class SlowvoteEmbedView extends AphrontView { $percent = sprintf('%d%%', $count ? 100 * $choices / $count : 0); - switch ($poll->getMethod()) { + $method = $poll->getMethod(); + switch ($method) { case SlowvotePollVotingMethod::METHOD_PLURALITY: $status = pht('%s (%d / %d)', $percent, $choices, $count); break; case SlowvotePollVotingMethod::METHOD_APPROVAL: $status = pht('%s Approval (%d / %d)', $percent, $choices, $count); break; + default: + $status = pht('Unknown ("%s")', $method); + break; } return phutil_tag(