Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / project / storage / PhabricatorProjectTransaction.php
blob158c2480c01f7f62785719692e893c774c7a308e
1 <?php
3 final class PhabricatorProjectTransaction
4 extends PhabricatorModularTransaction {
6 // NOTE: This is deprecated, members are just a normal edge now.
7 const TYPE_MEMBERS = 'project:members';
9 const MAILTAG_METADATA = 'project-metadata';
10 const MAILTAG_MEMBERS = 'project-members';
11 const MAILTAG_WATCHERS = 'project-watchers';
12 const MAILTAG_OTHER = 'project-other';
14 public function getApplicationName() {
15 return 'project';
18 public function getApplicationTransactionType() {
19 return PhabricatorProjectProjectPHIDType::TYPECONST;
22 public function getBaseTransactionClass() {
23 return 'PhabricatorProjectTransactionType';
26 public function getRequiredHandlePHIDs() {
27 $old = $this->getOldValue();
28 $new = $this->getNewValue();
30 $req_phids = array();
31 switch ($this->getTransactionType()) {
32 case self::TYPE_MEMBERS:
33 $add = array_diff($new, $old);
34 $rem = array_diff($old, $new);
35 $req_phids = array_merge($add, $rem);
36 break;
39 return array_merge($req_phids, parent::getRequiredHandlePHIDs());
42 public function shouldHide() {
43 switch ($this->getTransactionType()) {
44 case PhabricatorTransactions::TYPE_EDGE:
45 $edge_type = $this->getMetadataValue('edge:type');
46 switch ($edge_type) {
47 case PhabricatorProjectSilencedEdgeType::EDGECONST:
48 return true;
49 default:
50 break;
54 return parent::shouldHide();
57 public function shouldHideForMail(array $xactions) {
58 switch ($this->getTransactionType()) {
59 case PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE:
60 case PhabricatorProjectSortTransaction::TRANSACTIONTYPE:
61 case PhabricatorProjectFilterTransaction::TRANSACTIONTYPE:
62 case PhabricatorProjectWorkboardBackgroundTransaction::TRANSACTIONTYPE:
63 return true;
66 return parent::shouldHideForMail($xactions);
69 public function getIcon() {
70 switch ($this->getTransactionType()) {
71 case self::TYPE_MEMBERS:
72 return 'fa-user';
74 return parent::getIcon();
77 public function getTitle() {
78 $old = $this->getOldValue();
79 $new = $this->getNewValue();
80 $author_phid = $this->getAuthorPHID();
81 $author_handle = $this->renderHandleLink($author_phid);
83 switch ($this->getTransactionType()) {
84 case PhabricatorTransactions::TYPE_CREATE:
85 return pht(
86 '%s created this project.',
87 $this->renderHandleLink($author_phid));
89 case self::TYPE_MEMBERS:
90 $add = array_diff($new, $old);
91 $rem = array_diff($old, $new);
93 if ($add && $rem) {
94 return pht(
95 '%s changed project member(s), added %d: %s; removed %d: %s.',
96 $author_handle,
97 count($add),
98 $this->renderHandleList($add),
99 count($rem),
100 $this->renderHandleList($rem));
101 } else if ($add) {
102 if (count($add) == 1 && (head($add) == $this->getAuthorPHID())) {
103 return pht(
104 '%s joined this project.',
105 $author_handle);
106 } else {
107 return pht(
108 '%s added %d project member(s): %s.',
109 $author_handle,
110 count($add),
111 $this->renderHandleList($add));
113 } else if ($rem) {
114 if (count($rem) == 1 && (head($rem) == $this->getAuthorPHID())) {
115 return pht(
116 '%s left this project.',
117 $author_handle);
118 } else {
119 return pht(
120 '%s removed %d project member(s): %s.',
121 $author_handle,
122 count($rem),
123 $this->renderHandleList($rem));
126 break;
129 return parent::getTitle();
132 public function getMailTags() {
133 $tags = array();
134 switch ($this->getTransactionType()) {
135 case PhabricatorProjectNameTransaction::TRANSACTIONTYPE:
136 case PhabricatorProjectSlugsTransaction::TRANSACTIONTYPE:
137 case PhabricatorProjectImageTransaction::TRANSACTIONTYPE:
138 case PhabricatorProjectIconTransaction::TRANSACTIONTYPE:
139 case PhabricatorProjectColorTransaction::TRANSACTIONTYPE:
140 $tags[] = self::MAILTAG_METADATA;
141 break;
142 case PhabricatorTransactions::TYPE_EDGE:
143 $type = $this->getMetadata('edge:type');
144 $type = head($type);
145 $type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
146 $type_watcher = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
147 if ($type == $type_member) {
148 $tags[] = self::MAILTAG_MEMBERS;
149 } else if ($type == $type_watcher) {
150 $tags[] = self::MAILTAG_WATCHERS;
151 } else {
152 $tags[] = self::MAILTAG_OTHER;
154 break;
155 case PhabricatorProjectStatusTransaction::TRANSACTIONTYPE:
156 case PhabricatorProjectLockTransaction::TRANSACTIONTYPE:
157 default:
158 $tags[] = self::MAILTAG_OTHER;
159 break;
161 return $tags;