@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+16 -5
+2
resources/sql/autopatches/20220525.slowvote.06.method-type.sql
··· 1 + ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll 2 + CHANGE method method VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
+5
resources/sql/autopatches/20220525.slowvote.07.method-value.sql
··· 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';
+2 -2
src/applications/slowvote/constants/SlowvotePollVotingMethod.php
··· 3 3 final class SlowvotePollVotingMethod 4 4 extends Phobject { 5 5 6 - const METHOD_PLURALITY = 0; 7 - const METHOD_APPROVAL = 1; 6 + const METHOD_PLURALITY = 'plurality'; 7 + const METHOD_APPROVAL = 'approval'; 8 8 9 9 private $key; 10 10
+1 -1
src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
··· 57 57 $v_space = $request->getStr('spacePHID'); 58 58 59 59 if ($is_new) { 60 - $poll->setMethod($request->getInt('method')); 60 + $poll->setMethod($request->getStr('method')); 61 61 } 62 62 63 63 if (!strlen($v_question)) {
+1 -1
src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
··· 54 54 'question' => 'text255', 55 55 'responseVisibility' => 'text32', 56 56 'shuffle' => 'bool', 57 - 'method' => 'uint32', 57 + 'method' => 'text32', 58 58 'description' => 'text', 59 59 'isClosed' => 'bool', 60 60 ),
+5 -1
src/applications/slowvote/view/SlowvoteEmbedView.php
··· 301 301 302 302 $percent = sprintf('%d%%', $count ? 100 * $choices / $count : 0); 303 303 304 - switch ($poll->getMethod()) { 304 + $method = $poll->getMethod(); 305 + switch ($method) { 305 306 case SlowvotePollVotingMethod::METHOD_PLURALITY: 306 307 $status = pht('%s (%d / %d)', $percent, $choices, $count); 307 308 break; 308 309 case SlowvotePollVotingMethod::METHOD_APPROVAL: 309 310 $status = pht('%s Approval (%d / %d)', $percent, $choices, $count); 311 + break; 312 + default: 313 + $status = pht('Unknown ("%s")', $method); 310 314 break; 311 315 } 312 316