@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update Macro for Modular Transactions

Summary: Overall, seems to work ok.

Test Plan:
- Add a Macro
- Edit Macro
- Use Macro
- Disable Macro
- Re-enable Macro
- Attach Audio
- Set Audio to loop
- Annoy cats

{F4932069}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17813

+295 -381
+13 -1
src/__phutil_library_map__.php
··· 2972 2972 'PhabricatorLogoutController' => 'applications/auth/controller/PhabricatorLogoutController.php', 2973 2973 'PhabricatorLunarPhasePolicyRule' => 'applications/policy/rule/PhabricatorLunarPhasePolicyRule.php', 2974 2974 'PhabricatorMacroApplication' => 'applications/macro/application/PhabricatorMacroApplication.php', 2975 + 'PhabricatorMacroAudioBehaviorTransaction' => 'applications/macro/xaction/PhabricatorMacroAudioBehaviorTransaction.php', 2975 2976 'PhabricatorMacroAudioController' => 'applications/macro/controller/PhabricatorMacroAudioController.php', 2977 + 'PhabricatorMacroAudioTransaction' => 'applications/macro/xaction/PhabricatorMacroAudioTransaction.php', 2976 2978 'PhabricatorMacroCommentController' => 'applications/macro/controller/PhabricatorMacroCommentController.php', 2977 2979 'PhabricatorMacroConfigOptions' => 'applications/macro/config/PhabricatorMacroConfigOptions.php', 2978 2980 'PhabricatorMacroController' => 'applications/macro/controller/PhabricatorMacroController.php', 2979 2981 'PhabricatorMacroDatasource' => 'applications/macro/typeahead/PhabricatorMacroDatasource.php', 2980 2982 'PhabricatorMacroDisableController' => 'applications/macro/controller/PhabricatorMacroDisableController.php', 2983 + 'PhabricatorMacroDisabledTransaction' => 'applications/macro/xaction/PhabricatorMacroDisabledTransaction.php', 2981 2984 'PhabricatorMacroEditController' => 'applications/macro/controller/PhabricatorMacroEditController.php', 2982 2985 'PhabricatorMacroEditor' => 'applications/macro/editor/PhabricatorMacroEditor.php', 2986 + 'PhabricatorMacroFileTransaction' => 'applications/macro/xaction/PhabricatorMacroFileTransaction.php', 2983 2987 'PhabricatorMacroListController' => 'applications/macro/controller/PhabricatorMacroListController.php', 2984 2988 'PhabricatorMacroMacroPHIDType' => 'applications/macro/phid/PhabricatorMacroMacroPHIDType.php', 2985 2989 'PhabricatorMacroMailReceiver' => 'applications/macro/mail/PhabricatorMacroMailReceiver.php', 2986 2990 'PhabricatorMacroManageCapability' => 'applications/macro/capability/PhabricatorMacroManageCapability.php', 2987 2991 'PhabricatorMacroMemeController' => 'applications/macro/controller/PhabricatorMacroMemeController.php', 2988 2992 'PhabricatorMacroMemeDialogController' => 'applications/macro/controller/PhabricatorMacroMemeDialogController.php', 2993 + 'PhabricatorMacroNameTransaction' => 'applications/macro/xaction/PhabricatorMacroNameTransaction.php', 2989 2994 'PhabricatorMacroQuery' => 'applications/macro/query/PhabricatorMacroQuery.php', 2990 2995 'PhabricatorMacroReplyHandler' => 'applications/macro/mail/PhabricatorMacroReplyHandler.php', 2991 2996 'PhabricatorMacroSearchEngine' => 'applications/macro/query/PhabricatorMacroSearchEngine.php', 2992 2997 'PhabricatorMacroTransaction' => 'applications/macro/storage/PhabricatorMacroTransaction.php', 2993 2998 'PhabricatorMacroTransactionComment' => 'applications/macro/storage/PhabricatorMacroTransactionComment.php', 2994 2999 'PhabricatorMacroTransactionQuery' => 'applications/macro/query/PhabricatorMacroTransactionQuery.php', 3000 + 'PhabricatorMacroTransactionType' => 'applications/macro/xaction/PhabricatorMacroTransactionType.php', 2995 3001 'PhabricatorMacroViewController' => 'applications/macro/controller/PhabricatorMacroViewController.php', 2996 3002 'PhabricatorMailEmailHeraldField' => 'applications/metamta/herald/PhabricatorMailEmailHeraldField.php', 2997 3003 'PhabricatorMailEmailHeraldFieldGroup' => 'applications/metamta/herald/PhabricatorMailEmailHeraldFieldGroup.php', ··· 8162 8168 'PhabricatorLogoutController' => 'PhabricatorAuthController', 8163 8169 'PhabricatorLunarPhasePolicyRule' => 'PhabricatorPolicyRule', 8164 8170 'PhabricatorMacroApplication' => 'PhabricatorApplication', 8171 + 'PhabricatorMacroAudioBehaviorTransaction' => 'PhabricatorMacroTransactionType', 8165 8172 'PhabricatorMacroAudioController' => 'PhabricatorMacroController', 8173 + 'PhabricatorMacroAudioTransaction' => 'PhabricatorMacroTransactionType', 8166 8174 'PhabricatorMacroCommentController' => 'PhabricatorMacroController', 8167 8175 'PhabricatorMacroConfigOptions' => 'PhabricatorApplicationConfigOptions', 8168 8176 'PhabricatorMacroController' => 'PhabricatorController', 8169 8177 'PhabricatorMacroDatasource' => 'PhabricatorTypeaheadDatasource', 8170 8178 'PhabricatorMacroDisableController' => 'PhabricatorMacroController', 8179 + 'PhabricatorMacroDisabledTransaction' => 'PhabricatorMacroTransactionType', 8171 8180 'PhabricatorMacroEditController' => 'PhabricatorMacroController', 8172 8181 'PhabricatorMacroEditor' => 'PhabricatorApplicationTransactionEditor', 8182 + 'PhabricatorMacroFileTransaction' => 'PhabricatorMacroTransactionType', 8173 8183 'PhabricatorMacroListController' => 'PhabricatorMacroController', 8174 8184 'PhabricatorMacroMacroPHIDType' => 'PhabricatorPHIDType', 8175 8185 'PhabricatorMacroMailReceiver' => 'PhabricatorObjectMailReceiver', 8176 8186 'PhabricatorMacroManageCapability' => 'PhabricatorPolicyCapability', 8177 8187 'PhabricatorMacroMemeController' => 'PhabricatorMacroController', 8178 8188 'PhabricatorMacroMemeDialogController' => 'PhabricatorMacroController', 8189 + 'PhabricatorMacroNameTransaction' => 'PhabricatorMacroTransactionType', 8179 8190 'PhabricatorMacroQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 8180 8191 'PhabricatorMacroReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 8181 8192 'PhabricatorMacroSearchEngine' => 'PhabricatorApplicationSearchEngine', 8182 - 'PhabricatorMacroTransaction' => 'PhabricatorApplicationTransaction', 8193 + 'PhabricatorMacroTransaction' => 'PhabricatorModularTransaction', 8183 8194 'PhabricatorMacroTransactionComment' => 'PhabricatorApplicationTransactionComment', 8184 8195 'PhabricatorMacroTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 8196 + 'PhabricatorMacroTransactionType' => 'PhabricatorModularTransactionType', 8185 8197 'PhabricatorMacroViewController' => 'PhabricatorMacroController', 8186 8198 'PhabricatorMailEmailHeraldField' => 'HeraldField', 8187 8199 'PhabricatorMailEmailHeraldFieldGroup' => 'HeraldFieldGroup',
+3 -2
src/applications/macro/controller/PhabricatorMacroAudioController.php
··· 34 34 if ($request->getBool('behaviorForm')) { 35 35 $xactions[] = id(new PhabricatorMacroTransaction()) 36 36 ->setTransactionType( 37 - PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR) 37 + PhabricatorMacroAudioBehaviorTransaction::TRANSACTIONTYPE) 38 38 ->setNewValue($request->getStr('audioBehavior')); 39 39 } else { 40 40 $file = null; ··· 54 54 $e_file = pht('Invalid'); 55 55 } else { 56 56 $xactions[] = id(new PhabricatorMacroTransaction()) 57 - ->setTransactionType(PhabricatorMacroTransaction::TYPE_AUDIO) 57 + ->setTransactionType( 58 + PhabricatorMacroAudioTransaction::TRANSACTIONTYPE) 58 59 ->setNewValue($file->getPHID()); 59 60 } 60 61 } else {
+2 -1
src/applications/macro/controller/PhabricatorMacroDisableController.php
··· 22 22 23 23 if ($request->isDialogFormPost() || $macro->getIsDisabled()) { 24 24 $xaction = id(new PhabricatorMacroTransaction()) 25 - ->setTransactionType(PhabricatorMacroTransaction::TYPE_DISABLED) 25 + ->setTransactionType( 26 + PhabricatorMacroDisabledTransaction::TRANSACTIONTYPE) 26 27 ->setNewValue($macro->getIsDisabled() ? 0 : 1); 27 28 28 29 $editor = id(new PhabricatorMacroEditor())
+4 -2
src/applications/macro/controller/PhabricatorMacroEditController.php
··· 135 135 136 136 if ($new_name !== null) { 137 137 $xactions[] = id(new PhabricatorMacroTransaction()) 138 - ->setTransactionType(PhabricatorMacroTransaction::TYPE_NAME) 138 + ->setTransactionType( 139 + PhabricatorMacroNameTransaction::TRANSACTIONTYPE) 139 140 ->setNewValue($new_name); 140 141 } 141 142 142 143 if ($file) { 143 144 $xactions[] = id(new PhabricatorMacroTransaction()) 144 - ->setTransactionType(PhabricatorMacroTransaction::TYPE_FILE) 145 + ->setTransactionType( 146 + PhabricatorMacroFileTransaction::TRANSACTIONTYPE) 145 147 ->setNewValue($file->getPHID()); 146 148 } 147 149
+1 -1
src/applications/macro/controller/PhabricatorMacroViewController.php
··· 45 45 if (!$macro->getIsDisabled()) { 46 46 $header->setStatus('fa-check', 'bluegrey', pht('Active')); 47 47 } else { 48 - $header->setStatus('fa-ban', 'red', pht('Archived')); 48 + $header->setStatus('fa-ban', 'indigo', pht('Archived')); 49 49 } 50 50 51 51 $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
+2 -88
src/applications/macro/editor/PhabricatorMacroEditor.php
··· 13 13 14 14 public function getTransactionTypes() { 15 15 $types = parent::getTransactionTypes(); 16 - 17 16 $types[] = PhabricatorTransactions::TYPE_COMMENT; 18 - $types[] = PhabricatorMacroTransaction::TYPE_NAME; 19 - $types[] = PhabricatorMacroTransaction::TYPE_DISABLED; 20 - $types[] = PhabricatorMacroTransaction::TYPE_FILE; 21 - $types[] = PhabricatorMacroTransaction::TYPE_AUDIO; 22 - $types[] = PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR; 23 17 24 18 return $types; 25 19 } 26 20 27 - protected function getCustomTransactionOldValue( 28 - PhabricatorLiskDAO $object, 29 - PhabricatorApplicationTransaction $xaction) { 30 - 31 - switch ($xaction->getTransactionType()) { 32 - case PhabricatorMacroTransaction::TYPE_NAME: 33 - return $object->getName(); 34 - case PhabricatorMacroTransaction::TYPE_DISABLED: 35 - return $object->getIsDisabled(); 36 - case PhabricatorMacroTransaction::TYPE_FILE: 37 - return $object->getFilePHID(); 38 - case PhabricatorMacroTransaction::TYPE_AUDIO: 39 - return $object->getAudioPHID(); 40 - case PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR: 41 - return $object->getAudioBehavior(); 42 - } 43 - } 44 - 45 - protected function getCustomTransactionNewValue( 46 - PhabricatorLiskDAO $object, 47 - PhabricatorApplicationTransaction $xaction) { 48 - 49 - switch ($xaction->getTransactionType()) { 50 - case PhabricatorMacroTransaction::TYPE_NAME: 51 - case PhabricatorMacroTransaction::TYPE_DISABLED: 52 - case PhabricatorMacroTransaction::TYPE_FILE: 53 - case PhabricatorMacroTransaction::TYPE_AUDIO: 54 - case PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR: 55 - return $xaction->getNewValue(); 56 - } 57 - } 58 - 59 - protected function applyCustomInternalTransaction( 60 - PhabricatorLiskDAO $object, 61 - PhabricatorApplicationTransaction $xaction) { 62 - 63 - switch ($xaction->getTransactionType()) { 64 - case PhabricatorMacroTransaction::TYPE_NAME: 65 - $object->setName($xaction->getNewValue()); 66 - break; 67 - case PhabricatorMacroTransaction::TYPE_DISABLED: 68 - $object->setIsDisabled($xaction->getNewValue()); 69 - break; 70 - case PhabricatorMacroTransaction::TYPE_FILE: 71 - $object->setFilePHID($xaction->getNewValue()); 72 - break; 73 - case PhabricatorMacroTransaction::TYPE_AUDIO: 74 - $object->setAudioPHID($xaction->getNewValue()); 75 - break; 76 - case PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR: 77 - $object->setAudioBehavior($xaction->getNewValue()); 78 - break; 79 - } 80 - } 81 - 82 21 protected function applyCustomExternalTransaction( 83 22 PhabricatorLiskDAO $object, 84 23 PhabricatorApplicationTransaction $xaction) { 85 24 86 25 switch ($xaction->getTransactionType()) { 87 - case PhabricatorMacroTransaction::TYPE_FILE: 88 - case PhabricatorMacroTransaction::TYPE_AUDIO: 26 + case PhabricatorMacroFileTransaction::TRANSACTIONTYPE: 27 + case PhabricatorMacroAudioTransaction::TRANSACTIONTYPE: 89 28 // When changing a macro's image or audio, attach the underlying files 90 29 // to the macro (and detach the old files). 91 30 $old = $xaction->getOldValue(); ··· 117 56 } 118 57 } 119 58 120 - protected function mergeTransactions( 121 - PhabricatorApplicationTransaction $u, 122 - PhabricatorApplicationTransaction $v) { 123 - 124 - $type = $u->getTransactionType(); 125 - switch ($type) { 126 - case PhabricatorMacroTransaction::TYPE_NAME: 127 - case PhabricatorMacroTransaction::TYPE_DISABLED: 128 - case PhabricatorMacroTransaction::TYPE_FILE: 129 - case PhabricatorMacroTransaction::TYPE_AUDIO: 130 - case PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR: 131 - return $v; 132 - } 133 - 134 - return parent::mergeTransactions($u, $v); 135 - } 136 - 137 59 protected function shouldSendMail( 138 60 PhabricatorLiskDAO $object, 139 61 array $xactions) { 140 - foreach ($xactions as $xaction) { 141 - switch ($xaction->getTransactionType()) { 142 - case PhabricatorMacroTransaction::TYPE_NAME; 143 - return ($xaction->getOldValue() !== null); 144 - default: 145 - break; 146 - } 147 - } 148 62 return true; 149 63 } 150 64
+3 -286
src/applications/macro/storage/PhabricatorMacroTransaction.php
··· 1 1 <?php 2 2 3 3 final class PhabricatorMacroTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_NAME = 'macro:name'; 7 - const TYPE_DISABLED = 'macro:disabled'; 8 - const TYPE_FILE = 'macro:file'; 9 - 10 - const TYPE_AUDIO = 'macro:audio'; 11 - const TYPE_AUDIO_BEHAVIOR = 'macro:audiobehavior'; 4 + extends PhabricatorModularTransaction { 12 5 13 6 public function getApplicationName() { 14 7 return 'file'; ··· 26 19 return new PhabricatorMacroTransactionComment(); 27 20 } 28 21 29 - public function getRequiredHandlePHIDs() { 30 - $phids = parent::getRequiredHandlePHIDs(); 31 - 32 - $old = $this->getOldValue(); 33 - $new = $this->getNewValue(); 34 - 35 - switch ($this->getTransactionType()) { 36 - case self::TYPE_FILE: 37 - case self::TYPE_AUDIO: 38 - if ($old !== null) { 39 - $phids[] = $old; 40 - } 41 - $phids[] = $new; 42 - break; 43 - } 44 - 45 - return $phids; 46 - } 47 - 48 - public function shouldHide() { 49 - $old = $this->getOldValue(); 50 - $new = $this->getNewValue(); 51 - 52 - switch ($this->getTransactionType()) { 53 - case self::TYPE_NAME: 54 - return ($old === null); 55 - } 56 - 57 - return parent::shouldHide(); 58 - } 59 - 60 - public function getTitle() { 61 - $author_phid = $this->getAuthorPHID(); 62 - 63 - $old = $this->getOldValue(); 64 - $new = $this->getNewValue(); 65 - 66 - switch ($this->getTransactionType()) { 67 - case self::TYPE_NAME: 68 - return pht( 69 - '%s renamed this macro from "%s" to "%s".', 70 - $this->renderHandleLink($author_phid), 71 - $old, 72 - $new); 73 - break; 74 - case self::TYPE_DISABLED: 75 - if ($new) { 76 - return pht( 77 - '%s disabled this macro.', 78 - $this->renderHandleLink($author_phid)); 79 - } else { 80 - return pht( 81 - '%s restored this macro.', 82 - $this->renderHandleLink($author_phid)); 83 - } 84 - break; 85 - 86 - case self::TYPE_AUDIO: 87 - if (!$old) { 88 - return pht( 89 - '%s attached audio: %s.', 90 - $this->renderHandleLink($author_phid), 91 - $this->renderHandleLink($new)); 92 - } else { 93 - return pht( 94 - '%s changed the audio for this macro from %s to %s.', 95 - $this->renderHandleLink($author_phid), 96 - $this->renderHandleLink($old), 97 - $this->renderHandleLink($new)); 98 - } 99 - 100 - case self::TYPE_AUDIO_BEHAVIOR: 101 - switch ($new) { 102 - case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE: 103 - return pht( 104 - '%s set the audio to play once.', 105 - $this->renderHandleLink($author_phid)); 106 - case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: 107 - return pht( 108 - '%s set the audio to loop.', 109 - $this->renderHandleLink($author_phid)); 110 - default: 111 - return pht( 112 - '%s disabled the audio for this macro.', 113 - $this->renderHandleLink($author_phid)); 114 - } 115 - 116 - case self::TYPE_FILE: 117 - if ($old === null) { 118 - return pht( 119 - '%s created this macro.', 120 - $this->renderHandleLink($author_phid)); 121 - } else { 122 - return pht( 123 - '%s changed the image for this macro from %s to %s.', 124 - $this->renderHandleLink($author_phid), 125 - $this->renderHandleLink($old), 126 - $this->renderHandleLink($new)); 127 - } 128 - break; 129 - } 130 - 131 - return parent::getTitle(); 132 - } 133 - 134 - public function getTitleForFeed() { 135 - $author_phid = $this->getAuthorPHID(); 136 - $object_phid = $this->getObjectPHID(); 137 - 138 - $old = $this->getOldValue(); 139 - $new = $this->getNewValue(); 140 - 141 - switch ($this->getTransactionType()) { 142 - case self::TYPE_NAME: 143 - return pht( 144 - '%s renamed %s from "%s" to "%s".', 145 - $this->renderHandleLink($author_phid), 146 - $this->renderHandleLink($object_phid), 147 - $old, 148 - $new); 149 - case self::TYPE_DISABLED: 150 - if ($new) { 151 - return pht( 152 - '%s disabled %s.', 153 - $this->renderHandleLink($author_phid), 154 - $this->renderHandleLink($object_phid)); 155 - } else { 156 - return pht( 157 - '%s restored %s.', 158 - $this->renderHandleLink($author_phid), 159 - $this->renderHandleLink($object_phid)); 160 - } 161 - case self::TYPE_FILE: 162 - if ($old === null) { 163 - return pht( 164 - '%s created %s.', 165 - $this->renderHandleLink($author_phid), 166 - $this->renderHandleLink($object_phid)); 167 - } else { 168 - return pht( 169 - '%s updated the image for %s.', 170 - $this->renderHandleLink($author_phid), 171 - $this->renderHandleLink($object_phid)); 172 - } 173 - 174 - case self::TYPE_AUDIO: 175 - if (!$old) { 176 - return pht( 177 - '%s attached audio to %s: %s.', 178 - $this->renderHandleLink($author_phid), 179 - $this->renderHandleLink($object_phid), 180 - $this->renderHandleLink($new)); 181 - } else { 182 - return pht( 183 - '%s changed the audio for %s from %s to %s.', 184 - $this->renderHandleLink($author_phid), 185 - $this->renderHandleLink($object_phid), 186 - $this->renderHandleLink($old), 187 - $this->renderHandleLink($new)); 188 - } 189 - 190 - case self::TYPE_AUDIO_BEHAVIOR: 191 - switch ($new) { 192 - case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE: 193 - return pht( 194 - '%s set the audio for %s to play once.', 195 - $this->renderHandleLink($author_phid), 196 - $this->renderHandleLink($object_phid)); 197 - case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: 198 - return pht( 199 - '%s set the audio for %s to loop.', 200 - $this->renderHandleLink($author_phid), 201 - $this->renderHandleLink($object_phid)); 202 - default: 203 - return pht( 204 - '%s disabled the audio for %s.', 205 - $this->renderHandleLink($author_phid), 206 - $this->renderHandleLink($object_phid)); 207 - } 208 - 209 - } 210 - 211 - return parent::getTitleForFeed(); 212 - } 213 - 214 - public function getActionName() { 215 - $old = $this->getOldValue(); 216 - $new = $this->getNewValue(); 217 - 218 - switch ($this->getTransactionType()) { 219 - case self::TYPE_NAME: 220 - if ($old === null) { 221 - return pht('Created'); 222 - } else { 223 - return pht('Renamed'); 224 - } 225 - case self::TYPE_DISABLED: 226 - if ($new) { 227 - return pht('Disabled'); 228 - } else { 229 - return pht('Restored'); 230 - } 231 - case self::TYPE_FILE: 232 - if ($old === null) { 233 - return pht('Created'); 234 - } else { 235 - return pht('Edited Image'); 236 - } 237 - 238 - case self::TYPE_AUDIO: 239 - return pht('Audio'); 240 - 241 - case self::TYPE_AUDIO_BEHAVIOR: 242 - return pht('Audio Behavior'); 243 - 244 - } 245 - 246 - return parent::getActionName(); 247 - } 248 - 249 - public function getActionStrength() { 250 - switch ($this->getTransactionType()) { 251 - case self::TYPE_DISABLED: 252 - return 2.0; 253 - case self::TYPE_FILE: 254 - return 1.5; 255 - } 256 - return parent::getActionStrength(); 257 - } 258 - 259 - public function getIcon() { 260 - $old = $this->getOldValue(); 261 - $new = $this->getNewValue(); 262 - 263 - switch ($this->getTransactionType()) { 264 - case self::TYPE_NAME: 265 - return 'fa-pencil'; 266 - case self::TYPE_FILE: 267 - if ($old === null) { 268 - return 'fa-plus'; 269 - } else { 270 - return 'fa-pencil'; 271 - } 272 - case self::TYPE_DISABLED: 273 - if ($new) { 274 - return 'fa-times'; 275 - } else { 276 - return 'fa-undo'; 277 - } 278 - case self::TYPE_AUDIO: 279 - return 'fa-headphones'; 280 - } 281 - 282 - return parent::getIcon(); 283 - } 284 - 285 - public function getColor() { 286 - $old = $this->getOldValue(); 287 - $new = $this->getNewValue(); 288 - 289 - switch ($this->getTransactionType()) { 290 - case self::TYPE_NAME: 291 - return PhabricatorTransactions::COLOR_BLUE; 292 - case self::TYPE_FILE: 293 - if ($old === null) { 294 - return PhabricatorTransactions::COLOR_GREEN; 295 - } else { 296 - return PhabricatorTransactions::COLOR_BLUE; 297 - } 298 - case self::TYPE_DISABLED: 299 - if ($new) { 300 - return PhabricatorTransactions::COLOR_RED; 301 - } else { 302 - return PhabricatorTransactions::COLOR_SKY; 303 - } 304 - } 305 - 306 - return parent::getColor(); 22 + public function getBaseTransactionClass() { 23 + return 'PhabricatorMacroTransactionType'; 307 24 } 308 25 309 26
+69
src/applications/macro/xaction/PhabricatorMacroAudioBehaviorTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorMacroAudioBehaviorTransaction 4 + extends PhabricatorMacroTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'macro:audiobehavior'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getAudioBehavior(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setAudioBehavior($value); 14 + } 15 + 16 + public function getTitle() { 17 + $new = $this->getNewValue(); 18 + $old = $this->getOldValue(); 19 + switch ($new) { 20 + case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE: 21 + return pht( 22 + '%s set the audio to play once.', 23 + $this->renderAuthor()); 24 + case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: 25 + return pht( 26 + '%s set the audio to loop.', 27 + $this->renderAuthor()); 28 + default: 29 + return pht( 30 + '%s disabled the audio for this macro.', 31 + $this->renderAuthor()); 32 + } 33 + } 34 + 35 + public function getTitleForFeed() { 36 + $new = $this->getNewValue(); 37 + $old = $this->getOldValue(); 38 + switch ($new) { 39 + case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE: 40 + return pht( 41 + '%s set the audio for %s to play once.', 42 + $this->renderAuthor(), 43 + $this->renderObject()); 44 + case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: 45 + return pht( 46 + '%s set the audio for %s to loop.', 47 + $this->renderAuthor(), 48 + $this->renderObject()); 49 + default: 50 + return pht( 51 + '%s disabled the audio for %s.', 52 + $this->renderAuthor(), 53 + $this->renderObject()); 54 + } 55 + } 56 + 57 + public function getIcon() { 58 + $new = $this->getNewValue(); 59 + switch ($new) { 60 + case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE: 61 + return 'fa-play-circle'; 62 + case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: 63 + return 'fa-repeat'; 64 + default: 65 + return 'fa-pause-circle'; 66 + } 67 + } 68 + 69 + }
+56
src/applications/macro/xaction/PhabricatorMacroAudioTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorMacroAudioTransaction 4 + extends PhabricatorMacroTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'macro:audio'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getAudioPHID(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setAudioPHID($value); 14 + } 15 + 16 + public function getTitle() { 17 + $new = $this->getNewValue(); 18 + $old = $this->getOldValue(); 19 + if (!$old) { 20 + return pht( 21 + '%s attached audio: %s.', 22 + $this->renderAuthor(), 23 + $this->renderHandle($new)); 24 + } else { 25 + return pht( 26 + '%s changed the audio for this macro from %s to %s.', 27 + $this->renderAuthor(), 28 + $this->renderHandle($old), 29 + $this->renderHandle($new)); 30 + } 31 + } 32 + 33 + public function getTitleForFeed() { 34 + $new = $this->getNewValue(); 35 + $old = $this->getOldValue(); 36 + if (!$old) { 37 + return pht( 38 + '%s attached audio to %s: %s.', 39 + $this->renderAuthor(), 40 + $this->renderObject(), 41 + $this->renderHandle($new)); 42 + } else { 43 + return pht( 44 + '%s changed the audio for %s from %s to %s.', 45 + $this->renderAuthor(), 46 + $this->renderObject(), 47 + $this->renderHandle($old), 48 + $this->renderHandle($new)); 49 + } 50 + } 51 + 52 + public function getIcon() { 53 + return 'fa-music'; 54 + } 55 + 56 + }
+50
src/applications/macro/xaction/PhabricatorMacroDisabledTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorMacroDisabledTransaction 4 + extends PhabricatorMacroTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'macro:disabled'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getIsDisabled(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setIsDisabled($value); 14 + } 15 + 16 + public function getTitle() { 17 + if ($this->getNewValue()) { 18 + return pht( 19 + '%s disabled this macro.', 20 + $this->renderAuthor()); 21 + } else { 22 + return pht( 23 + '%s restored this macro.', 24 + $this->renderAuthor()); 25 + } 26 + } 27 + 28 + public function getTitleForFeed() { 29 + if ($this->getNewValue()) { 30 + return pht( 31 + '%s disabled %s.', 32 + $this->renderAuthor(), 33 + $this->renderObject()); 34 + } else { 35 + return pht( 36 + '%s restored %s.', 37 + $this->renderAuthor(), 38 + $this->renderObject()); 39 + } 40 + } 41 + 42 + public function getIcon() { 43 + if ($this->getNewValue()) { 44 + return 'fa-ban'; 45 + } else { 46 + return 'fa-check'; 47 + } 48 + } 49 + 50 + }
+33
src/applications/macro/xaction/PhabricatorMacroFileTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorMacroFileTransaction 4 + extends PhabricatorMacroTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'macro:file'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getFilePHID(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setFilePHID($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s changed the image for this macro.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s changed the image for macro %s.', 25 + $this->renderAuthor(), 26 + $this->renderObject()); 27 + } 28 + 29 + public function getIcon() { 30 + return 'fa-file-image-o'; 31 + } 32 + 33 + }
+55
src/applications/macro/xaction/PhabricatorMacroNameTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorMacroNameTransaction 4 + extends PhabricatorMacroTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'macro:name'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setName($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s renamed this macro from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function getTitleForFeed() { 25 + return pht( 26 + '%s renamed %s macro %s to %s.', 27 + $this->renderAuthor(), 28 + $this->renderObject(), 29 + $this->renderOldValue(), 30 + $this->renderNewValue()); 31 + } 32 + 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { 37 + $errors[] = $this->newRequiredError( 38 + pht('Macros must have a name.')); 39 + } 40 + 41 + $max_length = $object->getColumnMaximumByteLength('name'); 42 + foreach ($xactions as $xaction) { 43 + $new_value = $xaction->getNewValue(); 44 + $new_length = strlen($new_value); 45 + if ($new_length > $max_length) { 46 + $errors[] = $this->newInvalidError( 47 + pht('The name can be no longer than %s characters.', 48 + new PhutilNumber($max_length))); 49 + } 50 + } 51 + 52 + return $errors; 53 + } 54 + 55 + }
+4
src/applications/macro/xaction/PhabricatorMacroTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorMacroTransactionType 4 + extends PhabricatorModularTransactionType {}