mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
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
This commit is contained in:
parent
ef1bedef02
commit
ea52bcbcd6
9 changed files with 164 additions and 128 deletions
101
resources/sql/patches/20130715.votecomments.php
Normal file
101
resources/sql/patches/20130715.votecomments.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
echo "Moving Slowvote comments to transactions...\n";
|
||||
|
||||
$viewer = PhabricatorUser::getOmnipotentUser();
|
||||
|
||||
$table_xaction = new PhabricatorSlowvoteTransaction();
|
||||
$table_comment = new PhabricatorSlowvoteTransactionComment();
|
||||
$conn_w = $table_xaction->establishConnection('w');
|
||||
|
||||
$comments = new LiskRawMigrationIterator($conn_w, 'slowvote_comment');
|
||||
|
||||
$conn_w->openTransaction();
|
||||
|
||||
foreach ($comments as $comment) {
|
||||
$id = $comment['id'];
|
||||
$poll_id = $comment['pollID'];
|
||||
$author_phid = $comment['authorPHID'];
|
||||
$text = $comment['commentText'];
|
||||
$date_created = $comment['dateCreated'];
|
||||
$date_modified = $comment['dateModified'];
|
||||
|
||||
echo "Migrating comment {$id}.\n";
|
||||
|
||||
$poll = id(new PhabricatorSlowvoteQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($poll_id))
|
||||
->executeOne();
|
||||
if (!$poll) {
|
||||
echo "No poll.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($author_phid))
|
||||
->executeOne();
|
||||
if (!$user) {
|
||||
echo "No user.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$comment_phid = PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_XCMT);
|
||||
$xaction_phid = PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_XACT,
|
||||
PhabricatorPHIDConstants::PHID_TYPE_POLL);
|
||||
|
||||
$source = PhabricatorContentSource::newForSource(
|
||||
PhabricatorContentSource::SOURCE_LEGACY,
|
||||
array())->serialize();
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'INSERT INTO %T (phid, transactionPHID, authorPHID, viewPolicy, editPolicy,
|
||||
commentVersion, content, contentSource, isDeleted,
|
||||
dateCreated, dateModified)
|
||||
VALUES (%s, %s, %s, %s, %s,
|
||||
%d, %s, %s, %d,
|
||||
%d, %d)',
|
||||
$table_comment->getTableName(),
|
||||
$comment_phid,
|
||||
$xaction_phid,
|
||||
$user->getPHID(),
|
||||
PhabricatorPolicies::POLICY_PUBLIC,
|
||||
$user->getPHID(),
|
||||
1,
|
||||
$text,
|
||||
$source,
|
||||
0,
|
||||
$date_created,
|
||||
$date_modified);
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'INSERT INTO %T (phid, authorPHID, objectPHID, viewPolicy, editPolicy,
|
||||
commentPHID, commentVersion, transactionType, oldValue, newValue,
|
||||
contentSource, metadata, dateCreated, dateModified)
|
||||
VALUES (%s, %s, %s, %s, %s,
|
||||
%s, %d, %s, %s, %s,
|
||||
%s, %s, %d, %d)',
|
||||
$table_xaction->getTableName(),
|
||||
$xaction_phid,
|
||||
$user->getPHID(),
|
||||
$poll->getPHID(),
|
||||
PhabricatorPolicies::POLICY_PUBLIC,
|
||||
$user->getPHID(),
|
||||
$comment_phid,
|
||||
1,
|
||||
PhabricatorTransactions::TYPE_COMMENT,
|
||||
null,
|
||||
null,
|
||||
$source,
|
||||
'{}',
|
||||
$date_created,
|
||||
$date_modified);
|
||||
}
|
||||
|
||||
$conn_w->saveTransaction();
|
||||
|
||||
echo "Done.\n";
|
|
@ -1536,6 +1536,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlowvotePollController' => 'applications/slowvote/controller/PhabricatorSlowvotePollController.php',
|
||||
'PhabricatorSlowvoteQuery' => 'applications/slowvote/query/PhabricatorSlowvoteQuery.php',
|
||||
'PhabricatorSlowvoteSearchEngine' => 'applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php',
|
||||
'PhabricatorSlowvoteTransaction' => 'applications/slowvote/storage/PhabricatorSlowvoteTransaction.php',
|
||||
'PhabricatorSlowvoteTransactionComment' => 'applications/slowvote/storage/PhabricatorSlowvoteTransactionComment.php',
|
||||
'PhabricatorSlowvoteTransactionQuery' => 'applications/slowvote/query/PhabricatorSlowvoteTransactionQuery.php',
|
||||
'PhabricatorSlowvoteVoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteVoteController.php',
|
||||
'PhabricatorSlug' => 'infrastructure/util/PhabricatorSlug.php',
|
||||
'PhabricatorSlugTestCase' => 'infrastructure/util/__tests__/PhabricatorSlugTestCase.php',
|
||||
|
@ -3500,6 +3503,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController',
|
||||
'PhabricatorSlowvoteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorSlowvoteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorSlowvoteTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'PhabricatorSlowvoteTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
'PhabricatorSlowvoteTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhabricatorSlowvoteVoteController' => 'PhabricatorSlowvoteController',
|
||||
'PhabricatorSlugTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorSortTableExample' => 'PhabricatorUIExample',
|
||||
|
|
|
@ -9,6 +9,7 @@ final class PhabricatorContentSource {
|
|||
const SOURCE_MOBILE = 'mobile';
|
||||
const SOURCE_TABLET = 'tablet';
|
||||
const SOURCE_FAX = 'fax';
|
||||
const SOURCE_LEGACY = 'legacy';
|
||||
|
||||
private $source;
|
||||
private $params = array();
|
||||
|
|
|
@ -13,19 +13,20 @@ final class PhabricatorContentSourceView extends AphrontView {
|
|||
require_celerity_resource('phabricator-content-source-view-css');
|
||||
|
||||
$map = array(
|
||||
PhabricatorContentSource::SOURCE_WEB => 'Web',
|
||||
PhabricatorContentSource::SOURCE_CONDUIT => 'Conduit',
|
||||
PhabricatorContentSource::SOURCE_EMAIL => 'Email',
|
||||
PhabricatorContentSource::SOURCE_MOBILE => 'Mobile',
|
||||
PhabricatorContentSource::SOURCE_TABLET => 'Tablet',
|
||||
PhabricatorContentSource::SOURCE_FAX => 'Fax',
|
||||
PhabricatorContentSource::SOURCE_WEB => pht('Web'),
|
||||
PhabricatorContentSource::SOURCE_CONDUIT => pht('Conduit'),
|
||||
PhabricatorContentSource::SOURCE_EMAIL => pht('Email'),
|
||||
PhabricatorContentSource::SOURCE_MOBILE => pht('Mobile'),
|
||||
PhabricatorContentSource::SOURCE_TABLET => pht('Tablet'),
|
||||
PhabricatorContentSource::SOURCE_FAX => pht('Fax'),
|
||||
PhabricatorContentSource::SOURCE_LEGACY => pht('Old World'),
|
||||
);
|
||||
|
||||
$source = $this->contentSource->getSource();
|
||||
$type = idx($map, $source, null);
|
||||
|
||||
if (!$type) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return phutil_tag(
|
||||
|
|
|
@ -32,20 +32,10 @@ final class PhabricatorSlowvotePollController
|
|||
$choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
|
||||
'pollID = %d',
|
||||
$poll->getID());
|
||||
$comments = id(new PhabricatorSlowvoteComment())->loadAllWhere(
|
||||
'pollID = %d',
|
||||
$poll->getID());
|
||||
|
||||
$choices_by_option = mgroup($choices, 'getOptionID');
|
||||
$comments_by_user = mpull($comments, null, 'getAuthorPHID');
|
||||
$choices_by_user = mgroup($choices, 'getAuthorPHID');
|
||||
$viewer_choices = idx($choices_by_user, $viewer_phid, array());
|
||||
$viewer_comment = idx($comments_by_user, $viewer_phid, null);
|
||||
|
||||
$comment_text = null;
|
||||
if ($viewer_comment) {
|
||||
$comment_text = $viewer_comment->getCommentText();
|
||||
}
|
||||
|
||||
if ($request->isAjax()) {
|
||||
$embed = id(new SlowvoteEmbedView())
|
||||
|
@ -63,7 +53,6 @@ final class PhabricatorSlowvotePollController
|
|||
|
||||
$phids = array_merge(
|
||||
mpull($choices, 'getAuthorPHID'),
|
||||
mpull($comments, 'getAuthorPHID'),
|
||||
array(
|
||||
$poll->getAuthorPHID(),
|
||||
));
|
||||
|
@ -85,22 +74,14 @@ final class PhabricatorSlowvotePollController
|
|||
$option);
|
||||
}
|
||||
|
||||
$comments_by_option = array();
|
||||
switch ($poll->getMethod()) {
|
||||
case PhabricatorSlowvotePoll::METHOD_PLURALITY:
|
||||
$choice_ids = array();
|
||||
foreach ($choices_by_user as $user_phid => $user_choices) {
|
||||
$choice_ids[$user_phid] = head($user_choices)->getOptionID();
|
||||
}
|
||||
foreach ($comments as $comment) {
|
||||
$choice = idx($choice_ids, $comment->getAuthorPHID());
|
||||
if ($choice) {
|
||||
$comments_by_option[$choice][] = $comment;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PhabricatorSlowvotePoll::METHOD_APPROVAL:
|
||||
// All comments are grouped in approval voting.
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown poll method!");
|
||||
|
@ -110,10 +91,8 @@ final class PhabricatorSlowvotePollController
|
|||
$poll,
|
||||
$options,
|
||||
$choices,
|
||||
$comments,
|
||||
$viewer_choices,
|
||||
$choices_by_option,
|
||||
$comments_by_option,
|
||||
$handles,
|
||||
$objects);
|
||||
|
||||
|
@ -139,12 +118,6 @@ final class PhabricatorSlowvotePollController
|
|||
id(new AphrontFormMarkupControl())
|
||||
->setLabel(pht('Vote'))
|
||||
->setValue($option_markup))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextAreaControl())
|
||||
->setLabel(pht('Comments'))
|
||||
->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)
|
||||
->setName('comments')
|
||||
->setValue($comment_text))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Engage in Deliberations')));
|
||||
|
@ -166,11 +139,14 @@ final class PhabricatorSlowvotePollController
|
|||
hsprintf('<br /><br />'),
|
||||
$panel);
|
||||
|
||||
$xactions = $this->buildTransactions($poll);
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
$crumbs,
|
||||
$header,
|
||||
$content,
|
||||
$xactions,
|
||||
),
|
||||
array(
|
||||
'title' => 'V'.$poll->getID().' '.$poll->getQuestion(),
|
||||
|
@ -179,51 +155,6 @@ final class PhabricatorSlowvotePollController
|
|||
));
|
||||
}
|
||||
|
||||
private function renderComments(array $comments, array $handles) {
|
||||
assert_instances_of($comments, 'PhabricatorSlowvoteComment');
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$engine = PhabricatorMarkupEngine::newSlowvoteMarkupEngine();
|
||||
$engine->setConfig('viewer', $viewer);
|
||||
|
||||
$comment_markup = array();
|
||||
foreach ($comments as $comment) {
|
||||
$handle = $handles[$comment->getAuthorPHID()];
|
||||
|
||||
$markup = $engine->markupText($comment->getCommentText());
|
||||
|
||||
require_celerity_resource('phabricator-remarkup-css');
|
||||
|
||||
$comment_markup[] = hsprintf(
|
||||
'<tr>'.
|
||||
'<th>'.
|
||||
'%s'.
|
||||
'<div class="phabricator-slowvote-datestamp">%s</div>'.
|
||||
'</th>'.
|
||||
'<td>'.
|
||||
'<div class="phabricator-remarkup">%s</div>'.
|
||||
'</td>'.
|
||||
'</tr>',
|
||||
$handle->renderLink(),
|
||||
phabricator_datetime($comment->getDateCreated(), $viewer),
|
||||
$markup);
|
||||
}
|
||||
|
||||
if ($comment_markup) {
|
||||
$comment_markup = phutil_tag(
|
||||
'table',
|
||||
array(
|
||||
'class' => 'phabricator-slowvote-comments',
|
||||
),
|
||||
$comment_markup);
|
||||
} else {
|
||||
$comment_markup = null;
|
||||
}
|
||||
|
||||
return $comment_markup;
|
||||
}
|
||||
|
||||
private function renderPollOption(
|
||||
PhabricatorSlowvotePoll $poll,
|
||||
|
@ -330,15 +261,12 @@ final class PhabricatorSlowvotePollController
|
|||
PhabricatorSlowvotePoll $poll,
|
||||
array $options,
|
||||
array $choices,
|
||||
array $comments,
|
||||
array $viewer_choices,
|
||||
array $choices_by_option,
|
||||
array $comments_by_option,
|
||||
array $handles,
|
||||
array $objects) {
|
||||
assert_instances_of($options, 'PhabricatorSlowvoteOption');
|
||||
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
|
||||
assert_instances_of($comments, 'PhabricatorSlowvoteComment');
|
||||
assert_instances_of($viewer_choices, 'PhabricatorSlowvoteChoice');
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
assert_instances_of($objects, 'PhabricatorLiskDAO');
|
||||
|
@ -407,10 +335,6 @@ final class PhabricatorSlowvotePollController
|
|||
$user_markup = pht('This option has failed to appeal to anyone.');
|
||||
}
|
||||
|
||||
$comment_markup = $this->renderComments(
|
||||
idx($comments_by_option, $id, array()),
|
||||
$handles);
|
||||
|
||||
$vote_count = $this->renderVoteCount(
|
||||
$poll,
|
||||
$choices,
|
||||
|
@ -422,26 +346,42 @@ final class PhabricatorSlowvotePollController
|
|||
'<h1>%s</h1>'.
|
||||
'<hr class="phabricator-slowvote-hr" />'.
|
||||
'%s'.
|
||||
'<div style="clear: both;" />'.
|
||||
'<div style="clear: both;"></div>'.
|
||||
'<hr class="phabricator-slowvote-hr" />'.
|
||||
'%s'.
|
||||
'</div>',
|
||||
$vote_count,
|
||||
$option->getName(),
|
||||
phutil_tag('div', array(), $user_markup),
|
||||
$comment_markup));
|
||||
}
|
||||
|
||||
if ($poll->getMethod() == PhabricatorSlowvotePoll::METHOD_APPROVAL &&
|
||||
$comments) {
|
||||
$comment_markup = $this->renderComments(
|
||||
$comments,
|
||||
$handles);
|
||||
$result_markup->appendChild(
|
||||
phutil_tag('h1', array(), pht('Motions Proposed for Consideration')));
|
||||
$result_markup->appendChild($comment_markup);
|
||||
phutil_tag('div', array(), $user_markup)));
|
||||
}
|
||||
|
||||
return $result_markup;
|
||||
}
|
||||
|
||||
private function buildTransactions(PhabricatorSlowvotePoll $poll) {
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$xactions = id(new PhabricatorSlowvoteTransactionQuery())
|
||||
->setViewer($viewer)
|
||||
->withObjectPHIDs(array($poll->getPHID()))
|
||||
->execute();
|
||||
|
||||
$engine = id(new PhabricatorMarkupEngine())
|
||||
->setViewer($viewer);
|
||||
foreach ($xactions as $xaction) {
|
||||
if ($xaction->getComment()) {
|
||||
$engine->addObject(
|
||||
$xaction->getComment(),
|
||||
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
|
||||
}
|
||||
}
|
||||
$engine->process();
|
||||
|
||||
$timeline = id(new PhabricatorApplicationTransactionView())
|
||||
->setUser($viewer)
|
||||
->setTransactions($xactions)
|
||||
->setMarkupEngine($engine);
|
||||
|
||||
return $timeline;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,33 +32,6 @@ final class PhabricatorSlowvoteVoteController
|
|||
$poll->getID(),
|
||||
$user->getPHID());
|
||||
|
||||
$comment_text = $request->getStr('comments');
|
||||
$old_comment = id(new PhabricatorSlowvoteComment())->loadOneWhere(
|
||||
'pollID = %d AND authorPHID = %s',
|
||||
$poll->getID(),
|
||||
$user->getPHID());
|
||||
|
||||
$update_comment = false;
|
||||
if ($old_comment && $comment_text &&
|
||||
$old_comment->getCommentText() !== $comment_text) {
|
||||
|
||||
$update_comment = true;
|
||||
} else if (!$old_comment && $comment_text) {
|
||||
$update_comment = true;
|
||||
}
|
||||
|
||||
if ($update_comment) {
|
||||
if ($old_comment) {
|
||||
$old_comment->delete();
|
||||
}
|
||||
|
||||
id(new PhabricatorSlowvoteComment())
|
||||
->setAuthorPHID($user->getPHID())
|
||||
->setPollID($poll->getID())
|
||||
->setCommentText($comment_text)
|
||||
->save();
|
||||
}
|
||||
|
||||
$old_votes = mpull($user_choices, null, 'getOptionID');
|
||||
|
||||
if ($request->isAjax()) {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorSlowvoteTransactionQuery
|
||||
extends PhabricatorApplicationTransactionQuery {
|
||||
|
||||
protected function getTemplateApplicationTransaction() {
|
||||
return new PhabricatorSlowvoteTransaction();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ final class PhabricatorSlowvoteTransaction
|
|||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return new PhabricatorMacroTransactionComment();
|
||||
return new PhabricatorSlowvoteTransactionComment();
|
||||
}
|
||||
|
||||
public function getApplicationObjectTypeName() {
|
||||
|
|
|
@ -1446,6 +1446,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
|||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('20130714.votexactions.sql'),
|
||||
),
|
||||
'20130715.votecomments.php' => array(
|
||||
'type' => 'php',
|
||||
'name' => $this->getPatchPath('20130715.votecomments.php'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue