[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ReleephRequestTransaction 4 extends PhabricatorApplicationTransaction { 5 6 const TYPE_REQUEST = 'releeph:request'; 7 const TYPE_USER_INTENT = 'releeph:user_intent'; 8 const TYPE_EDIT_FIELD = 'releeph:edit_field'; 9 const TYPE_PICK_STATUS = 'releeph:pick_status'; 10 const TYPE_COMMIT = 'releeph:commit'; 11 const TYPE_DISCOVERY = 'releeph:discovery'; 12 const TYPE_MANUAL_IN_BRANCH = 'releeph:manual'; 13 14 public function getApplicationName() { 15 return 'releeph'; 16 } 17 18 public function getApplicationTransactionType() { 19 return ReleephRequestPHIDType::TYPECONST; 20 } 21 22 public function getApplicationTransactionCommentObject() { 23 return new ReleephRequestTransactionComment(); 24 } 25 26 public function hasChangeDetails() { 27 switch ($this->getTransactionType()) { 28 default; 29 break; 30 } 31 return parent::hasChangeDetails(); 32 } 33 34 public function getRequiredHandlePHIDs() { 35 $phids = parent::getRequiredHandlePHIDs(); 36 $phids[] = $this->getObjectPHID(); 37 38 $new = $this->getNewValue(); 39 40 switch ($this->getTransactionType()) { 41 case ReleephRequestTransaction::TYPE_REQUEST: 42 case ReleephRequestTransaction::TYPE_DISCOVERY: 43 $phids[] = $new; 44 break; 45 46 case ReleephRequestTransaction::TYPE_EDIT_FIELD: 47 self::searchForPHIDs($this->getOldValue(), $phids); 48 self::searchForPHIDs($this->getNewValue(), $phids); 49 break; 50 } 51 52 return $phids; 53 } 54 55 public function getTitle() { 56 $author_phid = $this->getAuthorPHID(); 57 $object_phid = $this->getObjectPHID(); 58 59 $old = $this->getOldValue(); 60 $new = $this->getNewValue(); 61 62 switch ($this->getTransactionType()) { 63 case ReleephRequestTransaction::TYPE_REQUEST: 64 return pht( 65 '%s requested %s', 66 $this->renderHandleLink($author_phid), 67 $this->renderHandleLink($new)); 68 break; 69 70 case ReleephRequestTransaction::TYPE_USER_INTENT: 71 return $this->getIntentTitle(); 72 break; 73 74 case ReleephRequestTransaction::TYPE_EDIT_FIELD: 75 $field = newv($this->getMetadataValue('fieldClass'), array()); 76 $name = $field->getName(); 77 78 $markup = $name; 79 if ($this->getRenderingTarget() === 80 PhabricatorApplicationTransaction::TARGET_HTML) { 81 82 $markup = hsprintf('<em>%s</em>', $name); 83 } 84 85 return pht( 86 '%s changed the %s to "%s"', 87 $this->renderHandleLink($author_phid), 88 $markup, 89 $field->normalizeForTransactionView($this, $new)); 90 break; 91 92 case ReleephRequestTransaction::TYPE_PICK_STATUS: 93 switch ($new) { 94 case ReleephRequest::PICK_OK: 95 return pht('%s found this request picks without error', 96 $this->renderHandleLink($author_phid)); 97 98 case ReleephRequest::REVERT_OK: 99 return pht('%s found this request reverts without error', 100 $this->renderHandleLink($author_phid)); 101 102 case ReleephRequest::PICK_FAILED: 103 return pht("%s couldn't pick this request", 104 $this->renderHandleLink($author_phid)); 105 106 case ReleephRequest::REVERT_FAILED: 107 return pht("%s couldn't revert this request", 108 $this->renderHandleLink($author_phid)); 109 } 110 break; 111 112 case ReleephRequestTransaction::TYPE_COMMIT: 113 $action_type = $this->getMetadataValue('action'); 114 switch ($action_type) { 115 case 'pick': 116 return pht( 117 '%s picked this request and committed the result upstream', 118 $this->renderHandleLink($author_phid)); 119 break; 120 121 case 'revert': 122 return pht( 123 '%s reverted this request and committed the result upstream', 124 $this->renderHandleLink($author_phid)); 125 break; 126 } 127 break; 128 129 case ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH: 130 $action = $new ? pht('picked') : pht('reverted'); 131 return pht( 132 '%s marked this request as manually %s', 133 $this->renderHandleLink($author_phid), 134 $action); 135 break; 136 137 case ReleephRequestTransaction::TYPE_DISCOVERY: 138 return pht('%s discovered this commit as %s', 139 $this->renderHandleLink($author_phid), 140 $this->renderHandleLink($new)); 141 break; 142 143 default: 144 return parent::getTitle(); 145 break; 146 } 147 } 148 149 public function getActionStrength() { 150 return parent::getActionStrength(); 151 } 152 153 public function getActionName() { 154 switch ($this->getTransactionType()) { 155 case self::TYPE_REQUEST: 156 return pht('Requested'); 157 158 case self::TYPE_COMMIT: 159 $action_type = $this->getMetadataValue('action'); 160 switch ($action_type) { 161 case 'pick': 162 return pht('Picked'); 163 164 case 'revert': 165 return pht('Reverted'); 166 } 167 } 168 169 return parent::getActionName(); 170 } 171 172 public function getColor() { 173 $new = $this->getNewValue(); 174 175 switch ($this->getTransactionType()) { 176 case ReleephRequestTransaction::TYPE_USER_INTENT: 177 switch ($new) { 178 case ReleephRequest::INTENT_WANT: 179 return PhabricatorTransactions::COLOR_GREEN; 180 case ReleephRequest::INTENT_PASS: 181 return PhabricatorTransactions::COLOR_RED; 182 } 183 } 184 return parent::getColor(); 185 } 186 187 private static function searchForPHIDs($thing, array &$phids) { 188 /** 189 * To implement something like getRequiredHandlePHIDs() in a 190 * ReleephFieldSpecification, we'd have to provide the field with its 191 * ReleephRequest (so that it could load the PHIDs from the 192 * ReleephRequest's storage, and return them.) 193 * 194 * We don't have fields initialized with their ReleephRequests, but we can 195 * make a good guess at what handles will be needed for rendering the field 196 * in this transaction by inspecting the old and new values. 197 */ 198 if (!is_array($thing)) { 199 $thing = array($thing); 200 } 201 202 foreach ($thing as $value) { 203 if (phid_get_type($value) !== 204 PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { 205 206 $phids[] = $value; 207 } 208 } 209 } 210 211 private function getIntentTitle() { 212 $author_phid = $this->getAuthorPHID(); 213 $object_phid = $this->getObjectPHID(); 214 215 $new = $this->getNewValue(); 216 $is_pusher = $this->getMetadataValue('isPusher'); 217 218 switch ($new) { 219 case ReleephRequest::INTENT_WANT: 220 if ($is_pusher) { 221 return pht( 222 '%s approved this request', 223 $this->renderHandleLink($author_phid)); 224 } else { 225 return pht( 226 '%s wanted this request', 227 $this->renderHandleLink($author_phid)); 228 } 229 230 case ReleephRequest::INTENT_PASS: 231 if ($is_pusher) { 232 return pht( 233 '%s rejected this request', 234 $this->renderHandleLink($author_phid)); 235 } else { 236 return pht( 237 '%s passed on this request', 238 $this->renderHandleLink($author_phid)); 239 } 240 } 241 } 242 243 public function shouldHide() { 244 $type = $this->getTransactionType(); 245 246 if ($type === ReleephRequestTransaction::TYPE_USER_INTENT && 247 $this->getMetadataValue('isRQCreate')) { 248 249 return true; 250 } 251 252 if ($this->isBoringPickStatus()) { 253 return true; 254 } 255 256 // ReleephSummaryFieldSpecification is usually blank when an RQ is created, 257 // creating a transaction change from null to "". Hide these! 258 if ($type === ReleephRequestTransaction::TYPE_EDIT_FIELD) { 259 if ($this->getOldValue() === null && $this->getNewValue() === '') { 260 return true; 261 } 262 } 263 return parent::shouldHide(); 264 } 265 266 public function isBoringPickStatus() { 267 $type = $this->getTransactionType(); 268 if ($type === ReleephRequestTransaction::TYPE_PICK_STATUS) { 269 $new = $this->getNewValue(); 270 if ($new === ReleephRequest::PICK_OK || 271 $new === ReleephRequest::REVERT_OK) { 272 273 return true; 274 } 275 } 276 return false; 277 } 278 279 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |