Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / xaction / DiffusionCommitActionTransaction.php
blob1d351ffa5dc5ac9ac0eb92d1837a860a31f109c5
1 <?php
3 abstract class DiffusionCommitActionTransaction
4 extends DiffusionCommitTransactionType {
6 final public function getCommitActionKey() {
7 return $this->getPhobjectClassConstant('ACTIONKEY', 32);
10 public function isActionAvailable($object, PhabricatorUser $viewer) {
11 try {
12 $this->validateAction($object, $viewer);
13 return true;
14 } catch (Exception $ex) {
15 return false;
19 abstract protected function validateAction($object, PhabricatorUser $viewer);
20 abstract protected function getCommitActionLabel();
22 public function getCommandKeyword() {
23 return null;
26 public function getCommandAliases() {
27 return array();
30 public function getCommandSummary() {
31 return null;
34 protected function getCommitActionOrder() {
35 return 1000;
38 public function getCommitActionOrderVector() {
39 return id(new PhutilSortVector())
40 ->addInt($this->getCommitActionOrder());
43 protected function getCommitActionGroupKey() {
44 return DiffusionCommitEditEngine::ACTIONGROUP_COMMIT;
47 protected function getCommitActionDescription() {
48 return null;
51 public static function loadAllActions() {
52 return id(new PhutilClassMapQuery())
53 ->setAncestorClass(__CLASS__)
54 ->setUniqueMethod('getCommitActionKey')
55 ->execute();
58 protected function isViewerCommitAuthor(
59 PhabricatorRepositoryCommit $commit,
60 PhabricatorUser $viewer) {
62 if (!$viewer->getPHID()) {
63 return false;
66 return ($viewer->getPHID() === $commit->getEffectiveAuthorPHID());
69 public function newEditField(
70 PhabricatorRepositoryCommit $commit,
71 PhabricatorUser $viewer) {
73 // Actions in the "audit" group, like "Accept Commit", do not require
74 // that the actor be able to edit the commit.
75 $group_audit = DiffusionCommitEditEngine::ACTIONGROUP_AUDIT;
76 $is_audit = ($this->getCommitActionGroupKey() == $group_audit);
78 $field = id(new PhabricatorApplyEditField())
79 ->setKey($this->getCommitActionKey())
80 ->setTransactionType($this->getTransactionTypeConstant())
81 ->setCanApplyWithoutEditCapability($is_audit)
82 ->setValue(true);
84 if ($this->isActionAvailable($commit, $viewer)) {
85 $label = $this->getCommitActionLabel();
86 if ($label !== null) {
87 $field->setCommentActionLabel($label);
89 $description = $this->getCommitActionDescription();
90 $field->setActionDescription($description);
92 $group_key = $this->getCommitActionGroupKey();
93 $field->setCommentActionGroupKey($group_key);
95 $field->setActionConflictKey('commit.action');
99 return $field;
102 public function validateTransactions($object, array $xactions) {
103 $errors = array();
104 $actor = $this->getActor();
106 $action_exception = null;
107 try {
108 $this->validateAction($object, $actor);
109 } catch (Exception $ex) {
110 $action_exception = $ex;
113 foreach ($xactions as $xaction) {
114 if ($action_exception) {
115 $errors[] = $this->newInvalidError(
116 $action_exception->getMessage(),
117 $xaction);
121 return $errors;