protected function applyCustomInternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     $status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
     $status_revision = ArcanistDifferentialRevisionStatus::NEEDS_REVISION;
     $status_plan = ArcanistDifferentialRevisionStatus::CHANGES_PLANNED;
     switch ($xaction->getTransactionType()) {
         case PhabricatorTransactions::TYPE_VIEW_POLICY:
             $object->setViewPolicy($xaction->getNewValue());
             return;
         case PhabricatorTransactions::TYPE_EDIT_POLICY:
             $object->setEditPolicy($xaction->getNewValue());
             return;
         case PhabricatorTransactions::TYPE_SUBSCRIBERS:
         case PhabricatorTransactions::TYPE_COMMENT:
         case DifferentialTransaction::TYPE_INLINE:
             return;
         case PhabricatorTransactions::TYPE_EDGE:
             return;
         case DifferentialTransaction::TYPE_UPDATE:
             if (!$this->getIsCloseByCommit() && ($object->getStatus() == $status_revision || $object->getStatus() == $status_plan)) {
                 $object->setStatus($status_review);
             }
             $diff = $this->requireDiff($xaction->getNewValue());
             $object->setLineCount($diff->getLineCount());
             $object->setRepositoryPHID($diff->getRepositoryPHID());
             $object->setArcanistProjectPHID($diff->getArcanistProjectPHID());
             $object->attachActiveDiff($diff);
             // TODO: Update the `diffPHID` once we add that.
             return;
         case DifferentialTransaction::TYPE_ACTION:
             switch ($xaction->getNewValue()) {
                 case DifferentialAction::ACTION_RESIGN:
                 case DifferentialAction::ACTION_ACCEPT:
                 case DifferentialAction::ACTION_REJECT:
                     // These have no direct effects, and affect review status only
                     // indirectly by altering reviewers with TYPE_EDGE transactions.
                     return;
                 case DifferentialAction::ACTION_ABANDON:
                     $object->setStatus(ArcanistDifferentialRevisionStatus::ABANDONED);
                     return;
                 case DifferentialAction::ACTION_RETHINK:
                     $object->setStatus($status_plan);
                     return;
                 case DifferentialAction::ACTION_RECLAIM:
                     $object->setStatus($status_review);
                     return;
                 case DifferentialAction::ACTION_REOPEN:
                     $object->setStatus($status_review);
                     return;
                 case DifferentialAction::ACTION_REQUEST:
                     $object->setStatus($status_review);
                     return;
                 case DifferentialAction::ACTION_CLOSE:
                     $object->setStatus(ArcanistDifferentialRevisionStatus::CLOSED);
                     return;
                 case DifferentialAction::ACTION_CLAIM:
                     $object->setAuthorPHID($this->getActingAsPHID());
                     return;
             }
             break;
     }
     return parent::applyCustomInternalTransaction($object, $xaction);
 }
 protected function applyCustomInternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     $status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
     $status_revision = ArcanistDifferentialRevisionStatus::NEEDS_REVISION;
     $status_plan = ArcanistDifferentialRevisionStatus::CHANGES_PLANNED;
     $status_abandoned = ArcanistDifferentialRevisionStatus::ABANDONED;
     switch ($xaction->getTransactionType()) {
         case DifferentialTransaction::TYPE_INLINE:
             return;
         case DifferentialTransaction::TYPE_UPDATE:
             if (!$this->getIsCloseByCommit()) {
                 switch ($object->getStatus()) {
                     case $status_revision:
                     case $status_plan:
                     case $status_abandoned:
                         $object->setStatus($status_review);
                         break;
                 }
             }
             $diff = $this->requireDiff($xaction->getNewValue());
             $object->setLineCount($diff->getLineCount());
             if ($this->repositoryPHIDOverride !== false) {
                 $object->setRepositoryPHID($this->repositoryPHIDOverride);
             } else {
                 $object->setRepositoryPHID($diff->getRepositoryPHID());
             }
             $object->attachActiveDiff($diff);
             // TODO: Update the `diffPHID` once we add that.
             return;
         case DifferentialTransaction::TYPE_ACTION:
             switch ($xaction->getNewValue()) {
                 case DifferentialAction::ACTION_RESIGN:
                 case DifferentialAction::ACTION_ACCEPT:
                 case DifferentialAction::ACTION_REJECT:
                     // These have no direct effects, and affect review status only
                     // indirectly by altering reviewers with TYPE_EDGE transactions.
                     return;
                 case DifferentialAction::ACTION_ABANDON:
                     $object->setStatus(ArcanistDifferentialRevisionStatus::ABANDONED);
                     return;
                 case DifferentialAction::ACTION_RETHINK:
                     $object->setStatus($status_plan);
                     return;
                 case DifferentialAction::ACTION_RECLAIM:
                     $object->setStatus($status_review);
                     return;
                 case DifferentialAction::ACTION_REOPEN:
                     $object->setStatus($status_review);
                     return;
                 case DifferentialAction::ACTION_REQUEST:
                     $object->setStatus($status_review);
                     return;
                 case DifferentialAction::ACTION_CLOSE:
                     $object->setStatus(ArcanistDifferentialRevisionStatus::CLOSED);
                     return;
                 case DifferentialAction::ACTION_CLAIM:
                     $object->setAuthorPHID($this->getActingAsPHID());
                     return;
                 default:
                     throw new Exception(pht('Differential action "%s" is not a valid action!', $xaction->getNewValue()));
             }
             break;
     }
     return parent::applyCustomInternalTransaction($object, $xaction);
 }
