mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
7ed6996604
Summary: See discussion in T2715. Currently, PHIDs are all hard coded in the PHID application. In the long run, we need to move them out into actual applications. A specific immediate issue is Releeph, which uses a very very old and very broken mechanism to inject PHIDs in a way that only sort of works. Moving forward, every PHID type will be provided by a `PhabricatorPHIDType` subclass, which will manage loading it, etc. This also moves toward cleaning up the "load objects by name" (where "name" means something like `D12`) code, which is an //enormous// mess and spread across at least 4-5 callsites. Test Plan: Used `phid.lookup` and `phid.query` to load Slowvotes. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D6502
101 lines
2.5 KiB
PHP
101 lines
2.5 KiB
PHP
<?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,
|
|
PhabricatorSlowvotePHIDTypePoll::TYPECONST);
|
|
|
|
$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";
|