@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.

Reimplement Slowvote transactions using modular transactions

Summary:
Fixes T12623. Adds new modular transactions to Slowvote. Also converts
the `shuffle` column to `bool` for consistency with other boolean-ish columns.

Test Plan:
Create a new vote, modified everything that could be modified from the web UI,
observed expected timeline.

Example timeline: {F4938843}

Example transaction values in DB: {F4938850}

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T12623

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

+323 -333
+2
resources/sql/autopatches/20170504.1.slowvote.shuffle.sql
··· 1 + ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll 2 + MODIFY shuffle BOOL NOT NULL DEFAULT 0;
+13 -1
src/__phutil_library_map__.php
··· 3901 3901 'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php', 3902 3902 'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php', 3903 3903 'PhabricatorSlowvoteCloseController' => 'applications/slowvote/controller/PhabricatorSlowvoteCloseController.php', 3904 + 'PhabricatorSlowvoteCloseTransaction' => 'applications/slowvote/xactions/PhabricatorSlowvoteCloseTransaction.php', 3904 3905 'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php', 3905 3906 'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php', 3906 3907 'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php', 3907 3908 'PhabricatorSlowvoteDefaultViewCapability' => 'applications/slowvote/capability/PhabricatorSlowvoteDefaultViewCapability.php', 3909 + 'PhabricatorSlowvoteDescriptionTransaction' => 'applications/slowvote/xactions/PhabricatorSlowvoteDescriptionTransaction.php', 3908 3910 'PhabricatorSlowvoteEditController' => 'applications/slowvote/controller/PhabricatorSlowvoteEditController.php', 3909 3911 'PhabricatorSlowvoteEditor' => 'applications/slowvote/editor/PhabricatorSlowvoteEditor.php', 3910 3912 'PhabricatorSlowvoteListController' => 'applications/slowvote/controller/PhabricatorSlowvoteListController.php', ··· 3914 3916 'PhabricatorSlowvotePollController' => 'applications/slowvote/controller/PhabricatorSlowvotePollController.php', 3915 3917 'PhabricatorSlowvotePollPHIDType' => 'applications/slowvote/phid/PhabricatorSlowvotePollPHIDType.php', 3916 3918 'PhabricatorSlowvoteQuery' => 'applications/slowvote/query/PhabricatorSlowvoteQuery.php', 3919 + 'PhabricatorSlowvoteQuestionTransaction' => 'applications/slowvote/xactions/PhabricatorSlowvoteQuestionTransaction.php', 3917 3920 'PhabricatorSlowvoteReplyHandler' => 'applications/slowvote/mail/PhabricatorSlowvoteReplyHandler.php', 3921 + 'PhabricatorSlowvoteResponsesTransaction' => 'applications/slowvote/xactions/PhabricatorSlowvoteResponsesTransaction.php', 3918 3922 'PhabricatorSlowvoteSchemaSpec' => 'applications/slowvote/storage/PhabricatorSlowvoteSchemaSpec.php', 3919 3923 'PhabricatorSlowvoteSearchEngine' => 'applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php', 3924 + 'PhabricatorSlowvoteShuffleTransaction' => 'applications/slowvote/xactions/PhabricatorSlowvoteShuffleTransaction.php', 3920 3925 'PhabricatorSlowvoteTransaction' => 'applications/slowvote/storage/PhabricatorSlowvoteTransaction.php', 3921 3926 'PhabricatorSlowvoteTransactionComment' => 'applications/slowvote/storage/PhabricatorSlowvoteTransactionComment.php', 3922 3927 'PhabricatorSlowvoteTransactionQuery' => 'applications/slowvote/query/PhabricatorSlowvoteTransactionQuery.php', 3928 + 'PhabricatorSlowvoteTransactionType' => 'applications/slowvote/xactions/PhabricatorSlowvoteTransactionType.php', 3923 3929 'PhabricatorSlowvoteVoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteVoteController.php', 3924 3930 'PhabricatorSlug' => 'infrastructure/util/PhabricatorSlug.php', 3925 3931 'PhabricatorSlugTestCase' => 'infrastructure/util/__tests__/PhabricatorSlugTestCase.php', ··· 9327 9333 'PhabricatorSlowvoteApplication' => 'PhabricatorApplication', 9328 9334 'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO', 9329 9335 'PhabricatorSlowvoteCloseController' => 'PhabricatorSlowvoteController', 9336 + 'PhabricatorSlowvoteCloseTransaction' => 'PhabricatorSlowvoteTransactionType', 9330 9337 'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController', 9331 9338 'PhabricatorSlowvoteController' => 'PhabricatorController', 9332 9339 'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO', 9333 9340 'PhabricatorSlowvoteDefaultViewCapability' => 'PhabricatorPolicyCapability', 9341 + 'PhabricatorSlowvoteDescriptionTransaction' => 'PhabricatorSlowvoteTransactionType', 9334 9342 'PhabricatorSlowvoteEditController' => 'PhabricatorSlowvoteController', 9335 9343 'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor', 9336 9344 'PhabricatorSlowvoteListController' => 'PhabricatorSlowvoteController', ··· 9350 9358 'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController', 9351 9359 'PhabricatorSlowvotePollPHIDType' => 'PhabricatorPHIDType', 9352 9360 'PhabricatorSlowvoteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 9361 + 'PhabricatorSlowvoteQuestionTransaction' => 'PhabricatorSlowvoteTransactionType', 9353 9362 'PhabricatorSlowvoteReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 9363 + 'PhabricatorSlowvoteResponsesTransaction' => 'PhabricatorSlowvoteTransactionType', 9354 9364 'PhabricatorSlowvoteSchemaSpec' => 'PhabricatorConfigSchemaSpec', 9355 9365 'PhabricatorSlowvoteSearchEngine' => 'PhabricatorApplicationSearchEngine', 9356 - 'PhabricatorSlowvoteTransaction' => 'PhabricatorApplicationTransaction', 9366 + 'PhabricatorSlowvoteShuffleTransaction' => 'PhabricatorSlowvoteTransactionType', 9367 + 'PhabricatorSlowvoteTransaction' => 'PhabricatorModularTransaction', 9357 9368 'PhabricatorSlowvoteTransactionComment' => 'PhabricatorApplicationTransactionComment', 9358 9369 'PhabricatorSlowvoteTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 9370 + 'PhabricatorSlowvoteTransactionType' => 'PhabricatorModularTransactionType', 9359 9371 'PhabricatorSlowvoteVoteController' => 'PhabricatorSlowvoteController', 9360 9372 'PhabricatorSlug' => 'Phobject', 9361 9373 'PhabricatorSlugTestCase' => 'PhabricatorTestCase',
+2 -1
src/applications/slowvote/controller/PhabricatorSlowvoteCloseController.php
··· 32 32 $xactions = array(); 33 33 34 34 $xactions[] = id(new PhabricatorSlowvoteTransaction()) 35 - ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_CLOSE) 35 + ->setTransactionType( 36 + PhabricatorSlowvoteCloseTransaction::TRANSACTIONTYPE) 36 37 ->setNewValue($new_status); 37 38 38 39 id(new PhabricatorSlowvoteEditor())
+14 -5
src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
··· 77 77 } 78 78 } 79 79 80 - $xactions = array(); 81 80 $template = id(new PhabricatorSlowvoteTransaction()); 81 + $xactions = array(); 82 + 83 + if ($is_new) { 84 + $xactions[] = id(new PhabricatorSlowvoteTransaction()) 85 + ->setTransactionType(PhabricatorTransactions::TYPE_CREATE); 86 + } 82 87 83 88 $xactions[] = id(clone $template) 84 - ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_QUESTION) 89 + ->setTransactionType( 90 + PhabricatorSlowvoteQuestionTransaction::TRANSACTIONTYPE) 85 91 ->setNewValue($v_question); 86 92 87 93 $xactions[] = id(clone $template) 88 - ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION) 94 + ->setTransactionType( 95 + PhabricatorSlowvoteDescriptionTransaction::TRANSACTIONTYPE) 89 96 ->setNewValue($v_description); 90 97 91 98 $xactions[] = id(clone $template) 92 - ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_RESPONSES) 99 + ->setTransactionType( 100 + PhabricatorSlowvoteResponsesTransaction::TRANSACTIONTYPE) 93 101 ->setNewValue($v_responses); 94 102 95 103 $xactions[] = id(clone $template) 96 - ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_SHUFFLE) 104 + ->setTransactionType( 105 + PhabricatorSlowvoteShuffleTransaction::TRANSACTIONTYPE) 97 106 ->setNewValue($v_shuffle); 98 107 99 108 $xactions[] = id(clone $template)
+1 -93
src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
··· 13 13 14 14 public function getTransactionTypes() { 15 15 $types = parent::getTransactionTypes(); 16 - 17 16 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 18 17 19 - $types[] = PhabricatorSlowvoteTransaction::TYPE_QUESTION; 20 - $types[] = PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION; 21 - $types[] = PhabricatorSlowvoteTransaction::TYPE_RESPONSES; 22 - $types[] = PhabricatorSlowvoteTransaction::TYPE_SHUFFLE; 23 - $types[] = PhabricatorSlowvoteTransaction::TYPE_CLOSE; 24 - 25 18 return $types; 26 19 } 27 20 28 - protected function transactionHasEffect( 29 - PhabricatorLiskDAO $object, 30 - PhabricatorApplicationTransaction $xaction) { 31 - 32 - $old = $xaction->getOldValue(); 33 - $new = $xaction->getNewValue(); 34 - 35 - switch ($xaction->getTransactionType()) { 36 - case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 37 - if ($old === null) { 38 - return true; 39 - } 40 - return ((int)$old !== (int)$new); 41 - case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 42 - if ($old === null) { 43 - return true; 44 - } 45 - return ((bool)$old !== (bool)$new); 46 - } 47 - 48 - return parent::transactionHasEffect($object, $xaction); 49 - } 50 - 51 - 52 - protected function getCustomTransactionOldValue( 53 - PhabricatorLiskDAO $object, 54 - PhabricatorApplicationTransaction $xaction) { 55 - 56 - switch ($xaction->getTransactionType()) { 57 - case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 58 - return $object->getQuestion(); 59 - case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 60 - return $object->getDescription(); 61 - case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 62 - return $object->getResponseVisibility(); 63 - case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 64 - return $object->getShuffle(); 65 - case PhabricatorSlowvoteTransaction::TYPE_CLOSE: 66 - return $object->getIsClosed(); 67 - } 68 - } 69 - 70 - protected function getCustomTransactionNewValue( 71 - PhabricatorLiskDAO $object, 72 - PhabricatorApplicationTransaction $xaction) { 73 - 74 - switch ($xaction->getTransactionType()) { 75 - case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 76 - case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 77 - case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 78 - case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 79 - case PhabricatorSlowvoteTransaction::TYPE_CLOSE: 80 - return $xaction->getNewValue(); 81 - } 82 - } 83 - 84 - protected function applyCustomInternalTransaction( 85 - PhabricatorLiskDAO $object, 86 - PhabricatorApplicationTransaction $xaction) { 87 - 88 - switch ($xaction->getTransactionType()) { 89 - case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 90 - $object->setQuestion($xaction->getNewValue()); 91 - break; 92 - case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 93 - $object->setDescription($xaction->getNewValue()); 94 - break; 95 - case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 96 - $object->setResponseVisibility($xaction->getNewValue()); 97 - break; 98 - case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 99 - $object->setShuffle($xaction->getNewValue()); 100 - break; 101 - case PhabricatorSlowvoteTransaction::TYPE_CLOSE: 102 - $object->setIsClosed((int)$xaction->getNewValue()); 103 - break; 104 - } 105 - } 106 - 107 - protected function applyCustomExternalTransaction( 108 - PhabricatorLiskDAO $object, 109 - PhabricatorApplicationTransaction $xaction) { 110 - return; 111 - } 112 - 113 - protected function shouldSendMail( 21 + protected function shouldSendMail( 114 22 PhabricatorLiskDAO $object, 115 23 array $xactions) { 116 24 return true;
+3 -3
src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
··· 21 21 protected $question; 22 22 protected $description; 23 23 protected $authorPHID; 24 - protected $responseVisibility; 25 - protected $shuffle; 24 + protected $responseVisibility = 0; 25 + protected $shuffle = 0; 26 26 protected $method; 27 27 protected $mailKey; 28 28 protected $viewPolicy; ··· 54 54 self::CONFIG_COLUMN_SCHEMA => array( 55 55 'question' => 'text255', 56 56 'responseVisibility' => 'uint32', 57 - 'shuffle' => 'uint32', 57 + 'shuffle' => 'bool', 58 58 'method' => 'uint32', 59 59 'description' => 'text', 60 60 'isClosed' => 'bool',
+8 -230
src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php
··· 1 1 <?php 2 2 3 3 final class PhabricatorSlowvoteTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_QUESTION = 'vote:question'; 7 - const TYPE_DESCRIPTION = 'vote:description'; 8 - const TYPE_RESPONSES = 'vote:responses'; 9 - const TYPE_SHUFFLE = 'vote:shuffle'; 10 - const TYPE_CLOSE = 'vote:close'; 4 + extends PhabricatorModularTransaction { 11 5 12 6 const MAILTAG_DETAILS = 'vote:details'; 13 7 const MAILTAG_RESPONSES = 'vote:responses'; ··· 25 19 return new PhabricatorSlowvoteTransactionComment(); 26 20 } 27 21 28 - public function shouldHide() { 29 - $old = $this->getOldValue(); 30 - $new = $this->getNewValue(); 31 - 32 - switch ($this->getTransactionType()) { 33 - case self::TYPE_DESCRIPTION: 34 - case self::TYPE_RESPONSES: 35 - case self::TYPE_SHUFFLE: 36 - case self::TYPE_CLOSE: 37 - return ($old === null); 38 - } 39 - 40 - return parent::shouldHide(); 41 - } 42 - 43 - public function getTitle() { 44 - $author_phid = $this->getAuthorPHID(); 45 - 46 - $old = $this->getOldValue(); 47 - $new = $this->getNewValue(); 48 - 49 - switch ($this->getTransactionType()) { 50 - case self::TYPE_QUESTION: 51 - if ($old === null) { 52 - return pht( 53 - '%s created this poll.', 54 - $this->renderHandleLink($author_phid)); 55 - } else { 56 - return pht( 57 - '%s changed the poll question from "%s" to "%s".', 58 - $this->renderHandleLink($author_phid), 59 - $old, 60 - $new); 61 - } 62 - break; 63 - case self::TYPE_DESCRIPTION: 64 - return pht( 65 - '%s updated the description for this poll.', 66 - $this->renderHandleLink($author_phid)); 67 - case self::TYPE_RESPONSES: 68 - // TODO: This could be more detailed 69 - return pht( 70 - '%s changed who can see the responses.', 71 - $this->renderHandleLink($author_phid)); 72 - case self::TYPE_SHUFFLE: 73 - if ($new) { 74 - return pht( 75 - '%s made poll responses appear in a random order.', 76 - $this->renderHandleLink($author_phid)); 77 - } else { 78 - return pht( 79 - '%s made poll responses appear in a fixed order.', 80 - $this->renderHandleLink($author_phid)); 81 - } 82 - break; 83 - case self::TYPE_CLOSE: 84 - if ($new) { 85 - return pht( 86 - '%s closed this poll.', 87 - $this->renderHandleLink($author_phid)); 88 - } else { 89 - return pht( 90 - '%s reopened this poll.', 91 - $this->renderHandleLink($author_phid)); 92 - } 93 - 94 - break; 95 - } 96 - 97 - return parent::getTitle(); 98 - } 99 - 100 - public function getRemarkupBlocks() { 101 - $blocks = parent::getRemarkupBlocks(); 102 - 103 - $type = $this->getTransactionType(); 104 - switch ($type) { 105 - case self::TYPE_DESCRIPTION: 106 - $blocks[] = $this->getNewValue(); 107 - break; 108 - } 109 - 110 - return $blocks; 111 - } 112 - 113 - public function getTitleForFeed() { 114 - $author_phid = $this->getAuthorPHID(); 115 - $object_phid = $this->getObjectPHID(); 116 - 117 - $old = $this->getOldValue(); 118 - $new = $this->getNewValue(); 119 - 120 - $type = $this->getTransactionType(); 121 - switch ($type) { 122 - case self::TYPE_QUESTION: 123 - if ($old === null) { 124 - return pht( 125 - '%s created %s.', 126 - $this->renderHandleLink($author_phid), 127 - $this->renderHandleLink($object_phid)); 128 - 129 - } else { 130 - return pht( 131 - '%s renamed %s.', 132 - $this->renderHandleLink($author_phid), 133 - $this->renderHandleLink($object_phid)); 134 - } 135 - break; 136 - case self::TYPE_DESCRIPTION: 137 - if ($old === null) { 138 - return pht( 139 - '%s set the description of %s.', 140 - $this->renderHandleLink($author_phid), 141 - $this->renderHandleLink($object_phid)); 142 - 143 - } else { 144 - return pht( 145 - '%s edited the description of %s.', 146 - $this->renderHandleLink($author_phid), 147 - $this->renderHandleLink($object_phid)); 148 - } 149 - break; 150 - case self::TYPE_RESPONSES: 151 - // TODO: This could be more detailed 152 - return pht( 153 - '%s changed who can see the responses of %s.', 154 - $this->renderHandleLink($author_phid), 155 - $this->renderHandleLink($object_phid)); 156 - 157 - case self::TYPE_SHUFFLE: 158 - if ($new) { 159 - return pht( 160 - '%s made %s responses appear in a random order.', 161 - $this->renderHandleLink($author_phid), 162 - $this->renderHandleLink($object_phid)); 163 - 164 - } else { 165 - return pht( 166 - '%s made %s responses appear in a fixed order.', 167 - $this->renderHandleLink($author_phid), 168 - $this->renderHandleLink($object_phid)); 169 - } 170 - case self::TYPE_CLOSE: 171 - if ($new) { 172 - return pht( 173 - '%s closed %s.', 174 - $this->renderHandleLink($author_phid), 175 - $this->renderHandleLink($object_phid)); 176 - 177 - } else { 178 - return pht( 179 - '%s reopened %s.', 180 - $this->renderHandleLink($author_phid), 181 - $this->renderHandleLink($object_phid)); 182 - } 183 - break; 184 - } 185 - 186 - return parent::getTitleForFeed(); 187 - } 188 - 189 - public function getIcon() { 190 - $old = $this->getOldValue(); 191 - $new = $this->getNewValue(); 192 - 193 - switch ($this->getTransactionType()) { 194 - case self::TYPE_QUESTION: 195 - if ($old === null) { 196 - return 'fa-plus'; 197 - } else { 198 - return 'fa-pencil'; 199 - } 200 - case self::TYPE_DESCRIPTION: 201 - case self::TYPE_RESPONSES: 202 - return 'fa-pencil'; 203 - case self::TYPE_SHUFFLE: 204 - return 'fa-refresh'; 205 - case self::TYPE_CLOSE: 206 - if ($new) { 207 - return 'fa-ban'; 208 - } else { 209 - return 'fa-pencil'; 210 - } 211 - } 212 - 213 - return parent::getIcon(); 214 - } 215 - 216 - 217 - public function getColor() { 218 - $old = $this->getOldValue(); 219 - $new = $this->getNewValue(); 220 - 221 - switch ($this->getTransactionType()) { 222 - case self::TYPE_QUESTION: 223 - case self::TYPE_DESCRIPTION: 224 - case self::TYPE_RESPONSES: 225 - case self::TYPE_SHUFFLE: 226 - case self::TYPE_CLOSE: 227 - return PhabricatorTransactions::COLOR_BLUE; 228 - } 229 - 230 - return parent::getColor(); 231 - } 232 - 233 - public function hasChangeDetails() { 234 - switch ($this->getTransactionType()) { 235 - case self::TYPE_DESCRIPTION: 236 - return true; 237 - } 238 - return parent::hasChangeDetails(); 239 - } 240 - 241 - public function renderChangeDetails(PhabricatorUser $viewer) { 242 - return $this->renderTextCorpusChangeDetails( 243 - $viewer, 244 - $this->getOldValue(), 245 - $this->getNewValue()); 22 + public function getBaseTransactionClass() { 23 + return 'PhabricatorSlowvoteTransactionType'; 246 24 } 247 25 248 26 public function getMailTags() { 249 27 $tags = parent::getMailTags(); 250 28 251 29 switch ($this->getTransactionType()) { 252 - case self::TYPE_QUESTION: 253 - case self::TYPE_DESCRIPTION: 254 - case self::TYPE_SHUFFLE: 255 - case self::TYPE_CLOSE: 30 + case PhabricatorSlowvoteQuestionTransaction::TRANSACTIONTYPE: 31 + case PhabricatorSlowvoteDescriptionTransaction::TRANSACTIONTYPE: 32 + case PhabricatorSlowvoteShuffleTransaction::TRANSACTIONTYPE: 33 + case PhabricatorSlowvoteCloseTransaction::TRANSACTIONTYPE: 256 34 $tags[] = self::MAILTAG_DETAILS; 257 35 break; 258 - case self::TYPE_RESPONSES: 36 + case PhabricatorSlowvoteResponsesTransaction::TRANSACTIONTYPE: 259 37 $tags[] = self::MAILTAG_RESPONSES; 260 38 break; 261 39 default:
+60
src/applications/slowvote/xactions/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/xactions/PhabricatorSlowvoteDescriptionTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorSlowvoteDescriptionTransaction 4 + extends PhabricatorSlowvoteTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'vote:description'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getDescription(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setDescription($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the description for this poll.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + $old = $this->getOldValue(); 24 + 25 + if ($old === null) { 26 + return pht( 27 + '%s set the description of %s.', 28 + $this->renderAuthor(), 29 + $this->renderObject()); 30 + 31 + } else { 32 + return pht( 33 + '%s edited the description of %s.', 34 + $this->renderAuthor(), 35 + $this->renderObject()); 36 + } 37 + } 38 + 39 + public function hasChangeDetails() { 40 + return true; 41 + } 42 + 43 + public function newChangeDetailView() { 44 + return $this->renderTextCorpusChangeDetails( 45 + $this->getViewer(), 46 + $this->getOldValue(), 47 + $this->getNewValue()); 48 + } 49 + 50 + public function newRemarkupChanges() { 51 + $changes = array(); 52 + 53 + $changes[] = $this->newRemarkupChange() 54 + ->setOldValue($this->getOldValue()) 55 + ->setNewValue($this->getNewValue()); 56 + 57 + return $changes; 58 + } 59 + 60 + }
+70
src/applications/slowvote/xactions/PhabricatorSlowvoteQuestionTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorSlowvoteQuestionTransaction 4 + extends PhabricatorSlowvoteTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'vote:question'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getQuestion(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setQuestion($value); 14 + } 15 + 16 + public function getTitle() { 17 + $old = $this->getOldValue(); 18 + $new = $this->getNewValue(); 19 + 20 + if ($old === null) { 21 + return pht( 22 + '%s created this poll.', 23 + $this->renderAuthor()); 24 + } else { 25 + return pht( 26 + '%s changed the poll question from "%s" to "%s".', 27 + $this->renderAuthor(), 28 + $old, 29 + $new); 30 + } 31 + } 32 + 33 + public function getTitleForFeed() { 34 + $old = $this->getOldValue(); 35 + 36 + if ($old === null) { 37 + return pht( 38 + '%s created %s.', 39 + $this->renderAuthor(), 40 + $this->renderObject()); 41 + 42 + } else { 43 + return pht( 44 + '%s renamed %s.', 45 + $this->renderAuthor(), 46 + $this->renderObject()); 47 + } 48 + } 49 + 50 + public function getIcon() { 51 + $old = $this->getOldValue(); 52 + 53 + if ($old === null) { 54 + return 'fa-plus'; 55 + } else { 56 + return 'fa-pencil'; 57 + } 58 + } 59 + 60 + public function validateTransactions($object, array $xactions) { 61 + $errors = array(); 62 + 63 + if ($this->isEmptyTextTransaction($object->getQuestion(), $xactions)) { 64 + $errors[] = $this->newRequiredError(pht('Polls must have a question.')); 65 + } 66 + 67 + return $errors; 68 + } 69 + 70 + }
+31
src/applications/slowvote/xactions/PhabricatorSlowvoteResponsesTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorSlowvoteResponsesTransaction 4 + extends PhabricatorSlowvoteTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'vote:responses'; 7 + 8 + public function generateOldValue($object) { 9 + return (int)$object->getResponseVisibility(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setResponseVisibility($value); 14 + } 15 + 16 + public function getTitle() { 17 + // TODO: This could be more detailed 18 + return pht( 19 + '%s changed who can see the responses.', 20 + $this->renderAuthor()); 21 + } 22 + 23 + public function getTitleForFeed() { 24 + // TODO: This could be more detailed 25 + return pht( 26 + '%s changed who can see the responses of %s.', 27 + $this->renderAuthor(), 28 + $this->renderObject()); 29 + } 30 + 31 + }
+55
src/applications/slowvote/xactions/PhabricatorSlowvoteShuffleTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorSlowvoteShuffleTransaction 4 + extends PhabricatorSlowvoteTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'vote:shuffle'; 7 + 8 + public function generateOldValue($object) { 9 + return (bool)$object->getShuffle(); 10 + } 11 + 12 + public function generateNewValue($object, $value) { 13 + return (bool)$value; 14 + } 15 + 16 + public function applyInternalEffects($object, $value) { 17 + $object->setShuffle((int)$value); 18 + } 19 + 20 + public function getTitle() { 21 + $new = $this->getNewValue(); 22 + 23 + if ($new) { 24 + return pht( 25 + '%s made poll responses appear in a random order.', 26 + $this->renderAuthor()); 27 + } else { 28 + return pht( 29 + '%s made poll responses appear in a fixed order.', 30 + $this->renderAuthor()); 31 + } 32 + } 33 + 34 + public function getTitleForFeed() { 35 + $new = $this->getNewValue(); 36 + 37 + if ($new) { 38 + return pht( 39 + '%s made %s responses appear in a random order.', 40 + $this->renderAuthor(), 41 + $this->renderObject()); 42 + 43 + } else { 44 + return pht( 45 + '%s made %s responses appear in a fixed order.', 46 + $this->renderAuthor(), 47 + $this->renderObject()); 48 + } 49 + } 50 + 51 + public function getIcon() { 52 + return 'fa-refresh'; 53 + } 54 + 55 + }
+4
src/applications/slowvote/xactions/PhabricatorSlowvoteTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorSlowvoteTransactionType 4 + extends PhabricatorModularTransactionType {}