diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -999,7 +999,31 @@ $xaction->setPHID($xaction->generatePHID()); $comment_editor->applyEdit($xaction, $xaction->getComment()); } else { - $xaction->save(); + + // TODO: This is a transitional hack to let us migrate edge + // transactions to a more efficient storage format. For now, we're + // going to write a new slim format to the database but keep the old + // bulky format on the objects so we don't have to upgrade all the + // edit logic to the new format yet. See T13051. + + $edge_type = PhabricatorTransactions::TYPE_EDGE; + if ($xaction->getTransactionType() == $edge_type) { + $bulky_old = $xaction->getOldValue(); + $bulky_new = $xaction->getNewValue(); + + $record = PhabricatorEdgeChangeRecord::newFromTransaction($xaction); + $slim_old = $record->getModernOldEdgeTransactionData(); + $slim_new = $record->getModernNewEdgeTransactionData(); + + $xaction->setOldValue($slim_old); + $xaction->setNewValue($slim_new); + $xaction->save(); + + $xaction->setOldValue($bulky_old); + $xaction->setNewValue($bulky_new); + } else { + $xaction->save(); + } } } diff --git a/src/infrastructure/edges/util/PhabricatorEdgeChangeRecord.php b/src/infrastructure/edges/util/PhabricatorEdgeChangeRecord.php --- a/src/infrastructure/edges/util/PhabricatorEdgeChangeRecord.php +++ b/src/infrastructure/edges/util/PhabricatorEdgeChangeRecord.php @@ -44,10 +44,18 @@ return array_keys($rem); } + public function getModernOldEdgeTransactionData() { + return $this->getRemovedPHIDs(); + } + + public function getModernNewEdgeTransactionData() { + return $this->getAddedPHIDs(); + } + private function getOldDestinationPHIDs() { if ($this->xaction) { $old = $this->xaction->getOldValue(); - return ipull($old, 'dst'); + return $this->getPHIDsFromTransactionValue($old); } throw new Exception( @@ -57,12 +65,27 @@ private function getNewDestinationPHIDs() { if ($this->xaction) { $new = $this->xaction->getNewValue(); - return ipull($new, 'dst'); + return $this->getPHIDsFromTransactionValue($new); } throw new Exception( pht('Edge change record is not configured with any change data.')); } + private function getPHIDsFromTransactionValue($value) { + if (!$value) { + return array(); + } + + // If the list items are arrays, this is an older-style map of + // dictionaries. + $head = head($value); + if (is_array($head)) { + return ipull($value, 'dst'); + } + + // If the list items are not arrays, this is a newer-style list of PHIDs. + return $value; + } }