Exemplo n.º 3
0
 protected function applyCustomInternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     switch ($xaction->getTransactionType()) {
         case PhabricatorRepositoryURITransaction::TYPE_URI:
             if (!$this->getIsNewObject()) {
                 $old_uri = $object->getEffectiveURI();
             } else {
                 $old_uri = null;
                 // When creating a URI via the API, we may not have processed the
                 // repository transaction yet. Attach the repository here to make
                 // sure we have it for the calls below.
                 if ($this->repository) {
                     $object->attachRepository($this->repository);
                 }
             }
             $object->setURI($xaction->getNewValue());
             // If we've changed the domain or protocol of the URI, remove the
             // current credential. This improves behavior in several cases:
             // If a user switches between protocols with different credential
             // types, like HTTP and SSH, the old credential won't be valid anyway.
             // It's cleaner to remove it than leave a bad credential in place.
             // If a user switches hosts, the old credential is probably not
             // correct (and potentially confusing/misleading). Removing it forces
             // users to double check that they have the correct credentials.
             // If an attacker can't see a symmetric credential like a username and
             // password, they could still potentially capture it by changing the
             // host for a URI that uses it to `evil.com`, a server they control,
             // then observing the requests. Removing the credential prevents this
             // kind of escalation.
             // Since port and path changes are less likely to fall among these
             // cases, they don't trigger a credential wipe.
             $new_uri = $object->getEffectiveURI();
             if ($old_uri) {
                 $new_proto = $old_uri->getProtocol() != $new_uri->getProtocol();
                 $new_domain = $old_uri->getDomain() != $new_uri->getDomain();
                 if ($new_proto || $new_domain) {
                     $object->setCredentialPHID(null);
                 }
             }
             break;
         case PhabricatorRepositoryURITransaction::TYPE_IO:
             $object->setIOType($xaction->getNewValue());
             break;
         case PhabricatorRepositoryURITransaction::TYPE_DISPLAY:
             $object->setDisplayType($xaction->getNewValue());
             break;
         case PhabricatorRepositoryURITransaction::TYPE_REPOSITORY:
             $object->setRepositoryPHID($xaction->getNewValue());
             $object->attachRepository($this->repository);
             break;
         case PhabricatorRepositoryURITransaction::TYPE_CREDENTIAL:
             $object->setCredentialPHID($xaction->getNewValue());
             break;
         case PhabricatorRepositoryURITransaction::TYPE_DISABLE:
             $object->setIsDisabled($xaction->getNewValue());
             break;
     }
 }