Differential D15916 Diff 38332 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 1,530 Lines • ▼ Show 20 Lines | foreach ($packages as $package) { | ||||
| } | } | ||||
| } | } | ||||
| $owners_phid = id(new PhabricatorOwnersApplication()) | $owners_phid = id(new PhabricatorOwnersApplication()) | ||||
| ->getPHID(); | ->getPHID(); | ||||
| $xactions = array(); | $xactions = array(); | ||||
| if ($auto_subscribe) { | if ($auto_subscribe) { | ||||
| $xactions[] = $object->getApplicationTransactionTemplate() | $xactions[] = $object->getApplicationTransactionTemplate() | ||||
| ->setAuthorPHID($owners_phid) | ->setAuthorPHID($owners_phid) | ||||
| ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ||||
| ->setNewValue( | ->setNewValue( | ||||
| array( | array( | ||||
| '+' => mpull($auto_subscribe, 'getPHID'), | '+' => mpull($auto_subscribe, 'getPHID'), | ||||
| )); | )); | ||||
| } | } | ||||
| // TODO: Implement autoreview and autoblock, but these are more invovled. | $specs = array( | ||||
| array($auto_review, false), | |||||
| array($auto_block, true), | |||||
| ); | |||||
| foreach ($specs as $spec) { | |||||
| list($reviewers, $blocking) = $spec; | |||||
| if (!$reviewers) { | |||||
| continue; | |||||
| } | |||||
| $phids = mpull($reviewers, 'getPHID'); | |||||
| $xaction = $this->newAutoReviewTransaction($object, $phids, $blocking); | |||||
| if ($xaction) { | |||||
| $xactions[] = $xaction; | |||||
| } | |||||
| } | |||||
| return $xactions; | return $xactions; | ||||
| } | } | ||||
| private function newAutoReviewTransaction( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $phids, | |||||
| $is_blocking) { | |||||
| // TODO: This is substantially similar to DifferentialReviewersHeraldAction | |||||
| // and both are needlessly complex. This logic should live in the normal | |||||
| // transaction application pipeline. See T10967. | |||||
| $reviewers = $object->getReviewerStatus(); | |||||
| $reviewers = mpull($reviewers, null, 'getReviewerPHID'); | |||||
| if ($is_blocking) { | |||||
| $new_status = DifferentialReviewerStatus::STATUS_BLOCKING; | |||||
| } else { | |||||
| $new_status = DifferentialReviewerStatus::STATUS_ADDED; | |||||
| } | |||||
| $new_strength = DifferentialReviewerStatus::getStatusStrength( | |||||
| $new_status); | |||||
| $current = array(); | |||||
| foreach ($phids as $phid) { | |||||
| if (!isset($reviewers[$phid])) { | |||||
| continue; | |||||
| } | |||||
| // If we're applying a stronger status (usually, upgrading a reviewer | |||||
| // into a blocking reviewer), skip this check so we apply the change. | |||||
| $old_strength = DifferentialReviewerStatus::getStatusStrength( | |||||
| $reviewers[$phid]->getStatus()); | |||||
| if ($old_strength <= $new_strength) { | |||||
| continue; | |||||
| } | |||||
| $current[] = $phid; | |||||
| } | |||||
| $phids = array_diff($phids, $current); | |||||
| if (!$phids) { | |||||
| return null; | |||||
| } | |||||
| $phids = array_fuse($phids); | |||||
| $value = array(); | |||||
| foreach ($phids as $phid) { | |||||
| $value[$phid] = array( | |||||
| 'data' => array( | |||||
| 'status' => $new_status, | |||||
| ), | |||||
| ); | |||||
| } | |||||
| $edgetype_reviewer = DifferentialRevisionHasReviewerEdgeType::EDGECONST; | |||||
| $owners_phid = id(new PhabricatorOwnersApplication()) | |||||
| ->getPHID(); | |||||
| return $object->getApplicationTransactionTemplate() | |||||
| ->setAuthorPHID($owners_phid) | |||||
| ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | |||||
| ->setMetadataValue('edge:type', $edgetype_reviewer) | |||||
| ->setNewValue( | |||||
| array( | |||||
| '+' => $value, | |||||
| )); | |||||
| } | |||||
| protected function buildHeraldAdapter( | protected function buildHeraldAdapter( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| array $xactions) { | array $xactions) { | ||||
| $revision = id(new DifferentialRevisionQuery()) | $revision = id(new DifferentialRevisionQuery()) | ||||
| ->setViewer($this->getActor()) | ->setViewer($this->getActor()) | ||||
| ->withPHIDs(array($object->getPHID())) | ->withPHIDs(array($object->getPHID())) | ||||
| ->needActiveDiffs(true) | ->needActiveDiffs(true) | ||||
| ▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines | |||||