Differential D12130 Diff 29187 src/applications/differential/editor/DifferentialTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/editor/DifferentialTransactionEditor.php
<?php | <?php | ||||
final class DifferentialTransactionEditor | final class DifferentialTransactionEditor | ||||
extends PhabricatorApplicationTransactionEditor { | extends PhabricatorApplicationTransactionEditor { | ||||
private $heraldEmailPHIDs; | private $heraldEmailPHIDs; | ||||
private $changedPriorToCommitURI; | private $changedPriorToCommitURI; | ||||
private $isCloseByCommit; | private $isCloseByCommit; | ||||
private $repositoryPHIDOverride = false; | private $repositoryPHIDOverride = false; | ||||
private $expandedDone = false; | private $didExpandInlineState = false; | ||||
public function getEditorApplicationClass() { | public function getEditorApplicationClass() { | ||||
return 'PhabricatorDifferentialApplication'; | return 'PhabricatorDifferentialApplication'; | ||||
} | } | ||||
public function getEditorObjectsDescription() { | public function getEditorObjectsDescription() { | ||||
return pht('Differential Revisions'); | return pht('Differential Revisions'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | protected function getCustomTransactionNewValue( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_VIEW_POLICY: | case PhabricatorTransactions::TYPE_VIEW_POLICY: | ||||
case PhabricatorTransactions::TYPE_EDIT_POLICY: | case PhabricatorTransactions::TYPE_EDIT_POLICY: | ||||
case DifferentialTransaction::TYPE_ACTION: | case DifferentialTransaction::TYPE_ACTION: | ||||
case DifferentialTransaction::TYPE_UPDATE: | case DifferentialTransaction::TYPE_UPDATE: | ||||
case DifferentialTransaction::TYPE_INLINEDONE: | |||||
return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
case DifferentialTransaction::TYPE_INLINE: | case DifferentialTransaction::TYPE_INLINE: | ||||
return null; | return null; | ||||
} | } | ||||
return parent::getCustomTransactionNewValue($object, $xaction); | return parent::getCustomTransactionNewValue($object, $xaction); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | switch ($xaction->getTransactionType()) { | ||||
$object->setViewPolicy($xaction->getNewValue()); | $object->setViewPolicy($xaction->getNewValue()); | ||||
return; | return; | ||||
case PhabricatorTransactions::TYPE_EDIT_POLICY: | case PhabricatorTransactions::TYPE_EDIT_POLICY: | ||||
$object->setEditPolicy($xaction->getNewValue()); | $object->setEditPolicy($xaction->getNewValue()); | ||||
return; | return; | ||||
case PhabricatorTransactions::TYPE_SUBSCRIBERS: | case PhabricatorTransactions::TYPE_SUBSCRIBERS: | ||||
case PhabricatorTransactions::TYPE_COMMENT: | case PhabricatorTransactions::TYPE_COMMENT: | ||||
case DifferentialTransaction::TYPE_INLINE: | case DifferentialTransaction::TYPE_INLINE: | ||||
case DifferentialTransaction::TYPE_INLINEDONE: | |||||
return; | return; | ||||
case PhabricatorTransactions::TYPE_EDGE: | case PhabricatorTransactions::TYPE_EDGE: | ||||
return; | return; | ||||
case DifferentialTransaction::TYPE_UPDATE: | case DifferentialTransaction::TYPE_UPDATE: | ||||
if (!$this->getIsCloseByCommit() && | if (!$this->getIsCloseByCommit() && | ||||
(($object->getStatus() == $status_revision) || | (($object->getStatus() == $status_revision) || | ||||
($object->getStatus() == $status_plan))) { | ($object->getStatus() == $status_plan))) { | ||||
$object->setStatus($status_review); | $object->setStatus($status_review); | ||||
▲ Show 20 Lines • Show All 311 Lines • ▼ Show 20 Lines | switch ($xaction->getTransactionType()) { | ||||
), | ), | ||||
)); | )); | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
if (!$this->expandedDone) { | if (!$this->didExpandInlineState) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_COMMENT: | case PhabricatorTransactions::TYPE_COMMENT: | ||||
case DifferentialTransaction::TYPE_ACTION: | case DifferentialTransaction::TYPE_ACTION: | ||||
case DifferentialTransaction::TYPE_UPDATE: | case DifferentialTransaction::TYPE_UPDATE: | ||||
case DifferentialTransaction::TYPE_INLINE: | case DifferentialTransaction::TYPE_INLINE: | ||||
$this->expandedDone = true; | $this->didExpandInlineState = true; | ||||
$actor_phid = $this->getActingAsPHID(); | $actor_phid = $this->getActingAsPHID(); | ||||
$actor_is_author = ($object->getAuthorPHID() == $actor_phid); | $actor_is_author = ($object->getAuthorPHID() == $actor_phid); | ||||
if (!$actor_is_author) { | if (!$actor_is_author) { | ||||
break; | break; | ||||
} | } | ||||
$state_map = array( | $state_map = PhabricatorTransactions::getInlineStateMap(); | ||||
PhabricatorInlineCommentInterface::STATE_DRAFT => | |||||
PhabricatorInlineCommentInterface::STATE_DONE, | |||||
PhabricatorInlineCommentInterface::STATE_UNDRAFT => | |||||
PhabricatorInlineCommentInterface::STATE_UNDONE, | |||||
); | |||||
$inlines = id(new DifferentialDiffInlineCommentQuery()) | $inlines = id(new DifferentialDiffInlineCommentQuery()) | ||||
->setViewer($this->getActor()) | ->setViewer($this->getActor()) | ||||
->withRevisionPHIDs(array($object->getPHID())) | ->withRevisionPHIDs(array($object->getPHID())) | ||||
->withFixedStates(array_keys($state_map)) | ->withFixedStates(array_keys($state_map)) | ||||
->execute(); | ->execute(); | ||||
if (!$inlines) { | if (!$inlines) { | ||||
break; | break; | ||||
} | } | ||||
$old_value = mpull($inlines, 'getFixedState', 'getPHID'); | $old_value = mpull($inlines, 'getFixedState', 'getPHID'); | ||||
$new_value = array(); | $new_value = array(); | ||||
foreach ($old_value as $key => $state) { | foreach ($old_value as $key => $state) { | ||||
$new_value[$key] = $state_map[$state]; | $new_value[$key] = $state_map[$state]; | ||||
} | } | ||||
$results[] = id(new DifferentialTransaction()) | $results[] = id(new DifferentialTransaction()) | ||||
->setTransactionType(DifferentialTransaction::TYPE_INLINEDONE) | ->setTransactionType(PhabricatorTransactions::TYPE_INLINESTATE) | ||||
->setIgnoreOnNoEffect(true) | ->setIgnoreOnNoEffect(true) | ||||
->setOldValue($old_value) | ->setOldValue($old_value) | ||||
->setNewValue($new_value); | ->setNewValue($new_value); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return $results; | return $results; | ||||
Show All 13 Lines | switch ($xaction->getTransactionType()) { | ||||
case DifferentialTransaction::TYPE_ACTION: | case DifferentialTransaction::TYPE_ACTION: | ||||
return; | return; | ||||
case DifferentialTransaction::TYPE_INLINE: | case DifferentialTransaction::TYPE_INLINE: | ||||
$reply = $xaction->getComment()->getReplyToComment(); | $reply = $xaction->getComment()->getReplyToComment(); | ||||
if ($reply && !$reply->getHasReplies()) { | if ($reply && !$reply->getHasReplies()) { | ||||
$reply->setHasReplies(1)->save(); | $reply->setHasReplies(1)->save(); | ||||
} | } | ||||
return; | return; | ||||
case DifferentialTransaction::TYPE_INLINEDONE: | |||||
$table = new DifferentialTransactionComment(); | |||||
$conn_w = $table->establishConnection('w'); | |||||
foreach ($xaction->getNewValue() as $phid => $state) { | |||||
queryfx( | |||||
$conn_w, | |||||
'UPDATE %T SET fixedState = %s WHERE phid = %s', | |||||
$table->getTableName(), | |||||
$state, | |||||
$phid); | |||||
} | |||||
return; | |||||
case DifferentialTransaction::TYPE_UPDATE: | case DifferentialTransaction::TYPE_UPDATE: | ||||
// Now that we're inside the transaction, do a final check. | // Now that we're inside the transaction, do a final check. | ||||
$diff = $this->requireDiff($xaction->getNewValue()); | $diff = $this->requireDiff($xaction->getNewValue()); | ||||
// TODO: It would be slightly cleaner to just revalidate this | // TODO: It would be slightly cleaner to just revalidate this | ||||
// transaction somehow using the same validation code, but that's | // transaction somehow using the same validation code, but that's | ||||
// not easy to do at the moment. | // not easy to do at the moment. | ||||
$revision_id = $diff->getRevisionID(); | $revision_id = $diff->getRevisionID(); | ||||
if ($revision_id && ($revision_id != $object->getID())) { | if ($revision_id && ($revision_id != $object->getID())) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Diff is already attached to another revision. You lost '. | 'Diff is already attached to another revision. You lost '. | ||||
'a race?')); | 'a race?')); | ||||
} | } | ||||
$diff->setRevisionID($object->getID()); | $diff->setRevisionID($object->getID()); | ||||
$diff->save(); | $diff->save(); | ||||
return; | return; | ||||
} | } | ||||
return parent::applyCustomExternalTransaction($object, $xaction); | return parent::applyCustomExternalTransaction($object, $xaction); | ||||
} | } | ||||
protected function applyBuiltinExternalTransaction( | |||||
PhabricatorLiskDAO $object, | |||||
PhabricatorApplicationTransaction $xaction) { | |||||
switch ($xaction->getTransactionType()) { | |||||
case PhabricatorTransactions::TYPE_INLINESTATE: | |||||
$table = new DifferentialTransactionComment(); | |||||
$conn_w = $table->establishConnection('w'); | |||||
foreach ($xaction->getNewValue() as $phid => $state) { | |||||
queryfx( | |||||
$conn_w, | |||||
'UPDATE %T SET fixedState = %s WHERE phid = %s', | |||||
$table->getTableName(), | |||||
$state, | |||||
$phid); | |||||
} | |||||
return; | |||||
} | |||||
return parent::applyBuiltinExternalTransaction($object, $xaction); | |||||
} | |||||
protected function mergeEdgeData($type, array $u, array $v) { | protected function mergeEdgeData($type, array $u, array $v) { | ||||
$result = parent::mergeEdgeData($type, $u, $v); | $result = parent::mergeEdgeData($type, $u, $v); | ||||
switch ($type) { | switch ($type) { | ||||
case DifferentialRevisionHasReviewerEdgeType::EDGECONST: | case DifferentialRevisionHasReviewerEdgeType::EDGECONST: | ||||
// When the same reviewer has their status updated by multiple | // When the same reviewer has their status updated by multiple | ||||
// transactions, we want the strongest status to win. An example of | // transactions, we want the strongest status to win. An example of | ||||
// this is when a user adds a comment and also accepts a revision which | // this is when a user adds a comment and also accepts a revision which | ||||
▲ Show 20 Lines • Show All 1,297 Lines • Show Last 20 Lines |