2016-12-28 22:05:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialRevisionCloseTransaction
|
|
|
|
extends DifferentialRevisionActionTransaction {
|
|
|
|
|
|
|
|
const TRANSACTIONTYPE = 'differential.revision.close';
|
|
|
|
const ACTIONKEY = 'close';
|
|
|
|
|
|
|
|
protected function getRevisionActionLabel() {
|
|
|
|
return pht('Close Revision');
|
|
|
|
}
|
|
|
|
|
2017-09-18 23:14:52 +02:00
|
|
|
protected function getRevisionActionDescription(
|
|
|
|
DifferentialRevision $revision) {
|
2016-12-28 22:05:04 +01:00
|
|
|
return pht('This revision will be closed.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIcon() {
|
|
|
|
return 'fa-check';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getColor() {
|
|
|
|
return 'indigo';
|
|
|
|
}
|
|
|
|
|
Order actions sensibly within Differential revision comment action groups
Summary:
Ref T11114. See D17114 for some discussion.
For review actions: accept, reject, resign.
For revision actions, order is basically least-severe to most-severe action pairs: plan changes, request review, close, reopen, abandon, reclaim, commandeer.
Test Plan: Viewed revisions as an author and a reviewer, saw sensible action order within action groups.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11114
Differential Revision: https://secure.phabricator.com/D17115
2016-12-29 22:36:36 +01:00
|
|
|
protected function getRevisionActionOrder() {
|
|
|
|
return 300;
|
|
|
|
}
|
|
|
|
|
2017-01-12 16:40:48 +01:00
|
|
|
public function getActionName() {
|
|
|
|
return pht('Closed');
|
|
|
|
}
|
|
|
|
|
2016-12-28 22:05:04 +01:00
|
|
|
public function generateOldValue($object) {
|
|
|
|
return $object->isClosed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function applyInternalEffects($object, $value) {
|
2017-08-11 22:23:41 +02:00
|
|
|
$was_accepted = $object->isAccepted();
|
2016-12-28 22:05:04 +01:00
|
|
|
|
2017-08-12 00:49:05 +02:00
|
|
|
$status_published = DifferentialRevisionStatus::PUBLISHED;
|
|
|
|
$object->setModernRevisionStatus($status_published);
|
2016-12-28 22:05:04 +01:00
|
|
|
|
|
|
|
$object->setProperty(
|
|
|
|
DifferentialRevision::PROPERTY_CLOSED_FROM_ACCEPTED,
|
|
|
|
$was_accepted);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function validateAction($object, PhabricatorUser $viewer) {
|
2017-08-29 18:54:03 +02:00
|
|
|
if ($this->hasEditor()) {
|
|
|
|
if ($this->getEditor()->getIsCloseByCommit()) {
|
|
|
|
// If we're closing a revision because we discovered a commit, we don't
|
|
|
|
// care what state it was in.
|
|
|
|
return;
|
|
|
|
}
|
2017-08-11 23:47:39 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 22:05:04 +01:00
|
|
|
if ($object->isClosed()) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'You can not close this revision because it has already been '.
|
|
|
|
'closed. Only open revisions can be closed.'));
|
|
|
|
}
|
|
|
|
|
Order actions sensibly within Differential revision comment action groups
Summary:
Ref T11114. See D17114 for some discussion.
For review actions: accept, reject, resign.
For revision actions, order is basically least-severe to most-severe action pairs: plan changes, request review, close, reopen, abandon, reclaim, commandeer.
Test Plan: Viewed revisions as an author and a reviewer, saw sensible action order within action groups.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11114
Differential Revision: https://secure.phabricator.com/D17115
2016-12-29 22:36:36 +01:00
|
|
|
if (!$object->isAccepted()) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'You can not close this revision because it has not been accepted. '.
|
|
|
|
'Revisions must be accepted before they can be closed.'));
|
|
|
|
}
|
|
|
|
|
2016-12-28 22:05:04 +01:00
|
|
|
$config_key = 'differential.always-allow-close';
|
|
|
|
if (!PhabricatorEnv::getEnvConfig($config_key)) {
|
|
|
|
if (!$this->isViewerRevisionAuthor($object, $viewer)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'You can not close this revision because you are not the '.
|
|
|
|
'author. You can only close revisions you own. You can change '.
|
|
|
|
'this behavior by adjusting the "%s" setting in Config.',
|
|
|
|
$config_key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitle() {
|
2017-08-11 23:47:39 +02:00
|
|
|
if (!$this->getMetadataValue('isCommitClose')) {
|
|
|
|
return pht(
|
|
|
|
'%s closed this revision.',
|
|
|
|
$this->renderAuthor());
|
|
|
|
}
|
|
|
|
|
|
|
|
$commit_phid = $this->getMetadataValue('commitPHID');
|
|
|
|
$committer_phid = $this->getMetadataValue('committerPHID');
|
|
|
|
$author_phid = $this->getMetadataValue('authorPHID');
|
|
|
|
|
|
|
|
if ($committer_phid) {
|
|
|
|
$committer_name = $this->renderHandle($committer_phid);
|
|
|
|
} else {
|
|
|
|
$committer_name = $this->getMetadataValue('committerName');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($author_phid) {
|
|
|
|
$author_name = $this->renderHandle($author_phid);
|
|
|
|
} else {
|
|
|
|
$author_name = $this->getMetadatavalue('authorName');
|
|
|
|
}
|
|
|
|
|
|
|
|
$same_phid =
|
|
|
|
strlen($committer_phid) &&
|
|
|
|
strlen($author_phid) &&
|
|
|
|
($committer_phid == $author_phid);
|
|
|
|
|
|
|
|
$same_name =
|
|
|
|
!strlen($committer_phid) &&
|
|
|
|
!strlen($author_phid) &&
|
|
|
|
($committer_name == $author_name);
|
|
|
|
|
|
|
|
if ($same_name || $same_phid) {
|
|
|
|
return pht(
|
|
|
|
'Closed by commit %s (authored by %s).',
|
|
|
|
$this->renderHandle($commit_phid),
|
|
|
|
$author_name);
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'Closed by commit %s (authored by %s, committed by %s).',
|
|
|
|
$this->renderHandle($commit_phid),
|
|
|
|
$author_name,
|
|
|
|
$committer_name);
|
|
|
|
}
|
2016-12-28 22:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitleForFeed() {
|
|
|
|
return pht(
|
|
|
|
'%s closed %s.',
|
|
|
|
$this->renderAuthor(),
|
|
|
|
$this->renderObject());
|
|
|
|
}
|
|
|
|
|
2018-03-06 17:40:34 +01:00
|
|
|
public function getTransactionTypeForConduit($xaction) {
|
|
|
|
return 'close';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldValuesForConduit($object, $data) {
|
|
|
|
$commit_phid = $object->getMetadataValue('commitPHID');
|
|
|
|
|
|
|
|
if ($commit_phid) {
|
|
|
|
$commit_phids = array($commit_phid);
|
|
|
|
} else {
|
|
|
|
$commit_phids = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'commitPHIDs' => $commit_phids,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-28 22:05:04 +01:00
|
|
|
}
|