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

Use standard infrastructure to attach commits to other objects

Summary:
Ref T4896. Now that we have a transaction editor, we can delete a giant block of hacks.

I believe this also resolves the commit/task attachment issues @joshuaspence and @mbishopim3 mentioned.

Test Plan: Attached and detached commits and tasks.

Reviewers: btrahan, joshuaspence, mbishopim3

Reviewed By: mbishopim3

Subscribers: mbishopim3, epriestley, joshuaspence

Maniphest Tasks: T4896

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

+71 -66
+1
src/__phutil_library_map__.php
··· 4851 4851 'PhabricatorSubscribableInterface', 4852 4852 'HarbormasterBuildableInterface', 4853 4853 'PhabricatorCustomFieldInterface', 4854 + 'PhabricatorApplicationTransactionInterface', 4854 4855 ), 4855 4856 'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker', 4856 4857 'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO',
+17
src/applications/audit/editor/PhabricatorAuditEditor.php
··· 7 7 $types = parent::getTransactionTypes(); 8 8 9 9 $types[] = PhabricatorTransactions::TYPE_COMMENT; 10 + $types[] = PhabricatorTransactions::TYPE_EDGE; 10 11 11 12 // TODO: These will get modernized eventually, but that can happen one 12 13 // at a time later on. ··· 66 67 switch ($xaction->getTransactionType()) { 67 68 case PhabricatorTransactions::TYPE_COMMENT: 68 69 case PhabricatorTransactions::TYPE_SUBSCRIBERS: 70 + case PhabricatorTransactions::TYPE_EDGE: 69 71 case PhabricatorAuditActionConstants::ACTION: 70 72 case PhabricatorAuditActionConstants::INLINE: 71 73 case PhabricatorAuditActionConstants::ADD_AUDITORS: ··· 82 84 switch ($xaction->getTransactionType()) { 83 85 case PhabricatorTransactions::TYPE_COMMENT: 84 86 case PhabricatorTransactions::TYPE_SUBSCRIBERS: 87 + case PhabricatorTransactions::TYPE_EDGE: 85 88 case PhabricatorAuditActionConstants::ACTION: 86 89 case PhabricatorAuditActionConstants::INLINE: 87 90 return; ··· 129 132 protected function applyFinalEffects( 130 133 PhabricatorLiskDAO $object, 131 134 array $xactions) { 135 + 136 + // Load auditors explicitly; we may not have them if the caller was a 137 + // generic piece of infrastructure. 138 + 139 + $commit = id(new DiffusionCommitQuery()) 140 + ->setViewer($this->requireActor()) 141 + ->withIDs(array($object->getID())) 142 + ->needAuditRequests(true) 143 + ->executeOne(); 144 + if (!$commit) { 145 + throw new Exception( 146 + pht('Failed to load commit during transaction finalization!')); 147 + } 148 + $object->attachAudits($commit->getAudits()); 132 149 133 150 $status_concerned = PhabricatorAuditStatusConstants::CONCERNED; 134 151 $status_closed = PhabricatorAuditStatusConstants::CLOSED;
+5 -3
src/applications/diffusion/edge/DiffusionCommitHasTaskEdgeType.php
··· 5 5 const EDGECONST = 2; 6 6 7 7 public function shouldWriteInverseTransactions() { 8 - // TODO: This should happen after T4896, but Diffusion does not support 9 - // transactions yet. 10 - return false; 8 + return true; 9 + } 10 + 11 + public function getInverseEdgeConstant() { 12 + return ManiphestTaskHasCommitEdgeType::EDGECONST; 11 13 } 12 14 13 15 public function getTransactionAddString(
+5 -3
src/applications/maniphest/edge/ManiphestTaskHasCommitEdgeType.php
··· 5 5 const EDGECONST = 1; 6 6 7 7 public function shouldWriteInverseTransactions() { 8 - // TODO: This should happen after T4896, but Diffusion does not support 9 - // transactions yet. 10 - return false; 8 + return true; 9 + } 10 + 11 + public function getInverseEdgeConstant() { 12 + return DiffusionCommitHasTaskEdgeType::EDGECONST; 11 13 } 12 14 13 15 public function getTransactionAddString(
+18 -1
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 8 8 PhabricatorTokenReceiverInterface, 9 9 PhabricatorSubscribableInterface, 10 10 HarbormasterBuildableInterface, 11 - PhabricatorCustomFieldInterface { 11 + PhabricatorCustomFieldInterface, 12 + PhabricatorApplicationTransactionInterface { 12 13 13 14 protected $repositoryID; 14 15 protected $phid; ··· 349 350 350 351 public function shouldAllowSubscription($phid) { 351 352 return true; 353 + } 354 + 355 + 356 + /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 357 + 358 + 359 + public function getApplicationTransactionEditor() { 360 + return new PhabricatorAuditEditor(); 361 + } 362 + 363 + public function getApplicationTransactionObject() { 364 + return $this; 365 + } 366 + 367 + public function getApplicationTransactionTemplate() { 368 + return new PhabricatorAuditTransaction(); 352 369 } 353 370 354 371 }
+25 -59
src/applications/search/controller/PhabricatorSearchAttachController.php
··· 57 57 $phids = array_values($phids); 58 58 59 59 if ($edge_type) { 60 - if ($object instanceof PhabricatorRepositoryCommit) { 61 - // TODO: Remove this entire branch of special cased grossness 62 - // after T4896. 63 - 64 - $old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 65 - $this->phid, 66 - $edge_type); 67 - $add_phids = $phids; 68 - $rem_phids = array_diff($old_phids, $add_phids); 69 - 70 - // Doing this correctly (in a way that writes edge transactions) would 71 - // be a huge mess and we don't get the commit half of the transaction 72 - // anyway until T4896, so just write the edges themselves and skip 73 - // the transactions for now. 74 - 75 - $editor = new PhabricatorEdgeEditor(); 76 - foreach ($add_phids as $phid) { 77 - $editor->addEdge( 78 - $object->getPHID(), 79 - DiffusionCommitHasTaskEdgeType::EDGECONST, 80 - $phid); 81 - } 82 - 83 - foreach ($rem_phids as $phid) { 84 - $editor->removeEdge( 85 - $object->getPHID(), 86 - DiffusionCommitHasTaskEdgeType::EDGECONST, 87 - $phid); 88 - } 89 - 90 - $editor->save(); 91 - 92 - } else { 93 - if (!$object instanceof PhabricatorApplicationTransactionInterface) { 94 - throw new Exception( 95 - pht( 96 - 'Expected object ("%s") to implement interface "%s".', 97 - get_class($object), 98 - 'PhabricatorApplicationTransactionInterface')); 99 - } 60 + if (!$object instanceof PhabricatorApplicationTransactionInterface) { 61 + throw new Exception( 62 + pht( 63 + 'Expected object ("%s") to implement interface "%s".', 64 + get_class($object), 65 + 'PhabricatorApplicationTransactionInterface')); 66 + } 100 67 101 - $old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 102 - $this->phid, 103 - $edge_type); 104 - $add_phids = $phids; 105 - $rem_phids = array_diff($old_phids, $add_phids); 68 + $old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 69 + $this->phid, 70 + $edge_type); 71 + $add_phids = $phids; 72 + $rem_phids = array_diff($old_phids, $add_phids); 106 73 107 - $txn_editor = $object->getApplicationTransactionEditor() 108 - ->setActor($user) 109 - ->setContentSourceFromRequest($request) 110 - ->setContinueOnMissingFields(true); 74 + $txn_editor = $object->getApplicationTransactionEditor() 75 + ->setActor($user) 76 + ->setContentSourceFromRequest($request) 77 + ->setContinueOnMissingFields(true); 111 78 112 - $txn_template = $object->getApplicationTransactionTemplate() 113 - ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 114 - ->setMetadataValue('edge:type', $edge_type) 115 - ->setNewValue(array( 116 - '+' => array_fuse($add_phids), 117 - '-' => array_fuse($rem_phids))); 118 - $txn_editor->applyTransactions( 119 - $object->getApplicationTransactionObject(), 120 - array($txn_template)); 121 - } 79 + $txn_template = $object->getApplicationTransactionTemplate() 80 + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 81 + ->setMetadataValue('edge:type', $edge_type) 82 + ->setNewValue(array( 83 + '+' => array_fuse($add_phids), 84 + '-' => array_fuse($rem_phids))); 85 + $txn_editor->applyTransactions( 86 + $object->getApplicationTransactionObject(), 87 + array($txn_template)); 122 88 123 89 return id(new AphrontReloadResponse())->setURI($handle->getURI()); 124 90 } else {