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

Migrate Slowvote comments to ApplicationTransactions

Summary:
Move comments from the old table to ApplicationTransactions. Patch dances around which objects it uses since I intend to delete the comment table.

NOTE: This temporarily disables comment writes. I'll restore them shortly.

Test Plan: {F50166}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

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

+163 -127
+101
resources/sql/patches/20130715.votecomments.php
··· 1 + <?php 2 + 3 + echo "Moving Slowvote comments to transactions...\n"; 4 + 5 + $viewer = PhabricatorUser::getOmnipotentUser(); 6 + 7 + $table_xaction = new PhabricatorSlowvoteTransaction(); 8 + $table_comment = new PhabricatorSlowvoteTransactionComment(); 9 + $conn_w = $table_xaction->establishConnection('w'); 10 + 11 + $comments = new LiskRawMigrationIterator($conn_w, 'slowvote_comment'); 12 + 13 + $conn_w->openTransaction(); 14 + 15 + foreach ($comments as $comment) { 16 + $id = $comment['id']; 17 + $poll_id = $comment['pollID']; 18 + $author_phid = $comment['authorPHID']; 19 + $text = $comment['commentText']; 20 + $date_created = $comment['dateCreated']; 21 + $date_modified = $comment['dateModified']; 22 + 23 + echo "Migrating comment {$id}.\n"; 24 + 25 + $poll = id(new PhabricatorSlowvoteQuery()) 26 + ->setViewer($viewer) 27 + ->withIDs(array($poll_id)) 28 + ->executeOne(); 29 + if (!$poll) { 30 + echo "No poll.\n"; 31 + continue; 32 + } 33 + 34 + $user = id(new PhabricatorPeopleQuery()) 35 + ->setViewer($viewer) 36 + ->withPHIDs(array($author_phid)) 37 + ->executeOne(); 38 + if (!$user) { 39 + echo "No user.\n"; 40 + continue; 41 + } 42 + 43 + $comment_phid = PhabricatorPHID::generateNewPHID( 44 + PhabricatorPHIDConstants::PHID_TYPE_XCMT); 45 + $xaction_phid = PhabricatorPHID::generateNewPHID( 46 + PhabricatorPHIDConstants::PHID_TYPE_XACT, 47 + PhabricatorPHIDConstants::PHID_TYPE_POLL); 48 + 49 + $source = PhabricatorContentSource::newForSource( 50 + PhabricatorContentSource::SOURCE_LEGACY, 51 + array())->serialize(); 52 + 53 + queryfx( 54 + $conn_w, 55 + 'INSERT INTO %T (phid, transactionPHID, authorPHID, viewPolicy, editPolicy, 56 + commentVersion, content, contentSource, isDeleted, 57 + dateCreated, dateModified) 58 + VALUES (%s, %s, %s, %s, %s, 59 + %d, %s, %s, %d, 60 + %d, %d)', 61 + $table_comment->getTableName(), 62 + $comment_phid, 63 + $xaction_phid, 64 + $user->getPHID(), 65 + PhabricatorPolicies::POLICY_PUBLIC, 66 + $user->getPHID(), 67 + 1, 68 + $text, 69 + $source, 70 + 0, 71 + $date_created, 72 + $date_modified); 73 + 74 + queryfx( 75 + $conn_w, 76 + 'INSERT INTO %T (phid, authorPHID, objectPHID, viewPolicy, editPolicy, 77 + commentPHID, commentVersion, transactionType, oldValue, newValue, 78 + contentSource, metadata, dateCreated, dateModified) 79 + VALUES (%s, %s, %s, %s, %s, 80 + %s, %d, %s, %s, %s, 81 + %s, %s, %d, %d)', 82 + $table_xaction->getTableName(), 83 + $xaction_phid, 84 + $user->getPHID(), 85 + $poll->getPHID(), 86 + PhabricatorPolicies::POLICY_PUBLIC, 87 + $user->getPHID(), 88 + $comment_phid, 89 + 1, 90 + PhabricatorTransactions::TYPE_COMMENT, 91 + null, 92 + null, 93 + $source, 94 + '{}', 95 + $date_created, 96 + $date_modified); 97 + } 98 + 99 + $conn_w->saveTransaction(); 100 + 101 + echo "Done.\n";
+6
src/__phutil_library_map__.php
··· 1536 1536 'PhabricatorSlowvotePollController' => 'applications/slowvote/controller/PhabricatorSlowvotePollController.php', 1537 1537 'PhabricatorSlowvoteQuery' => 'applications/slowvote/query/PhabricatorSlowvoteQuery.php', 1538 1538 'PhabricatorSlowvoteSearchEngine' => 'applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php', 1539 + 'PhabricatorSlowvoteTransaction' => 'applications/slowvote/storage/PhabricatorSlowvoteTransaction.php', 1540 + 'PhabricatorSlowvoteTransactionComment' => 'applications/slowvote/storage/PhabricatorSlowvoteTransactionComment.php', 1541 + 'PhabricatorSlowvoteTransactionQuery' => 'applications/slowvote/query/PhabricatorSlowvoteTransactionQuery.php', 1539 1542 'PhabricatorSlowvoteVoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteVoteController.php', 1540 1543 'PhabricatorSlug' => 'infrastructure/util/PhabricatorSlug.php', 1541 1544 'PhabricatorSlugTestCase' => 'infrastructure/util/__tests__/PhabricatorSlugTestCase.php', ··· 3500 3503 'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController', 3501 3504 'PhabricatorSlowvoteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3502 3505 'PhabricatorSlowvoteSearchEngine' => 'PhabricatorApplicationSearchEngine', 3506 + 'PhabricatorSlowvoteTransaction' => 'PhabricatorApplicationTransaction', 3507 + 'PhabricatorSlowvoteTransactionComment' => 'PhabricatorApplicationTransactionComment', 3508 + 'PhabricatorSlowvoteTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 3503 3509 'PhabricatorSlowvoteVoteController' => 'PhabricatorSlowvoteController', 3504 3510 'PhabricatorSlugTestCase' => 'PhabricatorTestCase', 3505 3511 'PhabricatorSortTableExample' => 'PhabricatorUIExample',
+1
src/applications/metamta/contentsource/PhabricatorContentSource.php
··· 9 9 const SOURCE_MOBILE = 'mobile'; 10 10 const SOURCE_TABLET = 'tablet'; 11 11 const SOURCE_FAX = 'fax'; 12 + const SOURCE_LEGACY = 'legacy'; 12 13 13 14 private $source; 14 15 private $params = array();
+8 -7
src/applications/metamta/contentsource/PhabricatorContentSourceView.php
··· 13 13 require_celerity_resource('phabricator-content-source-view-css'); 14 14 15 15 $map = array( 16 - PhabricatorContentSource::SOURCE_WEB => 'Web', 17 - PhabricatorContentSource::SOURCE_CONDUIT => 'Conduit', 18 - PhabricatorContentSource::SOURCE_EMAIL => 'Email', 19 - PhabricatorContentSource::SOURCE_MOBILE => 'Mobile', 20 - PhabricatorContentSource::SOURCE_TABLET => 'Tablet', 21 - PhabricatorContentSource::SOURCE_FAX => 'Fax', 16 + PhabricatorContentSource::SOURCE_WEB => pht('Web'), 17 + PhabricatorContentSource::SOURCE_CONDUIT => pht('Conduit'), 18 + PhabricatorContentSource::SOURCE_EMAIL => pht('Email'), 19 + PhabricatorContentSource::SOURCE_MOBILE => pht('Mobile'), 20 + PhabricatorContentSource::SOURCE_TABLET => pht('Tablet'), 21 + PhabricatorContentSource::SOURCE_FAX => pht('Fax'), 22 + PhabricatorContentSource::SOURCE_LEGACY => pht('Old World'), 22 23 ); 23 24 24 25 $source = $this->contentSource->getSource(); 25 26 $type = idx($map, $source, null); 26 27 27 28 if (!$type) { 28 - return; 29 + return null; 29 30 } 30 31 31 32 return phutil_tag(
+32 -92
src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
··· 32 32 $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere( 33 33 'pollID = %d', 34 34 $poll->getID()); 35 - $comments = id(new PhabricatorSlowvoteComment())->loadAllWhere( 36 - 'pollID = %d', 37 - $poll->getID()); 38 35 39 36 $choices_by_option = mgroup($choices, 'getOptionID'); 40 - $comments_by_user = mpull($comments, null, 'getAuthorPHID'); 41 37 $choices_by_user = mgroup($choices, 'getAuthorPHID'); 42 38 $viewer_choices = idx($choices_by_user, $viewer_phid, array()); 43 - $viewer_comment = idx($comments_by_user, $viewer_phid, null); 44 - 45 - $comment_text = null; 46 - if ($viewer_comment) { 47 - $comment_text = $viewer_comment->getCommentText(); 48 - } 49 39 50 40 if ($request->isAjax()) { 51 41 $embed = id(new SlowvoteEmbedView()) ··· 63 53 64 54 $phids = array_merge( 65 55 mpull($choices, 'getAuthorPHID'), 66 - mpull($comments, 'getAuthorPHID'), 67 56 array( 68 57 $poll->getAuthorPHID(), 69 58 )); ··· 85 74 $option); 86 75 } 87 76 88 - $comments_by_option = array(); 89 77 switch ($poll->getMethod()) { 90 78 case PhabricatorSlowvotePoll::METHOD_PLURALITY: 91 79 $choice_ids = array(); 92 80 foreach ($choices_by_user as $user_phid => $user_choices) { 93 81 $choice_ids[$user_phid] = head($user_choices)->getOptionID(); 94 82 } 95 - foreach ($comments as $comment) { 96 - $choice = idx($choice_ids, $comment->getAuthorPHID()); 97 - if ($choice) { 98 - $comments_by_option[$choice][] = $comment; 99 - } 100 - } 101 83 break; 102 84 case PhabricatorSlowvotePoll::METHOD_APPROVAL: 103 - // All comments are grouped in approval voting. 104 85 break; 105 86 default: 106 87 throw new Exception("Unknown poll method!"); ··· 110 91 $poll, 111 92 $options, 112 93 $choices, 113 - $comments, 114 94 $viewer_choices, 115 95 $choices_by_option, 116 - $comments_by_option, 117 96 $handles, 118 97 $objects); 119 98 ··· 140 119 ->setLabel(pht('Vote')) 141 120 ->setValue($option_markup)) 142 121 ->appendChild( 143 - id(new AphrontFormTextAreaControl()) 144 - ->setLabel(pht('Comments')) 145 - ->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT) 146 - ->setName('comments') 147 - ->setValue($comment_text)) 148 - ->appendChild( 149 122 id(new AphrontFormSubmitControl()) 150 123 ->setValue(pht('Engage in Deliberations'))); 151 124 ··· 166 139 hsprintf('<br /><br />'), 167 140 $panel); 168 141 142 + $xactions = $this->buildTransactions($poll); 143 + 169 144 return $this->buildApplicationPage( 170 145 array( 171 146 $crumbs, 172 147 $header, 173 148 $content, 149 + $xactions, 174 150 ), 175 151 array( 176 152 'title' => 'V'.$poll->getID().' '.$poll->getQuestion(), ··· 179 155 )); 180 156 } 181 157 182 - private function renderComments(array $comments, array $handles) { 183 - assert_instances_of($comments, 'PhabricatorSlowvoteComment'); 184 - assert_instances_of($handles, 'PhabricatorObjectHandle'); 185 - 186 - $viewer = $this->getRequest()->getUser(); 187 - 188 - $engine = PhabricatorMarkupEngine::newSlowvoteMarkupEngine(); 189 - $engine->setConfig('viewer', $viewer); 190 - 191 - $comment_markup = array(); 192 - foreach ($comments as $comment) { 193 - $handle = $handles[$comment->getAuthorPHID()]; 194 - 195 - $markup = $engine->markupText($comment->getCommentText()); 196 - 197 - require_celerity_resource('phabricator-remarkup-css'); 198 - 199 - $comment_markup[] = hsprintf( 200 - '<tr>'. 201 - '<th>'. 202 - '%s'. 203 - '<div class="phabricator-slowvote-datestamp">%s</div>'. 204 - '</th>'. 205 - '<td>'. 206 - '<div class="phabricator-remarkup">%s</div>'. 207 - '</td>'. 208 - '</tr>', 209 - $handle->renderLink(), 210 - phabricator_datetime($comment->getDateCreated(), $viewer), 211 - $markup); 212 - } 213 - 214 - if ($comment_markup) { 215 - $comment_markup = phutil_tag( 216 - 'table', 217 - array( 218 - 'class' => 'phabricator-slowvote-comments', 219 - ), 220 - $comment_markup); 221 - } else { 222 - $comment_markup = null; 223 - } 224 - 225 - return $comment_markup; 226 - } 227 158 228 159 private function renderPollOption( 229 160 PhabricatorSlowvotePoll $poll, ··· 330 261 PhabricatorSlowvotePoll $poll, 331 262 array $options, 332 263 array $choices, 333 - array $comments, 334 264 array $viewer_choices, 335 265 array $choices_by_option, 336 - array $comments_by_option, 337 266 array $handles, 338 267 array $objects) { 339 268 assert_instances_of($options, 'PhabricatorSlowvoteOption'); 340 269 assert_instances_of($choices, 'PhabricatorSlowvoteChoice'); 341 - assert_instances_of($comments, 'PhabricatorSlowvoteComment'); 342 270 assert_instances_of($viewer_choices, 'PhabricatorSlowvoteChoice'); 343 271 assert_instances_of($handles, 'PhabricatorObjectHandle'); 344 272 assert_instances_of($objects, 'PhabricatorLiskDAO'); ··· 407 335 $user_markup = pht('This option has failed to appeal to anyone.'); 408 336 } 409 337 410 - $comment_markup = $this->renderComments( 411 - idx($comments_by_option, $id, array()), 412 - $handles); 413 - 414 338 $vote_count = $this->renderVoteCount( 415 339 $poll, 416 340 $choices, ··· 422 346 '<h1>%s</h1>'. 423 347 '<hr class="phabricator-slowvote-hr" />'. 424 348 '%s'. 425 - '<div style="clear: both;" />'. 349 + '<div style="clear: both;"></div>'. 426 350 '<hr class="phabricator-slowvote-hr" />'. 427 - '%s'. 428 351 '</div>', 429 352 $vote_count, 430 353 $option->getName(), 431 - phutil_tag('div', array(), $user_markup), 432 - $comment_markup)); 354 + phutil_tag('div', array(), $user_markup))); 433 355 } 434 356 435 - if ($poll->getMethod() == PhabricatorSlowvotePoll::METHOD_APPROVAL && 436 - $comments) { 437 - $comment_markup = $this->renderComments( 438 - $comments, 439 - $handles); 440 - $result_markup->appendChild( 441 - phutil_tag('h1', array(), pht('Motions Proposed for Consideration'))); 442 - $result_markup->appendChild($comment_markup); 357 + return $result_markup; 358 + } 359 + 360 + private function buildTransactions(PhabricatorSlowvotePoll $poll) { 361 + $viewer = $this->getRequest()->getUser(); 362 + 363 + $xactions = id(new PhabricatorSlowvoteTransactionQuery()) 364 + ->setViewer($viewer) 365 + ->withObjectPHIDs(array($poll->getPHID())) 366 + ->execute(); 367 + 368 + $engine = id(new PhabricatorMarkupEngine()) 369 + ->setViewer($viewer); 370 + foreach ($xactions as $xaction) { 371 + if ($xaction->getComment()) { 372 + $engine->addObject( 373 + $xaction->getComment(), 374 + PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); 375 + } 443 376 } 377 + $engine->process(); 444 378 445 - return $result_markup; 379 + $timeline = id(new PhabricatorApplicationTransactionView()) 380 + ->setUser($viewer) 381 + ->setTransactions($xactions) 382 + ->setMarkupEngine($engine); 383 + 384 + return $timeline; 446 385 } 386 + 447 387 }
-27
src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
··· 32 32 $poll->getID(), 33 33 $user->getPHID()); 34 34 35 - $comment_text = $request->getStr('comments'); 36 - $old_comment = id(new PhabricatorSlowvoteComment())->loadOneWhere( 37 - 'pollID = %d AND authorPHID = %s', 38 - $poll->getID(), 39 - $user->getPHID()); 40 - 41 - $update_comment = false; 42 - if ($old_comment && $comment_text && 43 - $old_comment->getCommentText() !== $comment_text) { 44 - 45 - $update_comment = true; 46 - } else if (!$old_comment && $comment_text) { 47 - $update_comment = true; 48 - } 49 - 50 - if ($update_comment) { 51 - if ($old_comment) { 52 - $old_comment->delete(); 53 - } 54 - 55 - id(new PhabricatorSlowvoteComment()) 56 - ->setAuthorPHID($user->getPHID()) 57 - ->setPollID($poll->getID()) 58 - ->setCommentText($comment_text) 59 - ->save(); 60 - } 61 - 62 35 $old_votes = mpull($user_choices, null, 'getOptionID'); 63 36 64 37 if ($request->isAjax()) {
+10
src/applications/slowvote/query/PhabricatorSlowvoteTransactionQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorSlowvoteTransactionQuery 4 + extends PhabricatorApplicationTransactionQuery { 5 + 6 + protected function getTemplateApplicationTransaction() { 7 + return new PhabricatorSlowvoteTransaction(); 8 + } 9 + 10 + }
+1 -1
src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php
··· 16 16 } 17 17 18 18 public function getApplicationTransactionCommentObject() { 19 - return new PhabricatorMacroTransactionComment(); 19 + return new PhabricatorSlowvoteTransactionComment(); 20 20 } 21 21 22 22 public function getApplicationObjectTypeName() {
+4
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1446 1446 'type' => 'sql', 1447 1447 'name' => $this->getPatchPath('20130714.votexactions.sql'), 1448 1448 ), 1449 + '20130715.votecomments.php' => array( 1450 + 'type' => 'php', 1451 + 'name' => $this->getPatchPath('20130715.votecomments.php'), 1452 + ), 1449 1453 ); 1450 1454 } 1451 1455 }