@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update Slowvote poll status to use sensible string constants

Summary: Ref T13682. This prepares for modernizing Slowvote and exposing a more usable API.

Test Plan: Ran migrations, opened and closed polls.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13682

Differential Revision: https://secure.phabricator.com/D21848

+119 -93
+2
resources/sql/autopatches/20220525.slowvote.08.status-type.sql
··· 1 + ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll 2 + CHANGE isClosed status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
+5
resources/sql/autopatches/20220525.slowvote.09.status-value.sql
··· 1 + UPDATE {$NAMESPACE}_slowvote.slowvote_poll 2 + SET status = 'open' WHERE status = '0'; 3 + 4 + UPDATE {$NAMESPACE}_slowvote.slowvote_poll 5 + SET status = 'closed' WHERE status = '1';
+19
resources/sql/autopatches/20220525.slowvote.10.status-xactions.sql
··· 1 + UPDATE {$NAMESPACE}_slowvote.slowvote_transaction 2 + SET transactionType = 'vote:status' 3 + WHERE transactionType = 'vote:close'; 4 + 5 + UPDATE {$NAMESPACE}_slowvote.slowvote_transaction 6 + SET oldValue = '"open"' WHERE 7 + transactionType = 'vote:status' AND oldValue IN ('0', '"0"', 'false'); 8 + 9 + UPDATE {$NAMESPACE}_slowvote.slowvote_transaction 10 + SET newValue = '"open"' WHERE 11 + transactionType = 'vote:status' AND newValue IN ('0', '"0"', 'false'); 12 + 13 + UPDATE {$NAMESPACE}_slowvote.slowvote_transaction 14 + SET oldValue = '"closed"' WHERE 15 + transactionType = 'vote:status' AND oldValue IN ('1', '"1"', 'true'); 16 + 17 + UPDATE {$NAMESPACE}_slowvote.slowvote_transaction 18 + SET newValue = '"closed"' WHERE 19 + transactionType = 'vote:status' AND newValue IN ('1', '"1"', 'true');
+2 -2
src/__phutil_library_map__.php
··· 4833 4833 'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php', 4834 4834 'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php', 4835 4835 'PhabricatorSlowvoteCloseController' => 'applications/slowvote/controller/PhabricatorSlowvoteCloseController.php', 4836 - 'PhabricatorSlowvoteCloseTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteCloseTransaction.php', 4837 4836 'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php', 4838 4837 'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php', 4839 4838 'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php', ··· 4854 4853 'PhabricatorSlowvoteSchemaSpec' => 'applications/slowvote/storage/PhabricatorSlowvoteSchemaSpec.php', 4855 4854 'PhabricatorSlowvoteSearchEngine' => 'applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php', 4856 4855 'PhabricatorSlowvoteShuffleTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteShuffleTransaction.php', 4856 + 'PhabricatorSlowvoteStatusTransaction' => 'applications/slowvote/xaction/PhabricatorSlowvoteStatusTransaction.php', 4857 4857 'PhabricatorSlowvoteTransaction' => 'applications/slowvote/storage/PhabricatorSlowvoteTransaction.php', 4858 4858 'PhabricatorSlowvoteTransactionComment' => 'applications/slowvote/storage/PhabricatorSlowvoteTransactionComment.php', 4859 4859 'PhabricatorSlowvoteTransactionQuery' => 'applications/slowvote/query/PhabricatorSlowvoteTransactionQuery.php', ··· 11539 11539 'PhabricatorSlowvoteApplication' => 'PhabricatorApplication', 11540 11540 'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO', 11541 11541 'PhabricatorSlowvoteCloseController' => 'PhabricatorSlowvoteController', 11542 - 'PhabricatorSlowvoteCloseTransaction' => 'PhabricatorSlowvoteTransactionType', 11543 11542 'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController', 11544 11543 'PhabricatorSlowvoteController' => 'PhabricatorController', 11545 11544 'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO', ··· 11571 11570 'PhabricatorSlowvoteSchemaSpec' => 'PhabricatorConfigSchemaSpec', 11572 11571 'PhabricatorSlowvoteSearchEngine' => 'PhabricatorApplicationSearchEngine', 11573 11572 'PhabricatorSlowvoteShuffleTransaction' => 'PhabricatorSlowvoteTransactionType', 11573 + 'PhabricatorSlowvoteStatusTransaction' => 'PhabricatorSlowvoteTransactionType', 11574 11574 'PhabricatorSlowvoteTransaction' => 'PhabricatorModularTransaction', 11575 11575 'PhabricatorSlowvoteTransactionComment' => 'PhabricatorApplicationTransactionComment', 11576 11576 'PhabricatorSlowvoteTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+8 -2
src/applications/slowvote/constants/SlowvotePollStatus.php
··· 3 3 final class SlowvotePollStatus 4 4 extends Phobject { 5 5 6 - const STATUS_OPEN = 0; 7 - const STATUS_CLOSED = 1; 6 + const STATUS_OPEN = 'open'; 7 + const STATUS_CLOSED = 'closed'; 8 8 9 9 private $key; 10 10 ··· 47 47 return $this->getProperty('header.tag.color'); 48 48 } 49 49 50 + public function getTransactionIcon() { 51 + return $this->getProperty('transaction.icon'); 52 + } 53 + 50 54 private function getProperty($key, $default = null) { 51 55 $spec = idx(self::getMap(), $this->getKey(), array()); 52 56 return idx($spec, $key, $default); ··· 58 62 'name' => pht('Open'), 59 63 'header.tag.icon' => 'fa-square-o', 60 64 'header.tag.color' => 'bluegrey', 65 + 'transaction.icon' => 'fa-pencil', 61 66 ), 62 67 self::STATUS_CLOSED => array( 63 68 'name' => pht('Closed'), 64 69 'header.tag.icon' => 'fa-ban', 65 70 'header.tag.color' => 'indigo', 71 + 'transaction.icon' => 'fa-ban', 66 72 ), 67 73 ); 68 74 }
+2 -2
src/applications/slowvote/controller/PhabricatorSlowvoteCloseController.php
··· 20 20 return new Aphront404Response(); 21 21 } 22 22 23 - $close_uri = '/V'.$poll->getID(); 23 + $close_uri = $poll->getURI(); 24 24 25 25 if ($request->isFormPost()) { 26 26 if ($poll->isClosed()) { ··· 33 33 34 34 $xactions[] = id(new PhabricatorSlowvoteTransaction()) 35 35 ->setTransactionType( 36 - PhabricatorSlowvoteCloseTransaction::TRANSACTIONTYPE) 36 + PhabricatorSlowvoteStatusTransaction::TRANSACTIONTYPE) 37 37 ->setNewValue($new_status); 38 38 39 39 id(new PhabricatorSlowvoteEditor())
+7 -6
src/applications/slowvote/query/PhabricatorSlowvoteQuery.php
··· 7 7 private $phids; 8 8 private $authorPHIDs; 9 9 private $withVotesByViewer; 10 - private $isClosed; 10 + private $statuses; 11 11 12 12 private $needOptions; 13 13 private $needChoices; ··· 33 33 return $this; 34 34 } 35 35 36 - public function withIsClosed($with_closed) { 37 - $this->isClosed = $with_closed; 36 + public function withStatuses(array $statuses) { 37 + $this->statuses = $statuses; 38 38 return $this; 39 39 } 40 40 ··· 137 137 $this->authorPHIDs); 138 138 } 139 139 140 - if ($this->isClosed !== null) { 140 + if ($this->statuses !== null) { 141 141 $where[] = qsprintf( 142 142 $conn, 143 - 'p.isClosed = %d', 144 - (int)$this->isClosed); 143 + 'p.status IN (%Ls)', 144 + $this->statuses); 145 145 } 146 + 146 147 return $where; 147 148 } 148 149
+8 -15
src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
··· 26 26 $query->withAuthorPHIDs($map['authorPHIDs']); 27 27 } 28 28 29 - $statuses = $map['statuses']; 30 - if (count($statuses) == 1) { 31 - $status = head($statuses); 32 - if ($status == 'open') { 33 - $query->withIsClosed(false); 34 - } else { 35 - $query->withIsClosed(true); 36 - } 29 + if ($map['statuses']) { 30 + $query->withStatuses($map['statuses']); 37 31 } 38 32 39 33 return $query; 40 34 } 41 35 42 36 protected function buildCustomSearchFields() { 37 + 38 + $status_options = SlowvotePollStatus::getAll(); 39 + $status_options = mpull($status_options, 'getName'); 43 40 44 41 return array( 45 42 id(new PhabricatorUsersSearchField()) ··· 61 58 id(new PhabricatorSearchCheckboxesField()) 62 59 ->setKey('statuses') 63 60 ->setLabel(pht('Statuses')) 64 - ->setOptions( 65 - array( 66 - 'open' => pht('Open'), 67 - 'closed' => pht('Closed'), 68 - )), 61 + ->setOptions($status_options), 69 62 ); 70 63 } 71 64 ··· 137 130 $item = id(new PHUIObjectItemView()) 138 131 ->setUser($viewer) 139 132 ->setObject($poll) 140 - ->setObjectName('V'.$poll->getID()) 133 + ->setObjectName($poll->getMonogram()) 141 134 ->setHeader($poll->getQuestion()) 142 - ->setHref('/V'.$poll->getID()) 135 + ->setHref($poll->getURI()) 143 136 ->addIcon('none', $date_created); 144 137 145 138 if ($poll->isClosed()) {
+5 -5
src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
··· 20 20 protected $shuffle = 0; 21 21 protected $method; 22 22 protected $viewPolicy; 23 - protected $isClosed; 23 + protected $status; 24 24 protected $spacePHID; 25 25 26 26 private $options = self::ATTACHABLE; ··· 43 43 ->setAuthorPHID($actor->getPHID()) 44 44 ->setViewPolicy($view_policy) 45 45 ->setSpacePHID($actor->getDefaultSpacePHID()) 46 - ->setIsClosed(SlowvotePollStatus::STATUS_OPEN) 46 + ->setStatus(SlowvotePollStatus::STATUS_OPEN) 47 47 ->setMethod($default_method) 48 48 ->setResponseVisibility($default_responses); 49 49 } ··· 57 57 'shuffle' => 'bool', 58 58 'method' => 'text32', 59 59 'description' => 'text', 60 - 'isClosed' => 'bool', 60 + 'status' => 'text32', 61 61 ), 62 62 self::CONFIG_KEY_SCHEMA => array( 63 63 ), ··· 69 69 } 70 70 71 71 public function getStatusObject() { 72 - return SlowvotePollStatus::newStatusObject($this->getIsClosed()); 72 + return SlowvotePollStatus::newStatusObject($this->getStatus()); 73 73 } 74 74 75 75 public function isClosed() { 76 - return ($this->getIsClosed() == SlowvotePollStatus::STATUS_CLOSED); 76 + return ($this->getStatus() == SlowvotePollStatus::STATUS_CLOSED); 77 77 } 78 78 79 79 public function getOptions() {
+1 -1
src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php
··· 30 30 case PhabricatorSlowvoteQuestionTransaction::TRANSACTIONTYPE: 31 31 case PhabricatorSlowvoteDescriptionTransaction::TRANSACTIONTYPE: 32 32 case PhabricatorSlowvoteShuffleTransaction::TRANSACTIONTYPE: 33 - case PhabricatorSlowvoteCloseTransaction::TRANSACTIONTYPE: 33 + case PhabricatorSlowvoteStatusTransaction::TRANSACTIONTYPE: 34 34 $tags[] = self::MAILTAG_DETAILS; 35 35 break; 36 36 case PhabricatorSlowvoteResponsesTransaction::TRANSACTIONTYPE:
-60
src/applications/slowvote/xaction/PhabricatorSlowvoteCloseTransaction.php
··· 1 - <?php 2 - 3 - final class PhabricatorSlowvoteCloseTransaction 4 - extends PhabricatorSlowvoteTransactionType { 5 - 6 - const TRANSACTIONTYPE = 'vote:close'; 7 - 8 - public function generateOldValue($object) { 9 - return (bool)$object->getIsClosed(); 10 - } 11 - 12 - public function generateNewValue($object, $value) { 13 - return (bool)$value; 14 - } 15 - 16 - public function applyInternalEffects($object, $value) { 17 - $object->setIsClosed((int)$value); 18 - } 19 - 20 - public function getTitle() { 21 - $new = $this->getNewValue(); 22 - 23 - if ($new) { 24 - return pht( 25 - '%s closed this poll.', 26 - $this->renderAuthor()); 27 - } else { 28 - return pht( 29 - '%s reopened this poll.', 30 - $this->renderAuthor()); 31 - } 32 - } 33 - 34 - public function getTitleForFeed() { 35 - $new = $this->getNewValue(); 36 - 37 - if ($new) { 38 - return pht( 39 - '%s closed %s.', 40 - $this->renderAuthor(), 41 - $this->renderObject()); 42 - } else { 43 - return pht( 44 - '%s reopened %s.', 45 - $this->renderAuthor(), 46 - $this->renderObject()); 47 - } 48 - } 49 - 50 - public function getIcon() { 51 - $new = $this->getNewValue(); 52 - 53 - if ($new) { 54 - return 'fa-ban'; 55 - } else { 56 - return 'fa-pencil'; 57 - } 58 - } 59 - 60 - }
+60
src/applications/slowvote/xaction/PhabricatorSlowvoteStatusTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorSlowvoteStatusTransaction 4 + extends PhabricatorSlowvoteTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'vote:status'; 7 + 8 + public function generateOldValue($object) { 9 + return (string)$object->getStatus(); 10 + } 11 + 12 + public function generateNewValue($object, $value) { 13 + return (string)$value; 14 + } 15 + 16 + public function applyInternalEffects($object, $value) { 17 + $object->setStatus($value); 18 + } 19 + 20 + public function getTitle() { 21 + $old_name = $this->getOldStatusObject()->getName(); 22 + $new_name = $this->getNewStatusObject()->getName(); 23 + 24 + return pht( 25 + '%s changed the status of this poll from %s to %s.', 26 + $this->renderAuthor(), 27 + $this->renderValue($old_name), 28 + $this->renderValue($new_name)); 29 + } 30 + 31 + public function getTitleForFeed() { 32 + $old_name = $this->getOldStatusObject()->getName(); 33 + $new_name = $this->getNewStatusObject()->getName(); 34 + 35 + 36 + return pht( 37 + '%s changed the status of %s from %s to %s.', 38 + $this->renderAuthor(), 39 + $this->renderObject(), 40 + $this->renderValue($old_name), 41 + $this->renderValue($new_name)); 42 + } 43 + 44 + public function getIcon() { 45 + return $this->getNewStatusObject()->getTransactionIcon(); 46 + } 47 + 48 + private function getOldStatusObject() { 49 + return $this->newStatusObject($this->getOldValue()); 50 + } 51 + 52 + private function getNewStatusObject() { 53 + return $this->newStatusObject($this->getNewValue()); 54 + } 55 + 56 + private function newStatusObject($value) { 57 + return SlowvotePollStatus::newStatusObject($value); 58 + } 59 + 60 + }