Differential D12126 Diff 29185 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; | |||||
| 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) { | |||||
| switch ($xaction->getTransactionType()) { | |||||
| case PhabricatorTransactions::TYPE_COMMENT: | |||||
| case DifferentialTransaction::TYPE_ACTION: | |||||
| case DifferentialTransaction::TYPE_UPDATE: | |||||
| case DifferentialTransaction::TYPE_INLINE: | |||||
| $this->expandedDone = true; | |||||
| $actor_phid = $this->getActingAsPHID(); | |||||
| $actor_is_author = ($object->getAuthorPHID() == $actor_phid); | |||||
| if (!$actor_is_author) { | |||||
| break; | |||||
| } | |||||
| $state_map = array( | |||||
| PhabricatorInlineCommentInterface::STATE_DRAFT => | |||||
| PhabricatorInlineCommentInterface::STATE_DONE, | |||||
| PhabricatorInlineCommentInterface::STATE_UNDRAFT => | |||||
| PhabricatorInlineCommentInterface::STATE_UNDONE, | |||||
| ); | |||||
| $inlines = id(new DifferentialDiffInlineCommentQuery()) | |||||
| ->setViewer($this->getActor()) | |||||
| ->withRevisionPHIDs(array($object->getPHID())) | |||||
| ->withFixedStates(array_keys($state_map)) | |||||
| ->execute(); | |||||
| if (!$inlines) { | |||||
| break; | |||||
| } | |||||
| $old_value = mpull($inlines, 'getFixedState', 'getPHID'); | |||||
| $new_value = array(); | |||||
| foreach ($old_value as $key => $state) { | |||||
| $new_value[$key] = $state_map[$state]; | |||||
| } | |||||
| $results[] = id(new DifferentialTransaction()) | |||||
| ->setTransactionType(DifferentialTransaction::TYPE_INLINEDONE) | |||||
| ->setIgnoreOnNoEffect(true) | |||||
| ->setOldValue($old_value) | |||||
| ->setNewValue($new_value); | |||||
| break; | |||||
| } | |||||
| } | |||||
| return $results; | return $results; | ||||
| } | } | ||||
| protected function applyCustomExternalTransaction( | protected function applyCustomExternalTransaction( | ||||
| 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: | ||||
| return; | return; | ||||
| case PhabricatorTransactions::TYPE_SUBSCRIBERS: | case PhabricatorTransactions::TYPE_SUBSCRIBERS: | ||||
| case PhabricatorTransactions::TYPE_EDGE: | case PhabricatorTransactions::TYPE_EDGE: | ||||
| case PhabricatorTransactions::TYPE_COMMENT: | case PhabricatorTransactions::TYPE_COMMENT: | ||||
| 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. | ||||
| ▲ Show 20 Lines • Show All 1,321 Lines • Show Last 20 Lines | |||||