Page MenuHomePhabricator
Paste P2055

migration.php
ActivePublic

Authored by amckinley on May 28 2017, 10:51 PM.
Tags
None
Referenced Files
F4981158: migration.php
May 28 2017, 10:51 PM
Subscribers
None
<?php
$viewer = PhabricatorUser::getOmnipotentUser();
// find all tasks with status = dupe
$tasks = id(new ManiphestTaskQuery())
->setViewer($viewer)
->withStatus('status-duplicate')
->execute();
foreach ($tasks as $task) {
// find the merge transaction
$merge_xaction = id(new ManiphestTransactionQuery())
->setViewer($viewer)
->withObjectPHIDs(array($task->getPHID()))
->withTransactionTypes(array('mergedinto'))
->needComments(true)
->executeOne();
// find the merge transaction's author to use as the viewer
$author_phid = $merge_xaction->getAuthorPHID();
$author = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withPHIDs(array($author_phid))
->executeOne();
// find the task we merged into
$target_phid = $merge_xaction->getNewValue();
$merged_into = id(new ManiphestTaskQuery())
->setViewer($viewer)
->withPHIDs(array($target_phid))
->executeOne();
// build the relationship object
$list = PhabricatorObjectRelationshipList::newForObject(
$author,
$task);
$relkey = ManiphestTaskCloseAsDuplicateRelationship::RELATIONSHIPKEY;
$relationship = $list->getRelationship($relkey)
->setContentSource(id (new PhabricatorUnknownContentSource()));
$edge_type = $relationship->getEdgeConstant();
// build the edge transactions
$add_phids = array($merged_into->getPHID());
$rem_phids = array();
$xactions = array();
$xactions[] = $task->getApplicationTransactionTemplate()
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', $edge_type)
->setNewValue(array(
'+' => array_fuse($add_phids),
'-' => array_fuse($rem_phids),
));
// // invoke willUpdateRelationships, which creates more transactions
// $add_objects = array($merged_into);
// $rem_objects = array();
// $more_xactions = $relationship->willUpdateRelationships(
// $task,
// $add_objects,
// $rem_objects);
// foreach ($more_xactions as $xaction) {
// $xactions[] = $xaction;
// }
$editor = $task->getApplicationTransactionEditor()
->setActor($author)
->setContentSource(id (new PhabricatorUnknownContentSource()))
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true);
// apply all the transactions we have so far
$editor->applyTransactions($task, $xactions);
// // invoke didUpdateRelationships, which applies its own transactions
// if ($add_objects || $rem_objects) {
// $relationship->didUpdateRelationships(
// $task,
// $add_objects,
// $rem_objects);
// }
}