mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Wrap edge transaction readers in a translation layer
Summary: Ref T13051. This puts a translation layer between the raw edge data in the transaction table and the UI that uses it. The intent is to start writing new, more compact data soon. This class give us a consistent API for interacting with either the new or old data format, so we don't have to migrate everything upfront. Test Plan: Browsed around, saw existing edge transactions render properly in transactions and feed. Added and removed subscribers and projects, saw good transaction rendering. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13051 Differential Revision: https://secure.phabricator.com/D18946
This commit is contained in:
parent
162563d40b
commit
de7f836f03
4 changed files with 82 additions and 26 deletions
|
@ -2747,6 +2747,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDraftEngine' => 'applications/transactions/draft/PhabricatorDraftEngine.php',
|
'PhabricatorDraftEngine' => 'applications/transactions/draft/PhabricatorDraftEngine.php',
|
||||||
'PhabricatorDraftInterface' => 'applications/transactions/draft/PhabricatorDraftInterface.php',
|
'PhabricatorDraftInterface' => 'applications/transactions/draft/PhabricatorDraftInterface.php',
|
||||||
'PhabricatorDrydockApplication' => 'applications/drydock/application/PhabricatorDrydockApplication.php',
|
'PhabricatorDrydockApplication' => 'applications/drydock/application/PhabricatorDrydockApplication.php',
|
||||||
|
'PhabricatorEdgeChangeRecord' => 'infrastructure/edges/util/PhabricatorEdgeChangeRecord.php',
|
||||||
'PhabricatorEdgeConfig' => 'infrastructure/edges/constants/PhabricatorEdgeConfig.php',
|
'PhabricatorEdgeConfig' => 'infrastructure/edges/constants/PhabricatorEdgeConfig.php',
|
||||||
'PhabricatorEdgeConstants' => 'infrastructure/edges/constants/PhabricatorEdgeConstants.php',
|
'PhabricatorEdgeConstants' => 'infrastructure/edges/constants/PhabricatorEdgeConstants.php',
|
||||||
'PhabricatorEdgeCycleException' => 'infrastructure/edges/exception/PhabricatorEdgeCycleException.php',
|
'PhabricatorEdgeCycleException' => 'infrastructure/edges/exception/PhabricatorEdgeCycleException.php',
|
||||||
|
@ -8170,6 +8171,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDraftDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorDraftDAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorDraftEngine' => 'Phobject',
|
'PhabricatorDraftEngine' => 'Phobject',
|
||||||
'PhabricatorDrydockApplication' => 'PhabricatorApplication',
|
'PhabricatorDrydockApplication' => 'PhabricatorApplication',
|
||||||
|
'PhabricatorEdgeChangeRecord' => 'Phobject',
|
||||||
'PhabricatorEdgeConfig' => 'PhabricatorEdgeConstants',
|
'PhabricatorEdgeConfig' => 'PhabricatorEdgeConstants',
|
||||||
'PhabricatorEdgeConstants' => 'Phobject',
|
'PhabricatorEdgeConstants' => 'Phobject',
|
||||||
'PhabricatorEdgeCycleException' => 'Exception',
|
'PhabricatorEdgeCycleException' => 'Exception',
|
||||||
|
|
|
@ -87,19 +87,6 @@ final class DifferentialTransaction
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PhabricatorTransactions::TYPE_EDGE:
|
|
||||||
$add = array_diff_key($new, $old);
|
|
||||||
$rem = array_diff_key($old, $new);
|
|
||||||
|
|
||||||
// Hide metadata-only edge transactions. These correspond to users
|
|
||||||
// accepting or rejecting revisions, but the change is always explicit
|
|
||||||
// because of the TYPE_ACTION transaction. Rendering these transactions
|
|
||||||
// just creates clutter.
|
|
||||||
|
|
||||||
if (!$add && !$rem) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DifferentialRevisionRequestReviewTransaction::TRANSACTIONTYPE:
|
case DifferentialRevisionRequestReviewTransaction::TRANSACTIONTYPE:
|
||||||
// Don't hide the initial "X requested review: ..." transaction from
|
// Don't hide the initial "X requested review: ..." transaction from
|
||||||
// mail or feed even when it occurs during creation. We need this
|
// mail or feed even when it occurs during creation. We need this
|
||||||
|
|
|
@ -302,8 +302,8 @@ abstract class PhabricatorApplicationTransaction
|
||||||
$phids[] = $new;
|
$phids[] = $new;
|
||||||
break;
|
break;
|
||||||
case PhabricatorTransactions::TYPE_EDGE:
|
case PhabricatorTransactions::TYPE_EDGE:
|
||||||
$phids[] = ipull($old, 'dst');
|
$record = PhabricatorEdgeChangeRecord::newFromTransaction($this);
|
||||||
$phids[] = ipull($new, 'dst');
|
$phids[] = $record->getChangedPHIDs();
|
||||||
break;
|
break;
|
||||||
case PhabricatorTransactions::TYPE_COLUMNS:
|
case PhabricatorTransactions::TYPE_COLUMNS:
|
||||||
foreach ($new as $move) {
|
foreach ($new as $move) {
|
||||||
|
@ -632,9 +632,8 @@ abstract class PhabricatorApplicationTransaction
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case PhabricatorObjectMentionedByObjectEdgeType::EDGECONST:
|
case PhabricatorObjectMentionedByObjectEdgeType::EDGECONST:
|
||||||
$new = ipull($this->getNewValue(), 'dst');
|
$record = PhabricatorEdgeChangeRecord::newFromTransaction($this);
|
||||||
$old = ipull($this->getOldValue(), 'dst');
|
$add = $record->getAddedPHIDs();
|
||||||
$add = array_diff($new, $old);
|
|
||||||
$add_value = reset($add);
|
$add_value = reset($add);
|
||||||
$add_handle = $this->getHandle($add_value);
|
$add_handle = $this->getHandle($add_value);
|
||||||
if ($add_handle->getPolicyFiltered()) {
|
if ($add_handle->getPolicyFiltered()) {
|
||||||
|
@ -933,10 +932,10 @@ abstract class PhabricatorApplicationTransaction
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PhabricatorTransactions::TYPE_EDGE:
|
case PhabricatorTransactions::TYPE_EDGE:
|
||||||
$new = ipull($new, 'dst');
|
$record = PhabricatorEdgeChangeRecord::newFromTransaction($this);
|
||||||
$old = ipull($old, 'dst');
|
$add = $record->getAddedPHIDs();
|
||||||
$add = array_diff($new, $old);
|
$rem = $record->getRemovedPHIDs();
|
||||||
$rem = array_diff($old, $new);
|
|
||||||
$type = $this->getMetadata('edge:type');
|
$type = $this->getMetadata('edge:type');
|
||||||
$type = head($type);
|
$type = head($type);
|
||||||
|
|
||||||
|
@ -1172,10 +1171,10 @@ abstract class PhabricatorApplicationTransaction
|
||||||
$this->renderHandleLink($new));
|
$this->renderHandleLink($new));
|
||||||
}
|
}
|
||||||
case PhabricatorTransactions::TYPE_EDGE:
|
case PhabricatorTransactions::TYPE_EDGE:
|
||||||
$new = ipull($new, 'dst');
|
$record = PhabricatorEdgeChangeRecord::newFromTransaction($this);
|
||||||
$old = ipull($old, 'dst');
|
$add = $record->getAddedPHIDs();
|
||||||
$add = array_diff($new, $old);
|
$rem = $record->getRemovedPHIDs();
|
||||||
$rem = array_diff($old, $new);
|
|
||||||
$type = $this->getMetadata('edge:type');
|
$type = $this->getMetadata('edge:type');
|
||||||
$type = head($type);
|
$type = head($type);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorEdgeChangeRecord
|
||||||
|
extends Phobject {
|
||||||
|
|
||||||
|
private $xaction;
|
||||||
|
|
||||||
|
public static function newFromTransaction(
|
||||||
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
$record = new self();
|
||||||
|
$record->xaction = $xaction;
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChangedPHIDs() {
|
||||||
|
$add = $this->getAddedPHIDs();
|
||||||
|
$rem = $this->getRemovedPHIDs();
|
||||||
|
|
||||||
|
$add = array_fuse($add);
|
||||||
|
$rem = array_fuse($rem);
|
||||||
|
|
||||||
|
return array_keys($add + $rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddedPHIDs() {
|
||||||
|
$old = $this->getOldDestinationPHIDs();
|
||||||
|
$new = $this->getNewDestinationPHIDs();
|
||||||
|
|
||||||
|
$old = array_fuse($old);
|
||||||
|
$new = array_fuse($new);
|
||||||
|
|
||||||
|
$add = array_diff_key($new, $old);
|
||||||
|
return array_keys($add);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRemovedPHIDs() {
|
||||||
|
$old = $this->getOldDestinationPHIDs();
|
||||||
|
$new = $this->getNewDestinationPHIDs();
|
||||||
|
|
||||||
|
$old = array_fuse($old);
|
||||||
|
$new = array_fuse($new);
|
||||||
|
|
||||||
|
$rem = array_diff_key($old, $new);
|
||||||
|
return array_keys($rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getOldDestinationPHIDs() {
|
||||||
|
if ($this->xaction) {
|
||||||
|
$old = $this->xaction->getOldValue();
|
||||||
|
return ipull($old, 'dst');
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception(
|
||||||
|
pht('Edge change record is not configured with any change data.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getNewDestinationPHIDs() {
|
||||||
|
if ($this->xaction) {
|
||||||
|
$new = $this->xaction->getNewValue();
|
||||||
|
return ipull($new, 'dst');
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception(
|
||||||
|
pht('Edge change record is not configured with any change data.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue