Path: blob/master/src/applications/differential/xaction/DifferentialRevisionCloseTransaction.php
12256 views
<?php12final class DifferentialRevisionCloseTransaction3extends DifferentialRevisionActionTransaction {45const TRANSACTIONTYPE = 'differential.revision.close';6const ACTIONKEY = 'close';78protected function getRevisionActionLabel(9DifferentialRevision $revision,10PhabricatorUser $viewer) {11return pht('Close Revision');12}1314protected function getRevisionActionDescription(15DifferentialRevision $revision,16PhabricatorUser $viewer) {17return pht('This revision will be closed.');18}1920public function getIcon() {21return 'fa-check';22}2324public function getColor() {25return 'indigo';26}2728protected function getRevisionActionOrder() {29return 300;30}3132public function getActionName() {33return pht('Closed');34}3536public function generateOldValue($object) {37return $object->isClosed();38}3940public function applyInternalEffects($object, $value) {41$was_accepted = $object->isAccepted();4243$status_published = DifferentialRevisionStatus::PUBLISHED;44$object->setModernRevisionStatus($status_published);4546$object->setProperty(47DifferentialRevision::PROPERTY_CLOSED_FROM_ACCEPTED,48$was_accepted);4950// See T13300. When a revision is closed, we promote it out of "Draft"51// immediately. This usually happens when a user creates a draft revision52// and then lands the associated commit before the revision leaves draft.53$object->setShouldBroadcast(true);54}5556protected function validateAction($object, PhabricatorUser $viewer) {57if ($this->hasEditor()) {58if ($this->getEditor()->getIsCloseByCommit()) {59// If we're closing a revision because we discovered a commit, we don't60// care what state it was in.61return;62}63}6465if ($object->isClosed()) {66throw new Exception(67pht(68'You can not close this revision because it has already been '.69'closed. Only open revisions can be closed.'));70}7172if (!$object->isAccepted()) {73throw new Exception(74pht(75'You can not close this revision because it has not been accepted. '.76'Revisions must be accepted before they can be closed.'));77}7879$config_key = 'differential.always-allow-close';80if (!PhabricatorEnv::getEnvConfig($config_key)) {81if (!$this->isViewerRevisionAuthor($object, $viewer)) {82throw new Exception(83pht(84'You can not close this revision because you are not the '.85'author. You can only close revisions you own. You can change '.86'this behavior by adjusting the "%s" setting in Config.',87$config_key));88}89}90}9192public function getTitle() {93$commit_phid = $this->getMetadataValue('commitPHID');94if ($commit_phid) {95$commit = id(new DiffusionCommitQuery())96->setViewer($this->getViewer())97->withPHIDs(array($commit_phid))98->needIdentities(true)99->executeOne();100} else {101$commit = null;102}103104if (!$commit) {105return pht(106'%s closed this revision.',107$this->renderAuthor());108}109110$author_phid = null;111if ($commit->hasAuthorIdentity()) {112$identity = $commit->getAuthorIdentity();113$author_phid = $identity->getIdentityDisplayPHID();114}115116$committer_phid = null;117if ($commit->hasCommitterIdentity()) {118$identity = $commit->getCommitterIdentity();119$committer_phid = $identity->getIdentityDisplayPHID();120}121122if (!$author_phid) {123return pht(124'Closed by commit %s.',125$this->renderHandle($commit_phid));126} else if (!$committer_phid || ($committer_phid === $author_phid)) {127return pht(128'Closed by commit %s (authored by %s).',129$this->renderHandle($commit_phid),130$this->renderHandle($author_phid));131} else {132return pht(133'Closed by commit %s (authored by %s, committed by %s).',134$this->renderHandle($commit_phid),135$this->renderHandle($author_phid),136$this->renderHandle($committer_phid));137}138}139140public function getTitleForFeed() {141return pht(142'%s closed %s.',143$this->renderAuthor(),144$this->renderObject());145}146147public function getTransactionTypeForConduit($xaction) {148return 'close';149}150151public function getFieldValuesForConduit($object, $data) {152$commit_phid = $object->getMetadataValue('commitPHID');153154if ($commit_phid) {155$commit_phids = array($commit_phid);156} else {157$commit_phids = array();158}159160return array(161'commitPHIDs' => $commit_phids,162);163}164165}166167168