Page MenuHomePhabricator

D18037.id43391.diff
No OneTemporary

D18037.id43391.diff

diff --git a/resources/sql/autopatches/20170528.maniphestdupes.php b/resources/sql/autopatches/20170528.maniphestdupes.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20170528.maniphestdupes.php
@@ -0,0 +1,64 @@
+<?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),
+ ));
+
+ $editor = $task->getApplicationTransactionEditor()
+ ->setActor($author)
+ ->setContentSource(id(new PhabricatorUnknownContentSource()))
+ ->setContinueOnMissingFields(true)
+ ->setContinueOnNoEffect(true);
+
+ $editor->applyTransactions($task, $xactions);
+}
diff --git a/src/applications/maniphest/controller/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/ManiphestTaskDetailController.php
--- a/src/applications/maniphest/controller/ManiphestTaskDetailController.php
+++ b/src/applications/maniphest/controller/ManiphestTaskDetailController.php
@@ -36,6 +36,7 @@
ManiphestTaskHasMockEdgeType::EDGECONST,
PhabricatorObjectMentionedByObjectEdgeType::EDGECONST,
PhabricatorObjectMentionsObjectEdgeType::EDGECONST,
+ ManiphestTaskHasDuplicateTaskEdgeType::EDGECONST,
);
$phid = $task->getPHID();
@@ -159,6 +160,7 @@
$related_tabs[] = $this->newMocksTab($task, $query);
$related_tabs[] = $this->newMentionsTab($task, $query);
+ $related_tabs[] = $this->newDuplicatesTab($task, $query);
$tab_view = null;
@@ -553,6 +555,32 @@
->appendChild($view);
}
+ private function newDuplicatesTab(
+ ManiphestTask $task,
+ PhabricatorEdgeQuery $edge_query) {
+
+ $in_type = ManiphestTaskHasDuplicateTaskEdgeType::EDGECONST;
+ $in_phids = $edge_query->getDestinationPHIDs(array(), array($in_type));
+
+ $viewer = $this->getViewer();
+ $in_handles = $viewer->loadHandles($in_phids);
+ $in_handles = $this->getCompleteHandles($in_handles);
+
+ $view = new PHUIPropertyListView();
+
+ if (!count($in_handles)) {
+ return null;
+ }
+
+ $view->addProperty(
+ pht('Duplicates Merged Here'), $in_handles->renderList());
+
+ return id(new PHUITabView())
+ ->setName(pht('Duplicates'))
+ ->setKey('duplicates')
+ ->appendChild($view);
+ }
+
private function getCompleteHandles(PhabricatorHandleList $handles) {
$phids = array();

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 26, 4:30 AM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7625279
Default Alt Text
D18037.id43391.diff (3 KB)

Event Timeline