@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.

Modernize PhameBlog with modular transactions

Summary: Moves PhameBlog over to the wonderful world of modular transactions and the riches that lay beyond...

Test Plan:
- Create Blog
- Edit Blog
- Set Header
- Delete Header
- Add picture
- Archive blog
- Set incorrect domain values
- Be irresponsible with subtitle length
- Activate blog
- Change description

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

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

+611 -600
+21 -1
src/__phutil_library_map__.php
··· 4232 4232 'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php', 4233 4233 'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php', 4234 4234 'PhameBlogDatasource' => 'applications/phame/typeahead/PhameBlogDatasource.php', 4235 + 'PhameBlogDescriptionTransaction' => 'applications/phame/xaction/PhameBlogDescriptionTransaction.php', 4235 4236 'PhameBlogEditConduitAPIMethod' => 'applications/phame/conduit/PhameBlogEditConduitAPIMethod.php', 4236 4237 'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php', 4237 4238 'PhameBlogEditEngine' => 'applications/phame/editor/PhameBlogEditEngine.php', 4238 4239 'PhameBlogEditor' => 'applications/phame/editor/PhameBlogEditor.php', 4239 4240 'PhameBlogFeedController' => 'applications/phame/controller/blog/PhameBlogFeedController.php', 4241 + 'PhameBlogFullDomainTransaction' => 'applications/phame/xaction/PhameBlogFullDomainTransaction.php', 4240 4242 'PhameBlogFulltextEngine' => 'applications/phame/search/PhameBlogFulltextEngine.php', 4243 + 'PhameBlogHeaderImageTransaction' => 'applications/phame/xaction/PhameBlogHeaderImageTransaction.php', 4241 4244 'PhameBlogHeaderPictureController' => 'applications/phame/controller/blog/PhameBlogHeaderPictureController.php', 4242 4245 'PhameBlogListController' => 'applications/phame/controller/blog/PhameBlogListController.php', 4243 4246 'PhameBlogListView' => 'applications/phame/view/PhameBlogListView.php', 4244 4247 'PhameBlogManageController' => 'applications/phame/controller/blog/PhameBlogManageController.php', 4248 + 'PhameBlogNameTransaction' => 'applications/phame/xaction/PhameBlogNameTransaction.php', 4249 + 'PhameBlogParentDomainTransaction' => 'applications/phame/xaction/PhameBlogParentDomainTransaction.php', 4250 + 'PhameBlogParentSiteTransaction' => 'applications/phame/xaction/PhameBlogParentSiteTransaction.php', 4251 + 'PhameBlogProfileImageTransaction' => 'applications/phame/xaction/PhameBlogProfileImageTransaction.php', 4245 4252 'PhameBlogProfilePictureController' => 'applications/phame/controller/blog/PhameBlogProfilePictureController.php', 4246 4253 'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php', 4247 4254 'PhameBlogReplyHandler' => 'applications/phame/mail/PhameBlogReplyHandler.php', 4248 4255 'PhameBlogSearchConduitAPIMethod' => 'applications/phame/conduit/PhameBlogSearchConduitAPIMethod.php', 4249 4256 'PhameBlogSearchEngine' => 'applications/phame/query/PhameBlogSearchEngine.php', 4250 4257 'PhameBlogSite' => 'applications/phame/site/PhameBlogSite.php', 4258 + 'PhameBlogStatusTransaction' => 'applications/phame/xaction/PhameBlogStatusTransaction.php', 4259 + 'PhameBlogSubtitleTransaction' => 'applications/phame/xaction/PhameBlogSubtitleTransaction.php', 4251 4260 'PhameBlogTransaction' => 'applications/phame/storage/PhameBlogTransaction.php', 4252 4261 'PhameBlogTransactionQuery' => 'applications/phame/query/PhameBlogTransactionQuery.php', 4262 + 'PhameBlogTransactionType' => 'applications/phame/xaction/PhameBlogTransactionType.php', 4253 4263 'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php', 4254 4264 'PhameConstants' => 'applications/phame/constants/PhameConstants.php', 4255 4265 'PhameController' => 'applications/phame/controller/PhameController.php', ··· 9690 9700 'PhameBlogController' => 'PhameController', 9691 9701 'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability', 9692 9702 'PhameBlogDatasource' => 'PhabricatorTypeaheadDatasource', 9703 + 'PhameBlogDescriptionTransaction' => 'PhameBlogTransactionType', 9693 9704 'PhameBlogEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 9694 9705 'PhameBlogEditController' => 'PhameBlogController', 9695 9706 'PhameBlogEditEngine' => 'PhabricatorEditEngine', 9696 9707 'PhameBlogEditor' => 'PhabricatorApplicationTransactionEditor', 9697 9708 'PhameBlogFeedController' => 'PhameBlogController', 9709 + 'PhameBlogFullDomainTransaction' => 'PhameBlogTransactionType', 9698 9710 'PhameBlogFulltextEngine' => 'PhabricatorFulltextEngine', 9711 + 'PhameBlogHeaderImageTransaction' => 'PhameBlogTransactionType', 9699 9712 'PhameBlogHeaderPictureController' => 'PhameBlogController', 9700 9713 'PhameBlogListController' => 'PhameBlogController', 9701 9714 'PhameBlogListView' => 'AphrontTagView', 9702 9715 'PhameBlogManageController' => 'PhameBlogController', 9716 + 'PhameBlogNameTransaction' => 'PhameBlogTransactionType', 9717 + 'PhameBlogParentDomainTransaction' => 'PhameBlogTransactionType', 9718 + 'PhameBlogParentSiteTransaction' => 'PhameBlogTransactionType', 9719 + 'PhameBlogProfileImageTransaction' => 'PhameBlogTransactionType', 9703 9720 'PhameBlogProfilePictureController' => 'PhameBlogController', 9704 9721 'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 9705 9722 'PhameBlogReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 9706 9723 'PhameBlogSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 9707 9724 'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine', 9708 9725 'PhameBlogSite' => 'PhameSite', 9709 - 'PhameBlogTransaction' => 'PhabricatorApplicationTransaction', 9726 + 'PhameBlogStatusTransaction' => 'PhameBlogTransactionType', 9727 + 'PhameBlogSubtitleTransaction' => 'PhameBlogTransactionType', 9728 + 'PhameBlogTransaction' => 'PhabricatorModularTransaction', 9710 9729 'PhameBlogTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 9730 + 'PhameBlogTransactionType' => 'PhabricatorModularTransactionType', 9711 9731 'PhameBlogViewController' => 'PhameLiveController', 9712 9732 'PhameConstants' => 'Phobject', 9713 9733 'PhameController' => 'PhabricatorController',
+1 -1
src/applications/phame/controller/blog/PhameBlogArchiveController.php
··· 32 32 $xactions = array(); 33 33 34 34 $xactions[] = id(new PhameBlogTransaction()) 35 - ->setTransactionType(PhameBlogTransaction::TYPE_STATUS) 35 + ->setTransactionType(PhameBlogStatusTransaction::TRANSACTIONTYPE) 36 36 ->setNewValue($new_status); 37 37 38 38 id(new PhameBlogEditor())
+1 -1
src/applications/phame/controller/blog/PhameBlogHeaderPictureController.php
··· 61 61 62 62 $xactions = array(); 63 63 $xactions[] = id(new PhameBlogTransaction()) 64 - ->setTransactionType(PhameBlogTransaction::TYPE_HEADERIMAGE) 64 + ->setTransactionType(PhameBlogHeaderImageTransaction::TRANSACTIONTYPE) 65 65 ->setNewValue($new_value); 66 66 67 67 $editor = id(new PhameBlogEditor())
+2 -1
src/applications/phame/controller/blog/PhameBlogProfilePictureController.php
··· 76 76 77 77 $xactions = array(); 78 78 $xactions[] = id(new PhameBlogTransaction()) 79 - ->setTransactionType(PhameBlogTransaction::TYPE_PROFILEIMAGE) 79 + ->setTransactionType( 80 + PhameBlogProfileImageTransaction::TRANSACTIONTYPE) 80 81 ->setNewValue($new_value); 81 82 82 83 $editor = id(new PhameBlogEditor())
+7 -7
src/applications/phame/editor/PhameBlogEditEngine.php
··· 75 75 ->setDescription(pht('Blog name.')) 76 76 ->setConduitDescription(pht('Retitle the blog.')) 77 77 ->setConduitTypeDescription(pht('New blog title.')) 78 - ->setTransactionType(PhameBlogTransaction::TYPE_NAME) 78 + ->setTransactionType(PhameBlogNameTransaction::TRANSACTIONTYPE) 79 79 ->setValue($object->getName()), 80 80 id(new PhabricatorTextEditField()) 81 81 ->setKey('subtitle') ··· 83 83 ->setDescription(pht('Blog subtitle.')) 84 84 ->setConduitDescription(pht('Change the blog subtitle.')) 85 85 ->setConduitTypeDescription(pht('New blog subtitle.')) 86 - ->setTransactionType(PhameBlogTransaction::TYPE_SUBTITLE) 86 + ->setTransactionType(PhameBlogSubtitleTransaction::TRANSACTIONTYPE) 87 87 ->setValue($object->getSubtitle()), 88 88 id(new PhabricatorRemarkupEditField()) 89 89 ->setKey('description') ··· 91 91 ->setDescription(pht('Blog description.')) 92 92 ->setConduitDescription(pht('Change the blog description.')) 93 93 ->setConduitTypeDescription(pht('New blog description.')) 94 - ->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION) 94 + ->setTransactionType(PhameBlogDescriptionTransaction::TRANSACTIONTYPE) 95 95 ->setValue($object->getDescription()), 96 96 id(new PhabricatorTextEditField()) 97 97 ->setKey('domainFullURI') ··· 104 104 ->setConduitDescription(pht('Change the blog full domain URI.')) 105 105 ->setConduitTypeDescription(pht('New blog full domain URI.')) 106 106 ->setValue($object->getDomainFullURI()) 107 - ->setTransactionType(PhameBlogTransaction::TYPE_FULLDOMAIN), 107 + ->setTransactionType(PhameBlogFullDomainTransaction::TRANSACTIONTYPE), 108 108 id(new PhabricatorTextEditField()) 109 109 ->setKey('parentSite') 110 110 ->setLabel(pht('Parent Site Name')) ··· 112 112 ->setConduitDescription(pht('Change the blog parent site name.')) 113 113 ->setConduitTypeDescription(pht('New blog parent site name.')) 114 114 ->setValue($object->getParentSite()) 115 - ->setTransactionType(PhameBlogTransaction::TYPE_PARENTSITE), 115 + ->setTransactionType(PhameBlogParentSiteTransaction::TRANSACTIONTYPE), 116 116 id(new PhabricatorTextEditField()) 117 117 ->setKey('parentDomain') 118 118 ->setLabel(pht('Parent Site URI')) ··· 120 120 ->setConduitDescription(pht('Change the blog parent domain.')) 121 121 ->setConduitTypeDescription(pht('New blog parent domain.')) 122 122 ->setValue($object->getParentDomain()) 123 - ->setTransactionType(PhameBlogTransaction::TYPE_PARENTDOMAIN), 123 + ->setTransactionType(PhameBlogParentDomainTransaction::TRANSACTIONTYPE), 124 124 id(new PhabricatorSelectEditField()) 125 125 ->setKey('status') 126 126 ->setLabel(pht('Status')) 127 - ->setTransactionType(PhameBlogTransaction::TYPE_STATUS) 127 + ->setTransactionType(PhameBlogStatusTransaction::TRANSACTIONTYPE) 128 128 ->setIsConduitOnly(true) 129 129 ->setOptions(PhameBlog::getStatusNameMap()) 130 130 ->setDescription(pht('Active or archived status.'))
+8 -237
src/applications/phame/editor/PhameBlogEditor.php
··· 11 11 return pht('Phame Blogs'); 12 12 } 13 13 14 + public function getCreateObjectTitle($author, $object) { 15 + return pht('%s created this blog.', $author); 16 + } 17 + 18 + public function getCreateObjectTitleForFeed($author, $object) { 19 + return pht('%s created %s.', $author, $object); 20 + } 21 + 14 22 public function getTransactionTypes() { 15 23 $types = parent::getTransactionTypes(); 16 - 17 - $types[] = PhameBlogTransaction::TYPE_NAME; 18 - $types[] = PhameBlogTransaction::TYPE_SUBTITLE; 19 - $types[] = PhameBlogTransaction::TYPE_DESCRIPTION; 20 - $types[] = PhameBlogTransaction::TYPE_FULLDOMAIN; 21 - $types[] = PhameBlogTransaction::TYPE_PARENTSITE; 22 - $types[] = PhameBlogTransaction::TYPE_PARENTDOMAIN; 23 - $types[] = PhameBlogTransaction::TYPE_STATUS; 24 - $types[] = PhameBlogTransaction::TYPE_HEADERIMAGE; 25 - $types[] = PhameBlogTransaction::TYPE_PROFILEIMAGE; 26 - 27 24 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 28 25 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 29 26 30 27 return $types; 31 - } 32 - 33 - protected function getCustomTransactionOldValue( 34 - PhabricatorLiskDAO $object, 35 - PhabricatorApplicationTransaction $xaction) { 36 - 37 - switch ($xaction->getTransactionType()) { 38 - case PhameBlogTransaction::TYPE_NAME: 39 - return $object->getName(); 40 - case PhameBlogTransaction::TYPE_SUBTITLE: 41 - return $object->getSubtitle(); 42 - case PhameBlogTransaction::TYPE_DESCRIPTION: 43 - return $object->getDescription(); 44 - case PhameBlogTransaction::TYPE_FULLDOMAIN: 45 - return $object->getDomainFullURI(); 46 - case PhameBlogTransaction::TYPE_PARENTSITE: 47 - return $object->getParentSite(); 48 - case PhameBlogTransaction::TYPE_PARENTDOMAIN: 49 - return $object->getParentDomain(); 50 - case PhameBlogTransaction::TYPE_PROFILEIMAGE: 51 - return $object->getProfileImagePHID(); 52 - case PhameBlogTransaction::TYPE_HEADERIMAGE: 53 - return $object->getHeaderImagePHID(); 54 - case PhameBlogTransaction::TYPE_STATUS: 55 - return $object->getStatus(); 56 - } 57 - } 58 - 59 - protected function getCustomTransactionNewValue( 60 - PhabricatorLiskDAO $object, 61 - PhabricatorApplicationTransaction $xaction) { 62 - 63 - switch ($xaction->getTransactionType()) { 64 - case PhameBlogTransaction::TYPE_NAME: 65 - case PhameBlogTransaction::TYPE_SUBTITLE: 66 - case PhameBlogTransaction::TYPE_DESCRIPTION: 67 - case PhameBlogTransaction::TYPE_STATUS: 68 - case PhameBlogTransaction::TYPE_PARENTSITE: 69 - case PhameBlogTransaction::TYPE_PARENTDOMAIN: 70 - case PhameBlogTransaction::TYPE_PROFILEIMAGE: 71 - case PhameBlogTransaction::TYPE_HEADERIMAGE: 72 - return $xaction->getNewValue(); 73 - case PhameBlogTransaction::TYPE_FULLDOMAIN: 74 - $domain = $xaction->getNewValue(); 75 - if (!strlen($xaction->getNewValue())) { 76 - return null; 77 - } 78 - return $domain; 79 - } 80 - } 81 - 82 - protected function applyCustomInternalTransaction( 83 - PhabricatorLiskDAO $object, 84 - PhabricatorApplicationTransaction $xaction) { 85 - 86 - switch ($xaction->getTransactionType()) { 87 - case PhameBlogTransaction::TYPE_NAME: 88 - return $object->setName($xaction->getNewValue()); 89 - case PhameBlogTransaction::TYPE_SUBTITLE: 90 - return $object->setSubtitle($xaction->getNewValue()); 91 - case PhameBlogTransaction::TYPE_DESCRIPTION: 92 - return $object->setDescription($xaction->getNewValue()); 93 - case PhameBlogTransaction::TYPE_FULLDOMAIN: 94 - $new_value = $xaction->getNewValue(); 95 - if (strlen($new_value)) { 96 - $uri = new PhutilURI($new_value); 97 - $domain = $uri->getDomain(); 98 - $object->setDomain($domain); 99 - } else { 100 - $object->setDomain(null); 101 - } 102 - $object->setDomainFullURI($new_value); 103 - return; 104 - case PhameBlogTransaction::TYPE_PROFILEIMAGE: 105 - return $object->setProfileImagePHID($xaction->getNewValue()); 106 - case PhameBlogTransaction::TYPE_HEADERIMAGE: 107 - return $object->setHeaderImagePHID($xaction->getNewValue()); 108 - case PhameBlogTransaction::TYPE_STATUS: 109 - return $object->setStatus($xaction->getNewValue()); 110 - case PhameBlogTransaction::TYPE_PARENTSITE: 111 - return $object->setParentSite($xaction->getNewValue()); 112 - case PhameBlogTransaction::TYPE_PARENTDOMAIN: 113 - return $object->setParentDomain($xaction->getNewValue()); 114 - } 115 - 116 - return parent::applyCustomInternalTransaction($object, $xaction); 117 - } 118 - 119 - protected function applyCustomExternalTransaction( 120 - PhabricatorLiskDAO $object, 121 - PhabricatorApplicationTransaction $xaction) { 122 - 123 - switch ($xaction->getTransactionType()) { 124 - case PhameBlogTransaction::TYPE_NAME: 125 - case PhameBlogTransaction::TYPE_SUBTITLE: 126 - case PhameBlogTransaction::TYPE_DESCRIPTION: 127 - case PhameBlogTransaction::TYPE_FULLDOMAIN: 128 - case PhameBlogTransaction::TYPE_PARENTSITE: 129 - case PhameBlogTransaction::TYPE_PARENTDOMAIN: 130 - case PhameBlogTransaction::TYPE_HEADERIMAGE: 131 - case PhameBlogTransaction::TYPE_PROFILEIMAGE: 132 - case PhameBlogTransaction::TYPE_STATUS: 133 - return; 134 - } 135 - 136 - return parent::applyCustomExternalTransaction($object, $xaction); 137 - } 138 - 139 - protected function validateTransaction( 140 - PhabricatorLiskDAO $object, 141 - $type, 142 - array $xactions) { 143 - 144 - $errors = parent::validateTransaction($object, $type, $xactions); 145 - 146 - 147 - switch ($type) { 148 - case PhameBlogTransaction::TYPE_NAME: 149 - $missing = $this->validateIsEmptyTextField( 150 - $object->getName(), 151 - $xactions); 152 - 153 - if ($missing) { 154 - $error = new PhabricatorApplicationTransactionValidationError( 155 - $type, 156 - pht('Required'), 157 - pht('Name is required.'), 158 - nonempty(last($xactions), null)); 159 - 160 - $error->setIsMissingFieldError(true); 161 - $errors[] = $error; 162 - } 163 - 164 - foreach ($xactions as $xaction) { 165 - $new = $xaction->getNewValue(); 166 - if (phutil_utf8_strlen($new) > 64) { 167 - $errors[] = new PhabricatorApplicationTransactionValidationError( 168 - $type, 169 - pht('Invalid'), 170 - pht( 171 - 'The selected blog title is too long. The maximum length '. 172 - 'of a blog title is 64 characters.'), 173 - $xaction); 174 - } 175 - } 176 - break; 177 - case PhameBlogTransaction::TYPE_SUBTITLE: 178 - foreach ($xactions as $xaction) { 179 - $new = $xaction->getNewValue(); 180 - if (phutil_utf8_strlen($new) > 64) { 181 - $errors[] = new PhabricatorApplicationTransactionValidationError( 182 - $type, 183 - pht('Invalid'), 184 - pht( 185 - 'The selected blog subtitle is too long. The maximum length '. 186 - 'of a blog subtitle is 64 characters.'), 187 - $xaction); 188 - } 189 - } 190 - break; 191 - case PhameBlogTransaction::TYPE_PARENTDOMAIN: 192 - if (!$xactions) { 193 - continue; 194 - } 195 - $parent_domain = last($xactions)->getNewValue(); 196 - if (empty($parent_domain)) { 197 - continue; 198 - } 199 - try { 200 - PhabricatorEnv::requireValidRemoteURIForLink($parent_domain); 201 - } catch (Exception $ex) { 202 - $error = new PhabricatorApplicationTransactionValidationError( 203 - $type, 204 - pht('Invalid URI'), 205 - pht('Parent Domain must be set to a valid Remote URI.'), 206 - nonempty(last($xactions), null)); 207 - $errors[] = $error; 208 - } 209 - break; 210 - case PhameBlogTransaction::TYPE_FULLDOMAIN: 211 - if (!$xactions) { 212 - continue; 213 - } 214 - $custom_domain = last($xactions)->getNewValue(); 215 - if (empty($custom_domain)) { 216 - continue; 217 - } 218 - list($error_label, $error_text) = 219 - $object->validateCustomDomain($custom_domain); 220 - if ($error_label) { 221 - $error = new PhabricatorApplicationTransactionValidationError( 222 - $type, 223 - $error_label, 224 - $error_text, 225 - nonempty(last($xactions), null)); 226 - $errors[] = $error; 227 - } 228 - if ($object->getViewPolicy() != PhabricatorPolicies::POLICY_PUBLIC) { 229 - $error_text = pht( 230 - 'For custom domains to work, the blog must have a view policy of '. 231 - 'public.'); 232 - $error = new PhabricatorApplicationTransactionValidationError( 233 - PhabricatorTransactions::TYPE_VIEW_POLICY, 234 - pht('Invalid Policy'), 235 - $error_text, 236 - nonempty(last($xactions), null)); 237 - $errors[] = $error; 238 - } 239 - $domain = new PhutilURI($custom_domain); 240 - $domain = $domain->getDomain(); 241 - $duplicate_blog = id(new PhameBlogQuery()) 242 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 243 - ->withDomain($domain) 244 - ->executeOne(); 245 - if ($duplicate_blog && $duplicate_blog->getID() != $object->getID()) { 246 - $error = new PhabricatorApplicationTransactionValidationError( 247 - $type, 248 - pht('Not Unique'), 249 - pht('Domain must be unique; another blog already has this domain.'), 250 - nonempty(last($xactions), null)); 251 - $errors[] = $error; 252 - } 253 - 254 - break; 255 - } 256 - return $errors; 257 28 } 258 29 259 30 protected function shouldSendMail(
+16 -28
src/applications/phame/storage/PhameBlog.php
··· 127 127 $supported_protocols = array('http', 'https'); 128 128 129 129 if (!in_array($protocol, $supported_protocols)) { 130 - return array( 131 - $label, 132 - pht( 130 + return pht( 133 131 'The custom domain should include a valid protocol in the URI '. 134 132 '(for example, "%s"). Valid protocols are "http" or "https".', 135 - $example_domain), 136 - ); 133 + $example_domain); 137 134 } 138 135 139 136 if (strlen($path) && $path != '/') { 140 - return array( 141 - $label, 142 - pht( 137 + return pht( 143 138 'The custom domain should not specify a path (hosting a Phame '. 144 139 'blog at a path is currently not supported). Instead, just provide '. 145 140 'the bare domain name (for example, "%s").', 146 - $example_domain), 147 - ); 141 + $example_domain); 148 142 } 149 143 150 144 if (strpos($domain, '.') === false) { 151 - return array( 152 - $label, 153 - pht( 145 + return pht( 154 146 'The custom domain should contain at least one dot (.) because '. 155 147 'some browsers fail to set cookies on domains without a dot. '. 156 148 'Instead, use a normal looking domain name like "%s".', 157 - $example_domain), 158 - ); 149 + $example_domain); 159 150 } 160 151 161 152 if (!PhabricatorEnv::getEnvConfig('policy.allow-public')) { 162 153 $href = PhabricatorEnv::getProductionURI( 163 154 '/config/edit/policy.allow-public/'); 164 - return array( 165 - pht('Fix Configuration'), 166 - pht( 167 - 'For custom domains to work, this Phabricator instance must be '. 168 - 'configured to allow the public access policy. Configure this '. 169 - 'setting %s, or ask an administrator to configure this setting. '. 170 - 'The domain can be specified later once this setting has been '. 171 - 'changed.', 172 - phutil_tag( 173 - 'a', 174 - array('href' => $href), 175 - pht('here'))), 176 - ); 155 + return pht( 156 + 'For custom domains to work, this Phabricator instance must be '. 157 + 'configured to allow the public access policy. Configure this '. 158 + 'setting %s, or ask an administrator to configure this setting. '. 159 + 'The domain can be specified later once this setting has been '. 160 + 'changed.', 161 + phutil_tag( 162 + 'a', 163 + array('href' => $href), 164 + pht('here'))); 177 165 } 178 166 179 167 return null;
+3 -324
src/applications/phame/storage/PhameBlogTransaction.php
··· 1 1 <?php 2 2 3 3 final class PhameBlogTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_NAME = 'phame.blog.name'; 7 - const TYPE_SUBTITLE = 'phame.blog.subtitle'; 8 - const TYPE_DESCRIPTION = 'phame.blog.description'; 9 - const TYPE_FULLDOMAIN = 'phame.blog.full.domain'; 10 - const TYPE_STATUS = 'phame.blog.status'; 11 - const TYPE_PARENTSITE = 'phame.blog.parent.site'; 12 - const TYPE_PARENTDOMAIN = 'phame.blog.parent.domain'; 13 - const TYPE_PROFILEIMAGE = 'phame.blog.header.image'; 14 - const TYPE_HEADERIMAGE = 'phame.blog.profile.image'; 4 + extends PhabricatorModularTransaction { 15 5 16 6 const MAILTAG_DETAILS = 'phame-blog-details'; 17 7 const MAILTAG_SUBSCRIBERS = 'phame-blog-subscribers'; ··· 25 15 return PhabricatorPhameBlogPHIDType::TYPECONST; 26 16 } 27 17 28 - public function shouldHide() { 29 - $old = $this->getOldValue(); 30 - switch ($this->getTransactionType()) { 31 - case self::TYPE_DESCRIPTION: 32 - if ($old === null) { 33 - return true; 34 - } 35 - } 36 - return parent::shouldHide(); 37 - } 38 - 39 - public function getRequiredHandlePHIDs() { 40 - $old = $this->getOldValue(); 41 - $new = $this->getNewValue(); 42 - 43 - $req_phids = array(); 44 - switch ($this->getTransactionType()) { 45 - case self::TYPE_PROFILEIMAGE: 46 - case self::TYPE_HEADERIMAGE: 47 - $req_phids[] = $old; 48 - $req_phids[] = $new; 49 - break; 50 - } 51 - 52 - return array_merge($req_phids, parent::getRequiredHandlePHIDs()); 53 - } 54 - 55 - public function getIcon() { 56 - $old = $this->getOldValue(); 57 - $new = $this->getNewValue(); 58 - switch ($this->getTransactionType()) { 59 - case self::TYPE_NAME: 60 - if ($old === null) { 61 - return 'fa-plus'; 62 - } else { 63 - return 'fa-pencil'; 64 - } 65 - break; 66 - case self::TYPE_DESCRIPTION: 67 - case self::TYPE_FULLDOMAIN: 68 - return 'fa-pencil'; 69 - case self::TYPE_HEADERIMAGE: 70 - return 'fa-image'; 71 - case self::TYPE_PROFILEIMAGE: 72 - return 'fa-star'; 73 - case self::TYPE_STATUS: 74 - if ($new == PhameBlog::STATUS_ARCHIVED) { 75 - return 'fa-ban'; 76 - } else { 77 - return 'fa-check'; 78 - } 79 - break; 80 - } 81 - return parent::getIcon(); 82 - } 83 - 84 - public function getColor() { 85 - 86 - $old = $this->getOldValue(); 87 - $new = $this->getNewValue(); 88 - 89 - switch ($this->getTransactionType()) { 90 - case self::TYPE_STATUS: 91 - if ($new == PhameBlog::STATUS_ARCHIVED) { 92 - return 'violet'; 93 - } else { 94 - return 'green'; 95 - } 96 - } 97 - return parent::getColor(); 18 + public function getBaseTransactionClass() { 19 + return 'PhameBlogTransactionType'; 98 20 } 99 21 100 22 public function getMailTags() { ··· 119 41 break; 120 42 } 121 43 return $tags; 122 - } 123 - 124 - public function getTitle() { 125 - $author_phid = $this->getAuthorPHID(); 126 - $object_phid = $this->getObjectPHID(); 127 - 128 - $old = $this->getOldValue(); 129 - $new = $this->getNewValue(); 130 - 131 - $type = $this->getTransactionType(); 132 - switch ($type) { 133 - case PhabricatorTransactions::TYPE_CREATE: 134 - return pht( 135 - '%s created this blog.', 136 - $this->renderHandleLink($author_phid)); 137 - case self::TYPE_NAME: 138 - if ($old === null) { 139 - return pht( 140 - '%s created this blog.', 141 - $this->renderHandleLink($author_phid)); 142 - } else { 143 - return pht( 144 - '%s updated the blog\'s name to "%s".', 145 - $this->renderHandleLink($author_phid), 146 - $new); 147 - } 148 - break; 149 - case self::TYPE_SUBTITLE: 150 - if ($old === null) { 151 - return pht( 152 - '%s set this blog\'s subtitle to "%s".', 153 - $this->renderHandleLink($author_phid), 154 - $new); 155 - } else { 156 - return pht( 157 - '%s updated the blog\'s subtitle to "%s".', 158 - $this->renderHandleLink($author_phid), 159 - $new); 160 - } 161 - break; 162 - case self::TYPE_DESCRIPTION: 163 - return pht( 164 - '%s updated the blog\'s description.', 165 - $this->renderHandleLink($author_phid)); 166 - break; 167 - case self::TYPE_FULLDOMAIN: 168 - return pht( 169 - '%s updated the blog\'s full domain to "%s".', 170 - $this->renderHandleLink($author_phid), 171 - $new); 172 - break; 173 - case self::TYPE_PARENTSITE: 174 - if ($old === null) { 175 - return pht( 176 - '%s set this blog\'s parent site to "%s".', 177 - $this->renderHandleLink($author_phid), 178 - $new); 179 - } else { 180 - return pht( 181 - '%s updated the blog\'s parent site to "%s".', 182 - $this->renderHandleLink($author_phid), 183 - $new); 184 - } 185 - break; 186 - case self::TYPE_PARENTDOMAIN: 187 - if ($old === null) { 188 - return pht( 189 - '%s set this blog\'s parent domain to "%s".', 190 - $this->renderHandleLink($author_phid), 191 - $new); 192 - } else { 193 - return pht( 194 - '%s updated the blog\'s parent domain to "%s".', 195 - $this->renderHandleLink($author_phid), 196 - $new); 197 - } 198 - break; 199 - case self::TYPE_HEADERIMAGE: 200 - if (!$old) { 201 - return pht( 202 - "%s set this blog's header image to %s.", 203 - $this->renderHandleLink($author_phid), 204 - $this->renderHandleLink($new)); 205 - } else if (!$new) { 206 - return pht( 207 - "%s removed this blog's header image.", 208 - $this->renderHandleLink($author_phid)); 209 - } else { 210 - return pht( 211 - "%s updated this blog's header image from %s to %s.", 212 - $this->renderHandleLink($author_phid), 213 - $this->renderHandleLink($old), 214 - $this->renderHandleLink($new)); 215 - } 216 - break; 217 - case self::TYPE_PROFILEIMAGE: 218 - if (!$old) { 219 - return pht( 220 - "%s set this blog's profile image to %s.", 221 - $this->renderHandleLink($author_phid), 222 - $this->renderHandleLink($new)); 223 - } else if (!$new) { 224 - return pht( 225 - "%s removed this blog's profile image.", 226 - $this->renderHandleLink($author_phid)); 227 - } else { 228 - return pht( 229 - "%s updated this blog's profile image from %s to %s.", 230 - $this->renderHandleLink($author_phid), 231 - $this->renderHandleLink($old), 232 - $this->renderHandleLink($new)); 233 - } 234 - break; 235 - case self::TYPE_STATUS: 236 - switch ($new) { 237 - case PhameBlog::STATUS_ACTIVE: 238 - return pht( 239 - '%s published this blog.', 240 - $this->renderHandleLink($author_phid)); 241 - case PhameBlog::STATUS_ARCHIVED: 242 - return pht( 243 - '%s archived this blog.', 244 - $this->renderHandleLink($author_phid)); 245 - } 246 - 247 - } 248 - 249 - return parent::getTitle(); 250 - } 251 - 252 - public function getTitleForFeed() { 253 - $author_phid = $this->getAuthorPHID(); 254 - $object_phid = $this->getObjectPHID(); 255 - 256 - $old = $this->getOldValue(); 257 - $new = $this->getNewValue(); 258 - 259 - $type = $this->getTransactionType(); 260 - switch ($type) { 261 - case self::TYPE_NAME: 262 - if ($old === null) { 263 - return pht( 264 - '%s created %s.', 265 - $this->renderHandleLink($author_phid), 266 - $this->renderHandleLink($object_phid)); 267 - } else { 268 - return pht( 269 - '%s updated the name for %s.', 270 - $this->renderHandleLink($author_phid), 271 - $this->renderHandleLink($object_phid)); 272 - } 273 - break; 274 - case self::TYPE_SUBTITLE: 275 - if ($old === null) { 276 - return pht( 277 - '%s set the subtitle for %s.', 278 - $this->renderHandleLink($author_phid), 279 - $this->renderHandleLink($object_phid)); 280 - } else { 281 - return pht( 282 - '%s updated the subtitle for %s.', 283 - $this->renderHandleLink($author_phid), 284 - $this->renderHandleLink($object_phid)); 285 - } 286 - break; 287 - case self::TYPE_DESCRIPTION: 288 - return pht( 289 - '%s updated the description for %s.', 290 - $this->renderHandleLink($author_phid), 291 - $this->renderHandleLink($object_phid)); 292 - break; 293 - case self::TYPE_FULLDOMAIN: 294 - return pht( 295 - '%s updated the full domain for %s.', 296 - $this->renderHandleLink($author_phid), 297 - $this->renderHandleLink($object_phid)); 298 - break; 299 - case self::TYPE_PARENTSITE: 300 - return pht( 301 - '%s updated the parent site for %s.', 302 - $this->renderHandleLink($author_phid), 303 - $this->renderHandleLink($object_phid)); 304 - break; 305 - case self::TYPE_PARENTDOMAIN: 306 - return pht( 307 - '%s updated the parent domain for %s.', 308 - $this->renderHandleLink($author_phid), 309 - $this->renderHandleLink($object_phid)); 310 - break; 311 - case self::TYPE_HEADERIMAGE: 312 - return pht( 313 - '%s updated the header image for %s.', 314 - $this->renderHandleLink($author_phid), 315 - $this->renderHandleLink($object_phid)); 316 - break; 317 - case self::TYPE_PROFILEIMAGE: 318 - return pht( 319 - '%s updated the profile image for %s.', 320 - $this->renderHandleLink($author_phid), 321 - $this->renderHandleLink($object_phid)); 322 - break; 323 - case self::TYPE_STATUS: 324 - switch ($new) { 325 - case PhameBlog::STATUS_ACTIVE: 326 - return pht( 327 - '%s published the blog %s.', 328 - $this->renderHandleLink($author_phid), 329 - $this->renderHandleLink($object_phid)); 330 - case PhameBlog::STATUS_ARCHIVED: 331 - return pht( 332 - '%s archived the blog %s.', 333 - $this->renderHandleLink($author_phid), 334 - $this->renderHandleLink($object_phid)); 335 - } 336 - break; 337 - 338 - } 339 - 340 - return parent::getTitleForFeed(); 341 - } 342 - 343 - public function hasChangeDetails() { 344 - switch ($this->getTransactionType()) { 345 - case self::TYPE_DESCRIPTION: 346 - return ($this->getOldValue() !== null); 347 - } 348 - 349 - return parent::hasChangeDetails(); 350 - } 351 - 352 - public function renderChangeDetails(PhabricatorUser $viewer) { 353 - switch ($this->getTransactionType()) { 354 - case self::TYPE_DESCRIPTION: 355 - $old = $this->getOldValue(); 356 - $new = $this->getNewValue(); 357 - 358 - return $this->renderTextCorpusChangeDetails( 359 - $viewer, 360 - $old, 361 - $new); 362 - } 363 - 364 - return parent::renderChangeDetails($viewer); 365 44 } 366 45 367 46 }
+60
src/applications/phame/xaction/PhameBlogDescriptionTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogDescriptionTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.blog.description'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getDescription(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setDescription($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the description.', 19 + $this->renderAuthor()); 20 + } 21 + 22 + public function getTitleForFeed() { 23 + return pht( 24 + '%s updated the description 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 BLOG DESCRIPTION'); 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 + }
+95
src/applications/phame/xaction/PhameBlogFullDomainTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogFullDomainTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.blog.full.domain'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getDomainFullURI(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + if (strlen($value)) { 14 + $uri = new PhutilURI($value); 15 + $domain = $uri->getDomain(); 16 + $object->setDomain($domain); 17 + } else { 18 + $object->setDomain(null); 19 + } 20 + $object->setDomainFullURI($value); 21 + } 22 + 23 + public function getTitle() { 24 + $old = $this->getOldValue(); 25 + if (!strlen($old)) { 26 + return pht( 27 + '%s set this blog\'s full domain to %s.', 28 + $this->renderAuthor(), 29 + $this->renderNewValue()); 30 + } else { 31 + return pht( 32 + '%s updated the blog\'s full domain from %s to %s.', 33 + $this->renderAuthor(), 34 + $this->renderOldValue(), 35 + $this->renderNewValue()); 36 + } 37 + } 38 + 39 + public function getTitleForFeed() { 40 + $old = $this->getOldValue(); 41 + if (!strlen($old)) { 42 + return pht( 43 + '%s set %s blog\'s full domain to %s.', 44 + $this->renderAuthor(), 45 + $this->renderObject(), 46 + $this->renderNewValue()); 47 + } else { 48 + return pht( 49 + '%s updated %s blog\'s full domain from %s to %s.', 50 + $this->renderAuthor(), 51 + $this->renderObject(), 52 + $this->renderOldValue(), 53 + $this->renderNewValue()); 54 + } 55 + } 56 + 57 + public function validateTransactions($object, array $xactions) { 58 + $errors = array(); 59 + 60 + if (!$xactions) { 61 + return $errors; 62 + } 63 + 64 + $custom_domain = last($xactions)->getNewValue(); 65 + if (empty($custom_domain)) { 66 + return $errors; 67 + } 68 + 69 + $error_text = $object->validateCustomDomain($custom_domain); 70 + if ($error_text) { 71 + $errors[] = $this->newInvalidError($error_text); 72 + } 73 + 74 + if ($object->getViewPolicy() != PhabricatorPolicies::POLICY_PUBLIC) { 75 + $errors[] = $this->newInvalidError( 76 + pht('For custom domains to work, the blog must have a view policy of '. 77 + 'public. This blog is currently set to "%s".', 78 + $object->getViewPolicy())); 79 + } 80 + 81 + $domain = new PhutilURI($custom_domain); 82 + $domain = $domain->getDomain(); 83 + $duplicate_blog = id(new PhameBlogQuery()) 84 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 85 + ->withDomain($domain) 86 + ->executeOne(); 87 + if ($duplicate_blog && $duplicate_blog->getID() != $object->getID()) { 88 + $errors[] = $this->newInvalidError( 89 + pht('Domain must be unique; another blog already has this domain.')); 90 + } 91 + 92 + return $errors; 93 + } 94 + 95 + }
+34
src/applications/phame/xaction/PhameBlogHeaderImageTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogHeaderImageTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + // TODO: Migrate these transactions ha ha .... ha 7 + const TRANSACTIONTYPE = 'phame.blog.profile.image'; 8 + 9 + public function generateOldValue($object) { 10 + return $object->getHeaderImagePHID(); 11 + } 12 + 13 + public function applyInternalEffects($object, $value) { 14 + $object->setHeaderImagePHID($value); 15 + } 16 + 17 + public function getTitle() { 18 + return pht( 19 + '%s changed the header image for this blog.', 20 + $this->renderAuthor()); 21 + } 22 + 23 + public function getTitleForFeed() { 24 + return pht( 25 + '%s changed the header image for blog %s.', 26 + $this->renderAuthor(), 27 + $this->renderObject()); 28 + } 29 + 30 + public function getIcon() { 31 + return 'fa-camera'; 32 + } 33 + 34 + }
+59
src/applications/phame/xaction/PhameBlogNameTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogNameTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.blog.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 blog 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 froms %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('Blogs 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 + public function getIcon() { 56 + return 'fa-rss'; 57 + } 58 + 59 + }
+82
src/applications/phame/xaction/PhameBlogParentDomainTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogParentDomainTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.blog.parent.domain'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getParentDomain(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setParentDomain($value); 14 + } 15 + 16 + public function getTitle() { 17 + $old = $this->getOldValue(); 18 + if (!strlen($old)) { 19 + return pht( 20 + '%s set this blog\'s parent domain to %s.', 21 + $this->renderAuthor(), 22 + $this->renderNewValue()); 23 + } else { 24 + return pht( 25 + '%s updated the blog\'s parent domain from %s to %s.', 26 + $this->renderAuthor(), 27 + $this->renderOldValue(), 28 + $this->renderNewValue()); 29 + } 30 + } 31 + 32 + public function getTitleForFeed() { 33 + $old = $this->getOldValue(); 34 + if (!strlen($old)) { 35 + return pht( 36 + '%s set %s blog\'s parent domain to %s.', 37 + $this->renderAuthor(), 38 + $this->renderObject(), 39 + $this->renderNewValue()); 40 + } else { 41 + return pht( 42 + '%s updated %s blog\'s parent domain from %s to %s.', 43 + $this->renderAuthor(), 44 + $this->renderObject(), 45 + $this->renderOldValue(), 46 + $this->renderNewValue()); 47 + } 48 + } 49 + 50 + public function validateTransactions($object, array $xactions) { 51 + $errors = array(); 52 + 53 + if (!$xactions) { 54 + return $errors; 55 + } 56 + 57 + $parent_domain = last($xactions)->getNewValue(); 58 + if (empty($parent_domain)) { 59 + return $errors; 60 + } 61 + 62 + try { 63 + PhabricatorEnv::requireValidRemoteURIForLink($parent_domain); 64 + } catch (Exception $ex) { 65 + $errors[] = $this->newInvalidError( 66 + pht('Parent Domain must be set to a valid Remote URI.')); 67 + } 68 + 69 + $max_length = $object->getColumnMaximumByteLength('parentDomain'); 70 + foreach ($xactions as $xaction) { 71 + $new_value = $xaction->getNewValue(); 72 + $new_length = strlen($new_value); 73 + if ($new_length > $max_length) { 74 + $errors[] = $this->newInvalidError( 75 + pht('The parent domain can be no longer than %s characters.', 76 + new PhutilNumber($max_length))); 77 + } 78 + } 79 + 80 + return $errors; 81 + } 82 + }
+66
src/applications/phame/xaction/PhameBlogParentSiteTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogParentSiteTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.blog.parent.site'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getParentSite(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setParentSite($value); 14 + } 15 + 16 + public function getTitle() { 17 + $old = $this->getOldValue(); 18 + if (!strlen($old)) { 19 + return pht( 20 + '%s set this blog\'s parent site to %s.', 21 + $this->renderAuthor(), 22 + $this->renderNewValue()); 23 + } else { 24 + return pht( 25 + '%s updated the blog\'s parent site from %s to %s.', 26 + $this->renderAuthor(), 27 + $this->renderOldValue(), 28 + $this->renderNewValue()); 29 + } 30 + } 31 + 32 + public function getTitleForFeed() { 33 + $old = $this->getOldValue(); 34 + if (!strlen($old)) { 35 + return pht( 36 + '%s set %s blog\'s parent site to %s.', 37 + $this->renderAuthor(), 38 + $this->renderObject(), 39 + $this->renderNewValue()); 40 + } else { 41 + return pht( 42 + '%s updated %s blog\'s parent site from %s to %s.', 43 + $this->renderAuthor(), 44 + $this->renderObject(), 45 + $this->renderOldValue(), 46 + $this->renderNewValue()); 47 + } 48 + } 49 + 50 + public function validateTransactions($object, array $xactions) { 51 + $errors = array(); 52 + 53 + $max_length = $object->getColumnMaximumByteLength('parentSite'); 54 + foreach ($xactions as $xaction) { 55 + $new_value = $xaction->getNewValue(); 56 + $new_length = strlen($new_value); 57 + if ($new_length > $max_length) { 58 + $errors[] = $this->newInvalidError( 59 + pht('The parent site can be no longer than %s characters.', 60 + new PhutilNumber($max_length))); 61 + } 62 + } 63 + 64 + return $errors; 65 + } 66 + }
+34
src/applications/phame/xaction/PhameBlogProfileImageTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogProfileImageTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + // TODO: Migrate these transactions ha ha .... ha 7 + const TRANSACTIONTYPE = 'phame.blog.header.image'; 8 + 9 + public function generateOldValue($object) { 10 + return $object->getProfileImagePHID(); 11 + } 12 + 13 + public function applyInternalEffects($object, $value) { 14 + $object->setProfileImagePHID($value); 15 + } 16 + 17 + public function getTitle() { 18 + return pht( 19 + '%s changed the profile image for this blog.', 20 + $this->renderAuthor()); 21 + } 22 + 23 + public function getTitleForFeed() { 24 + return pht( 25 + '%s changed the profile image for blog %s.', 26 + $this->renderAuthor(), 27 + $this->renderObject()); 28 + } 29 + 30 + public function getIcon() { 31 + return 'fa-file-image-o'; 32 + } 33 + 34 + }
+55
src/applications/phame/xaction/PhameBlogStatusTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogStatusTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.blog.status'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getStatus(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setStatus($value); 14 + } 15 + 16 + public function getTitle() { 17 + $new = $this->getNewValue(); 18 + switch ($new) { 19 + case PhameBlog::STATUS_ACTIVE: 20 + return pht( 21 + '%s published this blog.', 22 + $this->renderAuthor()); 23 + case PhameBlog::STATUS_ARCHIVED: 24 + return pht( 25 + '%s archived this blog.', 26 + $this->renderAuthor()); 27 + } 28 + } 29 + 30 + public function getTitleForFeed() { 31 + $new = $this->getNewValue(); 32 + switch ($new) { 33 + case PhameBlog::STATUS_ACTIVE: 34 + return pht( 35 + '%s published the blog %s.', 36 + $this->renderAuthor(), 37 + $this->renderObject()); 38 + case PhameBlog::STATUS_ARCHIVED: 39 + return pht( 40 + '%s archived the blog %s.', 41 + $this->renderAuthor(), 42 + $this->renderObject()); 43 + } 44 + } 45 + 46 + public function getIcon() { 47 + $new = $this->getNewValue(); 48 + if ($new == PhameBlog::STATUS_ARCHIVED) { 49 + return 'fa-ban'; 50 + } else { 51 + return 'fa-check'; 52 + } 53 + } 54 + 55 + }
+63
src/applications/phame/xaction/PhameBlogSubtitleTransaction.php
··· 1 + <?php 2 + 3 + final class PhameBlogSubtitleTransaction 4 + extends PhameBlogTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'phame.blog.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 blog\'s subtitle to "%s".', 21 + $this->renderAuthor(), 22 + $this->renderNewValue()); 23 + } else { 24 + return pht( 25 + '%s updated the blog\'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 + }
+4
src/applications/phame/xaction/PhameBlogTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PhameBlogTransactionType 4 + extends PhabricatorModularTransactionType {}