Differential D17118 Diff 41175 src/applications/differential/editor/DifferentialTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/editor/DifferentialTransactionEditor.php
| Show First 20 Lines • Show All 282 Lines • ▼ Show 20 Lines | if ($this->getIsCloseByCommit()) { | ||||
| switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
| case DifferentialTransaction::TYPE_UPDATE: | case DifferentialTransaction::TYPE_UPDATE: | ||||
| $downgrade_rejects = true; | $downgrade_rejects = true; | ||||
| if (!$is_sticky_accept) { | if (!$is_sticky_accept) { | ||||
| // If "sticky accept" is disabled, also downgrade the accepts. | // If "sticky accept" is disabled, also downgrade the accepts. | ||||
| $downgrade_accepts = true; | $downgrade_accepts = true; | ||||
| } | } | ||||
| break; | break; | ||||
| case DifferentialRevisionRequestReviewTransaction::TRANSACTIONTYPE: | |||||
| $downgrade_rejects = true; | |||||
| if ((!$is_sticky_accept) || | |||||
| ($object->getStatus() != $status_plan)) { | |||||
| // If the old state isn't "changes planned", downgrade the accepts. | |||||
| // This exception allows an accepted revision to go through | |||||
| // "Plan Changes" -> "Request Review" and return to "accepted" if | |||||
| // the author didn't update the revision, essentially undoing the | |||||
| // "Plan Changes". | |||||
| $downgrade_accepts = true; | |||||
| } | |||||
| break; | |||||
| // TODO: Remove this, obsoleted by ModularTransactions above. | |||||
| case DifferentialTransaction::TYPE_ACTION: | case DifferentialTransaction::TYPE_ACTION: | ||||
| switch ($xaction->getNewValue()) { | switch ($xaction->getNewValue()) { | ||||
| case DifferentialAction::ACTION_REQUEST: | case DifferentialAction::ACTION_REQUEST: | ||||
| $downgrade_rejects = true; | $downgrade_rejects = true; | ||||
| if ((!$is_sticky_accept) || | if ((!$is_sticky_accept) || | ||||
| ($object->getStatus() != $status_plan)) { | ($object->getStatus() != $status_plan)) { | ||||
| // If the old state isn't "changes planned", downgrade the | |||||
| // accepts. This exception allows an accepted revision to | |||||
| // go through Plan Changes -> Request Review to return to | |||||
| // "accepted" if the author didn't update the revision. | |||||
| $downgrade_accepts = true; | $downgrade_accepts = true; | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| Show All 39 Lines | if ($downgrade_rejects || $downgrade_accepts) { | ||||
| $results[] = id(new DifferentialTransaction()) | $results[] = id(new DifferentialTransaction()) | ||||
| ->setTransactionType($type_edge) | ->setTransactionType($type_edge) | ||||
| ->setMetadataValue('edge:type', $edge_reviewer) | ->setMetadataValue('edge:type', $edge_reviewer) | ||||
| ->setIgnoreOnNoEffect(true) | ->setIgnoreOnNoEffect(true) | ||||
| ->setNewValue(array('+' => $edits)); | ->setNewValue(array('+' => $edits)); | ||||
| } | } | ||||
| } | } | ||||
| $is_commandeer = false; | |||||
| switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
| case DifferentialTransaction::TYPE_UPDATE: | case DifferentialTransaction::TYPE_UPDATE: | ||||
| if ($this->getIsCloseByCommit()) { | if ($this->getIsCloseByCommit()) { | ||||
| // Don't bother with any of this if this update is a side effect of | // Don't bother with any of this if this update is a side effect of | ||||
| // commit detection. | // commit detection. | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | switch ($xaction->getTransactionType()) { | ||||
| $results[] = id(new DifferentialTransaction()) | $results[] = id(new DifferentialTransaction()) | ||||
| ->setTransactionType($type_edge) | ->setTransactionType($type_edge) | ||||
| ->setMetadataValue('edge:type', $edge_reviewer) | ->setMetadataValue('edge:type', $edge_reviewer) | ||||
| ->setIgnoreOnNoEffect(true) | ->setIgnoreOnNoEffect(true) | ||||
| ->setNewValue(array('+' => $edits)); | ->setNewValue(array('+' => $edits)); | ||||
| } | } | ||||
| break; | break; | ||||
| case DifferentialRevisionCommandeerTransaction::TRANSACTIONTYPE: | |||||
| $is_commandeer = true; | |||||
| break; | |||||
| case DifferentialTransaction::TYPE_ACTION: | case DifferentialTransaction::TYPE_ACTION: | ||||
| $action_type = $xaction->getNewValue(); | $action_type = $xaction->getNewValue(); | ||||
| switch ($action_type) { | switch ($action_type) { | ||||
| case DifferentialAction::ACTION_ACCEPT: | case DifferentialAction::ACTION_ACCEPT: | ||||
| case DifferentialAction::ACTION_REJECT: | case DifferentialAction::ACTION_REJECT: | ||||
| if ($action_type == DifferentialAction::ACTION_ACCEPT) { | if ($action_type == DifferentialAction::ACTION_ACCEPT) { | ||||
| $data = array( | $data = array( | ||||
| Show All 23 Lines | switch ($xaction->getTransactionType()) { | ||||
| $results[] = id(new DifferentialTransaction()) | $results[] = id(new DifferentialTransaction()) | ||||
| ->setTransactionType($type_edge) | ->setTransactionType($type_edge) | ||||
| ->setMetadataValue('edge:type', $edge_reviewer) | ->setMetadataValue('edge:type', $edge_reviewer) | ||||
| ->setIgnoreOnNoEffect(true) | ->setIgnoreOnNoEffect(true) | ||||
| ->setNewValue(array('+' => $edits)); | ->setNewValue(array('+' => $edits)); | ||||
| break; | break; | ||||
| case DifferentialAction::ACTION_CLAIM: | case DifferentialAction::ACTION_CLAIM: | ||||
| // If the user is commandeering, add the previous owner as a | $is_commandeer = true; | ||||
| // reviewer and remove the actor. | |||||
| $edits = array( | |||||
| '-' => array( | |||||
| $actor_phid => $actor_phid, | |||||
| ), | |||||
| ); | |||||
| $owner_phid = $object->getAuthorPHID(); | |||||
| if ($owner_phid) { | |||||
| $reviewer = new DifferentialReviewerProxy( | |||||
| $owner_phid, | |||||
| array( | |||||
| 'status' => DifferentialReviewerStatus::STATUS_ADDED, | |||||
| )); | |||||
| $edits['+'] = array( | |||||
| $owner_phid => array( | |||||
| 'data' => $reviewer->getEdgeData(), | |||||
| ), | |||||
| ); | |||||
| } | |||||
| // NOTE: We're setting setIsCommandeerSideEffect() on this because | |||||
| // normally you can't add a revision's author as a reviewer, but | |||||
| // this action swaps them after validation executes. | |||||
| $results[] = id(new DifferentialTransaction()) | |||||
| ->setTransactionType($type_edge) | |||||
| ->setMetadataValue('edge:type', $edge_reviewer) | |||||
| ->setIgnoreOnNoEffect(true) | |||||
| ->setIsCommandeerSideEffect(true) | |||||
| ->setNewValue($edits); | |||||
| break; | break; | ||||
| case DifferentialAction::ACTION_RESIGN: | case DifferentialAction::ACTION_RESIGN: | ||||
| // If the user is resigning, add a separate reviewer edit | // If the user is resigning, add a separate reviewer edit | ||||
| // transaction which removes them as a reviewer. | // transaction which removes them as a reviewer. | ||||
| $results[] = id(new DifferentialTransaction()) | $results[] = id(new DifferentialTransaction()) | ||||
| ->setTransactionType($type_edge) | ->setTransactionType($type_edge) | ||||
| ->setMetadataValue('edge:type', $edge_reviewer) | ->setMetadataValue('edge:type', $edge_reviewer) | ||||
| ->setIgnoreOnNoEffect(true) | ->setIgnoreOnNoEffect(true) | ||||
| ->setNewValue( | ->setNewValue( | ||||
| array( | array( | ||||
| '-' => array( | '-' => array( | ||||
| $actor_phid => $actor_phid, | $actor_phid => $actor_phid, | ||||
| ), | ), | ||||
| )); | )); | ||||
| break; | break; | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| if ($is_commandeer) { | |||||
| $results[] = $this->newCommandeerReviewerTransaction($object); | |||||
| } | |||||
| if (!$this->didExpandInlineState) { | 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->didExpandInlineState = true; | $this->didExpandInlineState = true; | ||||
| ▲ Show 20 Lines • Show All 964 Lines • ▼ Show 20 Lines | protected function shouldApplyHeraldRules( | ||||
| foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
| switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
| case DifferentialTransaction::TYPE_UPDATE: | case DifferentialTransaction::TYPE_UPDATE: | ||||
| if (!$this->getIsCloseByCommit()) { | if (!$this->getIsCloseByCommit()) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| break; | break; | ||||
| case DifferentialRevisionCommandeerTransaction::TRANSACTIONTYPE: | |||||
| // When users commandeer revisions, we may need to trigger | |||||
| // signatures or author-based rules. | |||||
| return true; | |||||
| case DifferentialTransaction::TYPE_ACTION: | case DifferentialTransaction::TYPE_ACTION: | ||||
| switch ($xaction->getNewValue()) { | switch ($xaction->getNewValue()) { | ||||
| case DifferentialAction::ACTION_CLAIM: | case DifferentialAction::ACTION_CLAIM: | ||||
| // When users commandeer revisions, we may need to trigger | // When users commandeer revisions, we may need to trigger | ||||
| // signatures or author-based rules. | // signatures or author-based rules. | ||||
| return true; | return true; | ||||
| } | } | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | protected function getCustomWorkerState() { | ||||
| ); | ); | ||||
| } | } | ||||
| protected function loadCustomWorkerState(array $state) { | protected function loadCustomWorkerState(array $state) { | ||||
| $this->changedPriorToCommitURI = idx($state, 'changedPriorToCommitURI'); | $this->changedPriorToCommitURI = idx($state, 'changedPriorToCommitURI'); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| private function newCommandeerReviewerTransaction( | |||||
| DifferentialRevision $revision) { | |||||
| $actor_phid = $this->getActingAsPHID(); | |||||
| $owner_phid = $revision->getAuthorPHID(); | |||||
| // If the user is commandeering, add the previous owner as a | |||||
| // reviewer and remove the actor. | |||||
| $edits = array( | |||||
| '-' => array( | |||||
| $actor_phid, | |||||
| ), | |||||
| '+' => array( | |||||
| $owner_phid, | |||||
| ), | |||||
| ); | |||||
| // NOTE: We're setting setIsCommandeerSideEffect() on this because normally | |||||
| // you can't add a revision's author as a reviewer, but this action swaps | |||||
| // them after validation executes. | |||||
| $xaction_type = DifferentialRevisionReviewersTransaction::TRANSACTIONTYPE; | |||||
| return id(new DifferentialTransaction()) | |||||
| ->setTransactionType($xaction_type) | |||||
| ->setIgnoreOnNoEffect(true) | |||||
| ->setIsCommandeerSideEffect(true) | |||||
| ->setNewValue($edits); | |||||
| } | |||||
| } | } | ||||