@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

Update PhamePost for modular transactions

Summary: Updates PhamePost for modular transactions.

Test Plan:
- Create a post
- Edit a post
- Add a header image
- Delete header image
- Award Token
- Leave comment
- Unpublish post
- Check History page
- Move post
- Archive post

{F4936456}

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

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

+392 -445
+15 -1
src/__phutil_library_map__.php
··· 4272 4272 'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php', 4273 4273 'PhamePost' => 'applications/phame/storage/PhamePost.php', 4274 4274 'PhamePostArchiveController' => 'applications/phame/controller/post/PhamePostArchiveController.php', 4275 + 'PhamePostBlogTransaction' => 'applications/phame/xaction/PhamePostBlogTransaction.php', 4276 + 'PhamePostBodyTransaction' => 'applications/phame/xaction/PhamePostBodyTransaction.php', 4275 4277 'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php', 4276 4278 'PhamePostEditConduitAPIMethod' => 'applications/phame/conduit/PhamePostEditConduitAPIMethod.php', 4277 4279 'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php', 4278 4280 'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php', 4279 4281 'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php', 4280 4282 'PhamePostFulltextEngine' => 'applications/phame/search/PhamePostFulltextEngine.php', 4283 + 'PhamePostHeaderImageTransaction' => 'applications/phame/xaction/PhamePostHeaderImageTransaction.php', 4281 4284 'PhamePostHeaderPictureController' => 'applications/phame/controller/post/PhamePostHeaderPictureController.php', 4282 4285 'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php', 4283 4286 'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php', ··· 4290 4293 'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php', 4291 4294 'PhamePostSearchConduitAPIMethod' => 'applications/phame/conduit/PhamePostSearchConduitAPIMethod.php', 4292 4295 'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php', 4296 + 'PhamePostSubtitleTransaction' => 'applications/phame/xaction/PhamePostSubtitleTransaction.php', 4297 + 'PhamePostTitleTransaction' => 'applications/phame/xaction/PhamePostTitleTransaction.php', 4293 4298 'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php', 4294 4299 'PhamePostTransactionComment' => 'applications/phame/storage/PhamePostTransactionComment.php', 4295 4300 'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php', 4301 + 'PhamePostTransactionType' => 'applications/phame/xaction/PhamePostTransactionType.php', 4296 4302 'PhamePostViewController' => 'applications/phame/controller/post/PhamePostViewController.php', 4303 + 'PhamePostVisibilityTransaction' => 'applications/phame/xaction/PhamePostVisibilityTransaction.php', 4297 4304 'PhameSchemaSpec' => 'applications/phame/storage/PhameSchemaSpec.php', 4298 4305 'PhameSite' => 'applications/phame/site/PhameSite.php', 4299 4306 'PhluxController' => 'applications/phlux/controller/PhluxController.php', ··· 9753 9760 'PhabricatorFulltextInterface', 9754 9761 ), 9755 9762 'PhamePostArchiveController' => 'PhamePostController', 9763 + 'PhamePostBlogTransaction' => 'PhamePostTransactionType', 9764 + 'PhamePostBodyTransaction' => 'PhamePostTransactionType', 9756 9765 'PhamePostController' => 'PhameController', 9757 9766 'PhamePostEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 9758 9767 'PhamePostEditController' => 'PhamePostController', 9759 9768 'PhamePostEditEngine' => 'PhabricatorEditEngine', 9760 9769 'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor', 9761 9770 'PhamePostFulltextEngine' => 'PhabricatorFulltextEngine', 9771 + 'PhamePostHeaderImageTransaction' => 'PhamePostTransactionType', 9762 9772 'PhamePostHeaderPictureController' => 'PhamePostController', 9763 9773 'PhamePostHistoryController' => 'PhamePostController', 9764 9774 'PhamePostListController' => 'PhamePostController', ··· 9771 9781 'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 9772 9782 'PhamePostSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 9773 9783 'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine', 9774 - 'PhamePostTransaction' => 'PhabricatorApplicationTransaction', 9784 + 'PhamePostSubtitleTransaction' => 'PhamePostTransactionType', 9785 + 'PhamePostTitleTransaction' => 'PhamePostTransactionType', 9786 + 'PhamePostTransaction' => 'PhabricatorModularTransaction', 9775 9787 'PhamePostTransactionComment' => 'PhabricatorApplicationTransactionComment', 9776 9788 'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 9789 + 'PhamePostTransactionType' => 'PhabricatorModularTransactionType', 9777 9790 'PhamePostViewController' => 'PhameLiveController', 9791 + 'PhamePostVisibilityTransaction' => 'PhamePostTransactionType', 9778 9792 'PhameSchemaSpec' => 'PhabricatorConfigSchemaSpec', 9779 9793 'PhameSite' => 'PhabricatorSite', 9780 9794 'PhluxController' => 'PhabricatorController',
+1 -1
src/applications/phame/controller/post/PhamePostArchiveController.php
··· 26 26 27 27 $new_value = PhameConstants::VISIBILITY_ARCHIVED; 28 28 $xactions[] = id(new PhamePostTransaction()) 29 - ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 29 + ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE) 30 30 ->setNewValue($new_value); 31 31 32 32 id(new PhamePostEditor())
+1 -1
src/applications/phame/controller/post/PhamePostHeaderPictureController.php
··· 61 61 62 62 $xactions = array(); 63 63 $xactions[] = id(new PhamePostTransaction()) 64 - ->setTransactionType(PhamePostTransaction::TYPE_HEADERIMAGE) 64 + ->setTransactionType(PhamePostHeaderImageTransaction::TRANSACTIONTYPE) 65 65 ->setNewValue($new_value); 66 66 67 67 $editor = id(new PhamePostEditor())
+1 -1
src/applications/phame/controller/post/PhamePostMoveController.php
··· 28 28 29 29 $xactions = array(); 30 30 $xactions[] = id(new PhamePostTransaction()) 31 - ->setTransactionType(PhamePostTransaction::TYPE_BLOG) 31 + ->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE) 32 32 ->setNewValue($v_blog); 33 33 34 34 $editor = id(new PhamePostEditor())
+1 -1
src/applications/phame/controller/post/PhamePostPublishController.php
··· 34 34 } 35 35 36 36 $xactions[] = id(new PhamePostTransaction()) 37 - ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 37 + ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE) 38 38 ->setNewValue($new_value); 39 39 40 40 id(new PhamePostEditor())
+5 -5
src/applications/phame/editor/PhamePostEditEngine.php
··· 84 84 pht('Choose a blog to create a post on (or move a post to).')) 85 85 ->setConduitTypeDescription(pht('PHID of the blog.')) 86 86 ->setAliases(array('blogPHID')) 87 - ->setTransactionType(PhamePostTransaction::TYPE_BLOG) 87 + ->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE) 88 88 ->setHandleParameterType(new AphrontPHIDListHTTPParameterType()) 89 89 ->setSingleValue($blog_phid) 90 90 ->setIsReorderable(false) ··· 97 97 ->setDescription(pht('Post title.')) 98 98 ->setConduitDescription(pht('Retitle the post.')) 99 99 ->setConduitTypeDescription(pht('New post title.')) 100 - ->setTransactionType(PhamePostTransaction::TYPE_TITLE) 100 + ->setTransactionType(PhamePostTitleTransaction::TRANSACTIONTYPE) 101 101 ->setValue($object->getTitle()), 102 102 id(new PhabricatorTextEditField()) 103 103 ->setKey('subtitle') ··· 105 105 ->setDescription(pht('Post subtitle.')) 106 106 ->setConduitDescription(pht('Change the post subtitle.')) 107 107 ->setConduitTypeDescription(pht('New post subtitle.')) 108 - ->setTransactionType(PhamePostTransaction::TYPE_SUBTITLE) 108 + ->setTransactionType(PhamePostSubtitleTransaction::TRANSACTIONTYPE) 109 109 ->setValue($object->getSubtitle()), 110 110 id(new PhabricatorSelectEditField()) 111 111 ->setKey('visibility') ··· 113 113 ->setDescription(pht('Post visibility.')) 114 114 ->setConduitDescription(pht('Change post visibility.')) 115 115 ->setConduitTypeDescription(pht('New post visibility constant.')) 116 - ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 116 + ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE) 117 117 ->setValue($object->getVisibility()) 118 118 ->setOptions(PhameConstants::getPhamePostStatusMap()), 119 119 id(new PhabricatorRemarkupEditField()) ··· 122 122 ->setDescription(pht('Post body.')) 123 123 ->setConduitDescription(pht('Change post body.')) 124 124 ->setConduitTypeDescription(pht('New post body.')) 125 - ->setTransactionType(PhamePostTransaction::TYPE_BODY) 125 + ->setTransactionType(PhamePostBodyTransaction::TRANSACTIONTYPE) 126 126 ->setValue($object->getBody()) 127 127 ->setPreviewPanel( 128 128 id(new PHUIRemarkupPreviewPanel())
+8 -164
src/applications/phame/editor/PhamePostEditor.php
··· 11 11 return pht('Phame Posts'); 12 12 } 13 13 14 - public function getTransactionTypes() { 15 - $types = parent::getTransactionTypes(); 16 - 17 - $types[] = PhamePostTransaction::TYPE_BLOG; 18 - $types[] = PhamePostTransaction::TYPE_TITLE; 19 - $types[] = PhamePostTransaction::TYPE_SUBTITLE; 20 - $types[] = PhamePostTransaction::TYPE_BODY; 21 - $types[] = PhamePostTransaction::TYPE_VISIBILITY; 22 - $types[] = PhamePostTransaction::TYPE_HEADERIMAGE; 23 - $types[] = PhabricatorTransactions::TYPE_COMMENT; 24 - 25 - return $types; 26 - } 27 - 28 - protected function getCustomTransactionOldValue( 29 - PhabricatorLiskDAO $object, 30 - PhabricatorApplicationTransaction $xaction) { 31 - 32 - switch ($xaction->getTransactionType()) { 33 - case PhamePostTransaction::TYPE_BLOG: 34 - return $object->getBlogPHID(); 35 - case PhamePostTransaction::TYPE_TITLE: 36 - return $object->getTitle(); 37 - case PhamePostTransaction::TYPE_SUBTITLE: 38 - return $object->getSubtitle(); 39 - case PhamePostTransaction::TYPE_BODY: 40 - return $object->getBody(); 41 - case PhamePostTransaction::TYPE_VISIBILITY: 42 - return $object->getVisibility(); 43 - case PhamePostTransaction::TYPE_HEADERIMAGE: 44 - return $object->getHeaderImagePHID(); 45 - } 46 - } 47 - 48 - protected function getCustomTransactionNewValue( 49 - PhabricatorLiskDAO $object, 50 - PhabricatorApplicationTransaction $xaction) { 51 - 52 - switch ($xaction->getTransactionType()) { 53 - case PhamePostTransaction::TYPE_TITLE: 54 - case PhamePostTransaction::TYPE_SUBTITLE: 55 - case PhamePostTransaction::TYPE_BODY: 56 - case PhamePostTransaction::TYPE_VISIBILITY: 57 - case PhamePostTransaction::TYPE_HEADERIMAGE: 58 - case PhamePostTransaction::TYPE_BLOG: 59 - return $xaction->getNewValue(); 60 - } 14 + public function getCreateObjectTitle($author, $object) { 15 + return pht('%s created this post.', $author); 61 16 } 62 17 63 - protected function applyCustomInternalTransaction( 64 - PhabricatorLiskDAO $object, 65 - PhabricatorApplicationTransaction $xaction) { 66 - 67 - switch ($xaction->getTransactionType()) { 68 - case PhamePostTransaction::TYPE_TITLE: 69 - return $object->setTitle($xaction->getNewValue()); 70 - case PhamePostTransaction::TYPE_SUBTITLE: 71 - return $object->setSubtitle($xaction->getNewValue()); 72 - case PhamePostTransaction::TYPE_BODY: 73 - return $object->setBody($xaction->getNewValue()); 74 - case PhamePostTransaction::TYPE_BLOG: 75 - return $object->setBlogPHID($xaction->getNewValue()); 76 - case PhamePostTransaction::TYPE_HEADERIMAGE: 77 - return $object->setHeaderImagePHID($xaction->getNewValue()); 78 - case PhamePostTransaction::TYPE_VISIBILITY: 79 - if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) { 80 - $object->setDatePublished(0); 81 - } else if ($xaction->getNewValue() == 82 - PhameConstants::VISIBILITY_ARCHIVED) { 83 - $object->setDatePublished(0); 84 - } else { 85 - $object->setDatePublished(PhabricatorTime::getNow()); 86 - } 87 - return $object->setVisibility($xaction->getNewValue()); 88 - } 89 - 90 - return parent::applyCustomInternalTransaction($object, $xaction); 91 - } 92 - 93 - protected function applyCustomExternalTransaction( 94 - PhabricatorLiskDAO $object, 95 - PhabricatorApplicationTransaction $xaction) { 96 - 97 - switch ($xaction->getTransactionType()) { 98 - case PhamePostTransaction::TYPE_TITLE: 99 - case PhamePostTransaction::TYPE_SUBTITLE: 100 - case PhamePostTransaction::TYPE_BODY: 101 - case PhamePostTransaction::TYPE_VISIBILITY: 102 - case PhamePostTransaction::TYPE_HEADERIMAGE: 103 - case PhamePostTransaction::TYPE_BLOG: 104 - return; 105 - } 106 - 107 - return parent::applyCustomExternalTransaction($object, $xaction); 18 + public function getCreateObjectTitleForFeed($author, $object) { 19 + return pht('%s created %s.', $author, $object); 108 20 } 109 21 110 - protected function validateTransaction( 111 - PhabricatorLiskDAO $object, 112 - $type, 113 - array $xactions) { 114 - 115 - $errors = parent::validateTransaction($object, $type, $xactions); 116 - 117 - switch ($type) { 118 - case PhamePostTransaction::TYPE_TITLE: 119 - $missing = $this->validateIsEmptyTextField( 120 - $object->getTitle(), 121 - $xactions); 122 - 123 - if ($missing) { 124 - $error = new PhabricatorApplicationTransactionValidationError( 125 - $type, 126 - pht('Required'), 127 - pht('Title is required.'), 128 - nonempty(last($xactions), null)); 129 - 130 - $error->setIsMissingFieldError(true); 131 - $errors[] = $error; 132 - } 133 - break; 134 - case PhamePostTransaction::TYPE_BLOG: 135 - if ($this->getIsNewObject()) { 136 - if (!$xactions) { 137 - $error = new PhabricatorApplicationTransactionValidationError( 138 - $type, 139 - pht('Required'), 140 - pht( 141 - 'When creating a post, you must specify which blog it '. 142 - 'should belong to.'), 143 - null); 144 - 145 - $error->setIsMissingFieldError(true); 146 - 147 - $errors[] = $error; 148 - break; 149 - } 150 - } 151 - 152 - foreach ($xactions as $xaction) { 153 - $new_phid = $xaction->getNewValue(); 22 + public function getTransactionTypes() { 23 + $types = parent::getTransactionTypes(); 24 + $types[] = PhabricatorTransactions::TYPE_COMMENT; 154 25 155 - $blog = id(new PhameBlogQuery()) 156 - ->setViewer($this->getActor()) 157 - ->withPHIDs(array($new_phid)) 158 - ->requireCapabilities( 159 - array( 160 - PhabricatorPolicyCapability::CAN_VIEW, 161 - PhabricatorPolicyCapability::CAN_EDIT, 162 - )) 163 - ->execute(); 164 - 165 - if ($blog) { 166 - continue; 167 - } 168 - 169 - $errors[] = new PhabricatorApplicationTransactionValidationError( 170 - $type, 171 - pht('Invalid'), 172 - pht( 173 - 'The specified blog PHID ("%s") is not valid. You can only '. 174 - 'create a post on (or move a post into) a blog which you '. 175 - 'have permission to see and edit.', 176 - $new_phid), 177 - $xaction); 178 - } 179 - 180 - break; 181 - } 182 - return $errors; 26 + return $types; 183 27 } 184 28 185 29 protected function shouldSendMail(
+5 -265
src/applications/phame/storage/PhamePostTransaction.php
··· 1 1 <?php 2 2 3 3 final class PhamePostTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_TITLE = 'phame.post.title'; 7 - const TYPE_SUBTITLE = 'phame.post.subtitle'; 8 - const TYPE_BODY = 'phame.post.body'; 9 - const TYPE_VISIBILITY = 'phame.post.visibility'; 10 - const TYPE_HEADERIMAGE = 'phame.post.headerimage'; 11 - const TYPE_BLOG = 'phame.post.blog'; 4 + extends PhabricatorModularTransaction { 12 5 13 6 const MAILTAG_CONTENT = 'phame-post-content'; 14 7 const MAILTAG_SUBSCRIBERS = 'phame-post-subscribers'; ··· 23 16 return PhabricatorPhamePostPHIDType::TYPECONST; 24 17 } 25 18 26 - public function getApplicationTransactionCommentObject() { 27 - return new PhamePostTransactionComment(); 28 - } 29 - 30 - public function getRemarkupBlocks() { 31 - $blocks = parent::getRemarkupBlocks(); 32 - 33 - switch ($this->getTransactionType()) { 34 - case self::TYPE_BODY: 35 - $blocks[] = $this->getNewValue(); 36 - break; 37 - } 38 - 39 - return $blocks; 19 + public function getBaseTransactionClass() { 20 + return 'PhamePostTransactionType'; 40 21 } 41 22 42 - public function shouldHide() { 43 - return parent::shouldHide(); 44 - } 45 - 46 - public function getRequiredHandlePHIDs() { 47 - $phids = parent::getRequiredHandlePHIDs(); 48 - 49 - switch ($this->getTransactionType()) { 50 - case self::TYPE_BLOG: 51 - $old = $this->getOldValue(); 52 - $new = $this->getNewValue(); 53 - 54 - if ($old) { 55 - $phids[] = $old; 56 - } 57 - 58 - if ($new) { 59 - $phids[] = $new; 60 - } 61 - break; 62 - } 63 - 64 - return $phids; 65 - } 66 - 67 - 68 - public function getIcon() { 69 - $old = $this->getOldValue(); 70 - $new = $this->getNewValue(); 71 - switch ($this->getTransactionType()) { 72 - case PhabricatorTransactions::TYPE_CREATE: 73 - return 'fa-plus'; 74 - break; 75 - case self::TYPE_HEADERIMAGE: 76 - return 'fa-camera-retro'; 77 - break; 78 - case self::TYPE_VISIBILITY: 79 - if ($new == PhameConstants::VISIBILITY_PUBLISHED) { 80 - return 'fa-globe'; 81 - } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 82 - return 'fa-ban'; 83 - } else { 84 - return 'fa-eye-slash'; 85 - } 86 - break; 87 - } 88 - return parent::getIcon(); 23 + public function getApplicationTransactionCommentObject() { 24 + return new PhamePostTransactionComment(); 89 25 } 90 26 91 27 public function getMailTags() { ··· 108 44 break; 109 45 } 110 46 return $tags; 111 - } 112 - 113 - 114 - public function getTitle() { 115 - $author_phid = $this->getAuthorPHID(); 116 - $object_phid = $this->getObjectPHID(); 117 - 118 - $old = $this->getOldValue(); 119 - $new = $this->getNewValue(); 120 - 121 - $type = $this->getTransactionType(); 122 - switch ($type) { 123 - case PhabricatorTransactions::TYPE_CREATE: 124 - return pht( 125 - '%s authored this post.', 126 - $this->renderHandleLink($author_phid)); 127 - case self::TYPE_BLOG: 128 - return pht( 129 - '%s moved this post from "%s" to "%s".', 130 - $this->renderHandleLink($author_phid), 131 - $this->renderHandleLink($old), 132 - $this->renderHandleLink($new)); 133 - case self::TYPE_TITLE: 134 - if ($old === null) { 135 - return pht( 136 - '%s authored this post.', 137 - $this->renderHandleLink($author_phid)); 138 - } else { 139 - return pht( 140 - '%s updated the post\'s name to "%s".', 141 - $this->renderHandleLink($author_phid), 142 - $new); 143 - } 144 - break; 145 - case self::TYPE_SUBTITLE: 146 - if ($old === null) { 147 - return pht( 148 - '%s set the post\'s subtitle to "%s".', 149 - $this->renderHandleLink($author_phid), 150 - $new); 151 - } else { 152 - return pht( 153 - '%s updated the post\'s subtitle to "%s".', 154 - $this->renderHandleLink($author_phid), 155 - $new); 156 - } 157 - break; 158 - case self::TYPE_BODY: 159 - return pht( 160 - '%s updated the blog post.', 161 - $this->renderHandleLink($author_phid)); 162 - break; 163 - case self::TYPE_HEADERIMAGE: 164 - return pht( 165 - '%s updated the header image.', 166 - $this->renderHandleLink($author_phid)); 167 - break; 168 - case self::TYPE_VISIBILITY: 169 - if ($new == PhameConstants::VISIBILITY_DRAFT) { 170 - return pht( 171 - '%s marked this post as a draft.', 172 - $this->renderHandleLink($author_phid)); 173 - } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 174 - return pht( 175 - '%s archived this post.', 176 - $this->renderHandleLink($author_phid)); 177 - } else { 178 - return pht( 179 - '%s published this post.', 180 - $this->renderHandleLink($author_phid)); 181 - } 182 - break; 183 - } 184 - 185 - return parent::getTitle(); 186 - } 187 - 188 - public function getTitleForFeed() { 189 - $author_phid = $this->getAuthorPHID(); 190 - $object_phid = $this->getObjectPHID(); 191 - 192 - $old = $this->getOldValue(); 193 - $new = $this->getNewValue(); 194 - 195 - $type = $this->getTransactionType(); 196 - switch ($type) { 197 - case PhabricatorTransactions::TYPE_CREATE: 198 - return pht( 199 - '%s authored %s.', 200 - $this->renderHandleLink($author_phid), 201 - $this->renderHandleLink($object_phid)); 202 - case self::TYPE_BLOG: 203 - return pht( 204 - '%s moved post "%s" from "%s" to "%s".', 205 - $this->renderHandleLink($author_phid), 206 - $this->renderHandleLink($object_phid), 207 - $this->renderHandleLink($old), 208 - $this->renderHandleLink($new)); 209 - case self::TYPE_TITLE: 210 - if ($old === null) { 211 - return pht( 212 - '%s authored %s.', 213 - $this->renderHandleLink($author_phid), 214 - $this->renderHandleLink($object_phid)); 215 - } else { 216 - return pht( 217 - '%s updated the name for %s.', 218 - $this->renderHandleLink($author_phid), 219 - $this->renderHandleLink($object_phid)); 220 - } 221 - break; 222 - case self::TYPE_SUBTITLE: 223 - return pht( 224 - '%s updated the subtitle for %s.', 225 - $this->renderHandleLink($author_phid), 226 - $this->renderHandleLink($object_phid)); 227 - break; 228 - case self::TYPE_BODY: 229 - return pht( 230 - '%s updated the blog post %s.', 231 - $this->renderHandleLink($author_phid), 232 - $this->renderHandleLink($object_phid)); 233 - break; 234 - case self::TYPE_HEADERIMAGE: 235 - return pht( 236 - '%s updated the header image for post %s.', 237 - $this->renderHandleLink($author_phid), 238 - $this->renderHandleLink($object_phid)); 239 - break; 240 - case self::TYPE_VISIBILITY: 241 - if ($new == PhameConstants::VISIBILITY_DRAFT) { 242 - return pht( 243 - '%s marked %s as a draft.', 244 - $this->renderHandleLink($author_phid), 245 - $this->renderHandleLink($object_phid)); 246 - } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 247 - return pht( 248 - '%s marked %s as archived.', 249 - $this->renderHandleLink($author_phid), 250 - $this->renderHandleLink($object_phid)); 251 - } else { 252 - return pht( 253 - '%s published %s.', 254 - $this->renderHandleLink($author_phid), 255 - $this->renderHandleLink($object_phid)); 256 - } 257 - break; 258 - } 259 - 260 - return parent::getTitleForFeed(); 261 - } 262 - 263 - public function getRemarkupBodyForFeed(PhabricatorFeedStory $story) { 264 - $old = $this->getOldValue(); 265 - 266 - switch ($this->getTransactionType()) { 267 - case self::TYPE_BODY: 268 - if ($old === null) { 269 - return $this->getNewValue(); 270 - } 271 - break; 272 - } 273 - 274 - return null; 275 - } 276 - 277 - public function getColor() { 278 - switch ($this->getTransactionType()) { 279 - case PhabricatorTransactions::TYPE_CREATE: 280 - return PhabricatorTransactions::COLOR_GREEN; 281 - } 282 - return parent::getColor(); 283 - } 284 - 285 - public function hasChangeDetails() { 286 - switch ($this->getTransactionType()) { 287 - case self::TYPE_BODY: 288 - return ($this->getOldValue() !== null); 289 - } 290 - 291 - return parent::hasChangeDetails(); 292 - } 293 - 294 - public function renderChangeDetails(PhabricatorUser $viewer) { 295 - switch ($this->getTransactionType()) { 296 - case self::TYPE_BODY: 297 - $old = $this->getOldValue(); 298 - $new = $this->getNewValue(); 299 - 300 - return $this->renderTextCorpusChangeDetails( 301 - $viewer, 302 - $old, 303 - $new); 304 - } 305 - 306 - return parent::renderChangeDetails($viewer); 307 47 } 308 48 309 49 }
+1 -1
src/applications/phame/xaction/PhameBlogNameTransaction.php
··· 23 23 24 24 public function getTitleForFeed() { 25 25 return pht( 26 - '%s renamed %s blog froms %s to %s.', 26 + '%s renamed %s blog from %s to %s.', 27 27 $this->renderAuthor(), 28 28 $this->renderObject(), 29 29 $this->renderOldValue(),
+5 -5
src/applications/phame/xaction/PhameBlogStatusTransaction.php
··· 45 45 46 46 public function getIcon() { 47 47 $new = $this->getNewValue(); 48 - if ($new == PhameBlog::STATUS_ARCHIVED) { 49 - return 'fa-ban'; 50 - } else { 51 - return 'fa-check'; 52 - } 48 + if ($new == PhameBlog::STATUS_ARCHIVED) { 49 + return 'fa-ban'; 50 + } else { 51 + return 'fa-check'; 53 52 } 53 + } 54 54 55 55 }
+64
src/applications/phame/xaction/PhamePostBlogTransaction.php
··· 1 + <?php 2 + 3 + final class PhamePostBlogTransaction 4 + extends PhamePostTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.post.blog'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getBlogPHID(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setBlogPHID($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s changed the blog for this post.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s changed the blog for post %s.', 25 + $this->renderAuthor(), 26 + $this->renderObject()); 27 + } 28 + 29 + public function validateTransactions($object, array $xactions) { 30 + $errors = array(); 31 + 32 + if ($this->isEmptyTextTransaction($object->getBlogPHID(), $xactions)) { 33 + $errors[] = $this->newRequiredError( 34 + pht('Posts must be attached to a blog.')); 35 + } 36 + 37 + foreach ($xactions as $xaction) { 38 + $new_phid = $xaction->getNewValue(); 39 + 40 + $blog = id(new PhameBlogQuery()) 41 + ->setViewer($this->getActor()) 42 + ->withPHIDs(array($new_phid)) 43 + ->requireCapabilities( 44 + array( 45 + PhabricatorPolicyCapability::CAN_VIEW, 46 + PhabricatorPolicyCapability::CAN_EDIT, 47 + )) 48 + ->execute(); 49 + 50 + if ($blog) { 51 + continue; 52 + } 53 + 54 + $errors[] = $this->newInvalidError( 55 + pht('The specified blog PHID ("%s") is not valid. You can only '. 56 + 'create a post on (or move a post into) a blog which you '. 57 + 'have permission to see and edit.', 58 + $new_phid)); 59 + } 60 + 61 + return $errors; 62 + } 63 + 64 + }
+60
src/applications/phame/xaction/PhamePostBodyTransaction.php
··· 1 + <?php 2 + 3 + final class PhamePostBodyTransaction 4 + extends PhamePostTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.post.body'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getBody(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setBody($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the post content.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s updated the post content for %s.', 25 + $this->renderAuthor(), 26 + $this->renderObject()); 27 + } 28 + 29 + public function hasChangeDetailView() { 30 + return true; 31 + } 32 + 33 + public function getMailDiffSectionHeader() { 34 + return pht('CHANGES TO POST CONTENT'); 35 + } 36 + 37 + public function newChangeDetailView() { 38 + $viewer = $this->getViewer(); 39 + 40 + return id(new PhabricatorApplicationTransactionTextDiffDetailView()) 41 + ->setViewer($viewer) 42 + ->setOldText($this->getOldValue()) 43 + ->setNewText($this->getNewValue()); 44 + } 45 + 46 + public function newRemarkupChanges() { 47 + $changes = array(); 48 + 49 + $changes[] = $this->newRemarkupChange() 50 + ->setOldValue($this->getOldValue()) 51 + ->setNewValue($this->getNewValue()); 52 + 53 + return $changes; 54 + } 55 + 56 + public function getIcon() { 57 + return 'fa-file-text-o'; 58 + } 59 + 60 + }
+33
src/applications/phame/xaction/PhamePostHeaderImageTransaction.php
··· 1 + <?php 2 + 3 + final class PhamePostHeaderImageTransaction 4 + extends PhamePostTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.post.headerimage'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getHeaderImagePHID(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setHeaderImagePHID($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s changed the header image for this post.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s changed the header image for post %s.', 25 + $this->renderAuthor(), 26 + $this->renderObject()); 27 + } 28 + 29 + public function getIcon() { 30 + return 'fa-camera'; 31 + } 32 + 33 + }
+63
src/applications/phame/xaction/PhamePostSubtitleTransaction.php
··· 1 + <?php 2 + 3 + final class PhamePostSubtitleTransaction 4 + extends PhamePostTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.post.subtitle'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getSubtitle(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setSubtitle($value); 14 + } 15 + 16 + public function getTitle() { 17 + $old = $this->getOldValue(); 18 + if ($old === null) { 19 + return pht( 20 + '%s set this post\'s subtitle to "%s".', 21 + $this->renderAuthor(), 22 + $this->renderNewValue()); 23 + } else { 24 + return pht( 25 + '%s updated the post\'s subtitle to "%s".', 26 + $this->renderAuthor(), 27 + $this->renderNewValue()); 28 + } 29 + } 30 + 31 + public function getTitleForFeed() { 32 + $old = $this->getOldValue(); 33 + if ($old === null) { 34 + return pht( 35 + '%s set the subtitle for %s.', 36 + $this->renderAuthor(), 37 + $this->renderObject()); 38 + } else { 39 + return pht( 40 + '%s updated the subtitle for %s.', 41 + $this->renderAuthor(), 42 + $this->renderObject()); 43 + } 44 + } 45 + 46 + public function validateTransactions($object, array $xactions) { 47 + $errors = array(); 48 + 49 + $max_length = $object->getColumnMaximumByteLength('subtitle'); 50 + foreach ($xactions as $xaction) { 51 + $new_value = $xaction->getNewValue(); 52 + $new_length = strlen($new_value); 53 + if ($new_length > $max_length) { 54 + $errors[] = $this->newInvalidError( 55 + pht('The subtitle can be no longer than %s characters.', 56 + new PhutilNumber($max_length))); 57 + } 58 + } 59 + 60 + return $errors; 61 + } 62 + 63 + }
+55
src/applications/phame/xaction/PhamePostTitleTransaction.php
··· 1 + <?php 2 + 3 + final class PhamePostTitleTransaction 4 + extends PhamePostTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.post.title'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getTitle(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setTitle($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s renamed this blog post 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 blog post from %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->getTitle(), $xactions)) { 37 + $errors[] = $this->newRequiredError( 38 + pht('Posts must have a title.')); 39 + } 40 + 41 + $max_length = $object->getColumnMaximumByteLength('title'); 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 title can be no longer than %s characters.', 48 + new PhutilNumber($max_length))); 49 + } 50 + } 51 + 52 + return $errors; 53 + } 54 + 55 + }
+4
src/applications/phame/xaction/PhamePostTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PhamePostTransactionType 4 + extends PhabricatorModularTransactionType {}
+70
src/applications/phame/xaction/PhamePostVisibilityTransaction.php
··· 1 + <?php 2 + 3 + final class PhamePostVisibilityTransaction 4 + extends PhamePostTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.post.visibility'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getVisibility(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + if ($value == PhameConstants::VISIBILITY_DRAFT) { 14 + $object->setDatePublished(0); 15 + } else if ($value == PhameConstants::VISIBILITY_ARCHIVED) { 16 + $object->setDatePublished(0); 17 + } else { 18 + $object->setDatePublished(PhabricatorTime::getNow()); 19 + } 20 + $object->setVisibility($value); 21 + } 22 + 23 + public function getTitle() { 24 + $new = $this->getNewValue(); 25 + if ($new == PhameConstants::VISIBILITY_DRAFT) { 26 + return pht( 27 + '%s marked this post as a draft.', 28 + $this->renderAuthor()); 29 + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 30 + return pht( 31 + '%s archived this post.', 32 + $this->renderAuthor()); 33 + } else { 34 + return pht( 35 + '%s published this post.', 36 + $this->renderAuthor()); 37 + } 38 + } 39 + 40 + public function getTitleForFeed() { 41 + $new = $this->getNewValue(); 42 + if ($new == PhameConstants::VISIBILITY_DRAFT) { 43 + return pht( 44 + '%s marked %s as a draft.', 45 + $this->renderAuthor(), 46 + $this->renderObject()); 47 + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 48 + return pht( 49 + '%s marked %s as archived.', 50 + $this->renderAuthor(), 51 + $this->renderObject()); 52 + } else { 53 + return pht( 54 + '%s published %s.', 55 + $this->renderAuthor(), 56 + $this->renderObject()); 57 + } 58 + } 59 + 60 + public function getIcon() { 61 + $new = $this->getNewValue(); 62 + if ($new == PhameConstants::VISIBILITY_PUBLISHED) { 63 + return 'fa-rss'; 64 + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 65 + return 'fa-ban'; 66 + } else { 67 + return 'fa-eye-slash'; 68 + } 69 + } 70 + }