Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / differential / herald / DifferentialReviewersHeraldAction.php
blob9537ad13d3af477b0aba9290a32a1772159360d5
1 <?php
3 abstract class DifferentialReviewersHeraldAction
4 extends HeraldAction {
6 const DO_AUTHORS = 'do.authors';
7 const DO_ADD_REVIEWERS = 'do.add-reviewers';
8 const DO_ADD_BLOCKING_REVIEWERS = 'do.add-blocking-reviewers';
10 public function getActionGroupKey() {
11 return HeraldApplicationActionGroup::ACTIONGROUPKEY;
14 public function supportsObject($object) {
15 return ($object instanceof DifferentialRevision);
18 protected function applyReviewers(array $phids, $is_blocking) {
19 $adapter = $this->getAdapter();
20 $object = $adapter->getObject();
22 $phids = array_fuse($phids);
24 // Don't try to add revision authors as reviewers.
25 $authors = array();
26 foreach ($phids as $phid) {
27 if ($phid == $object->getAuthorPHID()) {
28 $authors[] = $phid;
29 unset($phids[$phid]);
33 if ($authors) {
34 $this->logEffect(self::DO_AUTHORS, $authors);
35 if (!$phids) {
36 return;
40 $reviewers = $object->getReviewers();
42 if ($is_blocking) {
43 $new_status = DifferentialReviewerStatus::STATUS_BLOCKING;
44 } else {
45 $new_status = DifferentialReviewerStatus::STATUS_ADDED;
48 $new_strength = DifferentialReviewerStatus::getStatusStrength(
49 $new_status);
51 $current = array();
52 foreach ($phids as $phid) {
53 if (!isset($reviewers[$phid])) {
54 continue;
57 // If we're applying a stronger status (usually, upgrading a reviewer
58 // into a blocking reviewer), skip this check so we apply the change.
59 $old_strength = DifferentialReviewerStatus::getStatusStrength(
60 $reviewers[$phid]->getReviewerStatus());
61 if ($old_strength <= $new_strength) {
62 continue;
65 $current[] = $phid;
68 $allowed_types = array(
69 PhabricatorPeopleUserPHIDType::TYPECONST,
70 PhabricatorProjectProjectPHIDType::TYPECONST,
71 PhabricatorOwnersPackagePHIDType::TYPECONST,
74 $targets = $this->loadStandardTargets($phids, $allowed_types, $current);
75 if (!$targets) {
76 return;
79 $phids = array_fuse(array_keys($targets));
81 $value = array();
82 foreach ($phids as $phid) {
83 if ($is_blocking) {
84 $value[] = 'blocking('.$phid.')';
85 } else {
86 $value[] = $phid;
90 $reviewers_type = DifferentialRevisionReviewersTransaction::TRANSACTIONTYPE;
92 $xaction = $adapter->newTransaction()
93 ->setTransactionType($reviewers_type)
94 ->setNewValue(
95 array(
96 '+' => $value,
97 ));
99 $adapter->queueTransaction($xaction);
101 if ($is_blocking) {
102 $this->logEffect(self::DO_ADD_BLOCKING_REVIEWERS, $phids);
103 } else {
104 $this->logEffect(self::DO_ADD_REVIEWERS, $phids);
108 protected function getActionEffectMap() {
109 return array(
110 self::DO_AUTHORS => array(
111 'icon' => 'fa-user',
112 'color' => 'grey',
113 'name' => pht('Revision Author'),
115 self::DO_ADD_REVIEWERS => array(
116 'icon' => 'fa-user',
117 'color' => 'green',
118 'name' => pht('Added Reviewers'),
120 self::DO_ADD_BLOCKING_REVIEWERS => array(
121 'icon' => 'fa-user',
122 'color' => 'green',
123 'name' => pht('Added Blocking Reviewers'),
128 protected function renderActionEffectDescription($type, $data) {
129 switch ($type) {
130 case self::DO_AUTHORS:
131 return pht(
132 'Declined to add revision author as reviewer: %s.',
133 $this->renderHandleList($data));
134 case self::DO_ADD_REVIEWERS:
135 return pht(
136 'Added %s reviewer(s): %s.',
137 phutil_count($data),
138 $this->renderHandleList($data));
139 case self::DO_ADD_BLOCKING_REVIEWERS:
140 return pht(
141 'Added %s blocking reviewer(s): %s.',
142 phutil_count($data),
143 $this->renderHandleList($data));