mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-22 20:51:10 +01:00
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
This commit is contained in:
parent
c878bf5033
commit
4aec809b69
17 changed files with 392 additions and 445 deletions
|
@ -4272,12 +4272,15 @@ phutil_register_library_map(array(
|
||||||
'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php',
|
'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php',
|
||||||
'PhamePost' => 'applications/phame/storage/PhamePost.php',
|
'PhamePost' => 'applications/phame/storage/PhamePost.php',
|
||||||
'PhamePostArchiveController' => 'applications/phame/controller/post/PhamePostArchiveController.php',
|
'PhamePostArchiveController' => 'applications/phame/controller/post/PhamePostArchiveController.php',
|
||||||
|
'PhamePostBlogTransaction' => 'applications/phame/xaction/PhamePostBlogTransaction.php',
|
||||||
|
'PhamePostBodyTransaction' => 'applications/phame/xaction/PhamePostBodyTransaction.php',
|
||||||
'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php',
|
'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php',
|
||||||
'PhamePostEditConduitAPIMethod' => 'applications/phame/conduit/PhamePostEditConduitAPIMethod.php',
|
'PhamePostEditConduitAPIMethod' => 'applications/phame/conduit/PhamePostEditConduitAPIMethod.php',
|
||||||
'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php',
|
'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php',
|
||||||
'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php',
|
'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php',
|
||||||
'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php',
|
'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php',
|
||||||
'PhamePostFulltextEngine' => 'applications/phame/search/PhamePostFulltextEngine.php',
|
'PhamePostFulltextEngine' => 'applications/phame/search/PhamePostFulltextEngine.php',
|
||||||
|
'PhamePostHeaderImageTransaction' => 'applications/phame/xaction/PhamePostHeaderImageTransaction.php',
|
||||||
'PhamePostHeaderPictureController' => 'applications/phame/controller/post/PhamePostHeaderPictureController.php',
|
'PhamePostHeaderPictureController' => 'applications/phame/controller/post/PhamePostHeaderPictureController.php',
|
||||||
'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php',
|
'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php',
|
||||||
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
|
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
|
||||||
|
@ -4290,10 +4293,14 @@ phutil_register_library_map(array(
|
||||||
'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php',
|
'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php',
|
||||||
'PhamePostSearchConduitAPIMethod' => 'applications/phame/conduit/PhamePostSearchConduitAPIMethod.php',
|
'PhamePostSearchConduitAPIMethod' => 'applications/phame/conduit/PhamePostSearchConduitAPIMethod.php',
|
||||||
'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php',
|
'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php',
|
||||||
|
'PhamePostSubtitleTransaction' => 'applications/phame/xaction/PhamePostSubtitleTransaction.php',
|
||||||
|
'PhamePostTitleTransaction' => 'applications/phame/xaction/PhamePostTitleTransaction.php',
|
||||||
'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php',
|
'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php',
|
||||||
'PhamePostTransactionComment' => 'applications/phame/storage/PhamePostTransactionComment.php',
|
'PhamePostTransactionComment' => 'applications/phame/storage/PhamePostTransactionComment.php',
|
||||||
'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php',
|
'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php',
|
||||||
|
'PhamePostTransactionType' => 'applications/phame/xaction/PhamePostTransactionType.php',
|
||||||
'PhamePostViewController' => 'applications/phame/controller/post/PhamePostViewController.php',
|
'PhamePostViewController' => 'applications/phame/controller/post/PhamePostViewController.php',
|
||||||
|
'PhamePostVisibilityTransaction' => 'applications/phame/xaction/PhamePostVisibilityTransaction.php',
|
||||||
'PhameSchemaSpec' => 'applications/phame/storage/PhameSchemaSpec.php',
|
'PhameSchemaSpec' => 'applications/phame/storage/PhameSchemaSpec.php',
|
||||||
'PhameSite' => 'applications/phame/site/PhameSite.php',
|
'PhameSite' => 'applications/phame/site/PhameSite.php',
|
||||||
'PhluxController' => 'applications/phlux/controller/PhluxController.php',
|
'PhluxController' => 'applications/phlux/controller/PhluxController.php',
|
||||||
|
@ -9753,12 +9760,15 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorFulltextInterface',
|
'PhabricatorFulltextInterface',
|
||||||
),
|
),
|
||||||
'PhamePostArchiveController' => 'PhamePostController',
|
'PhamePostArchiveController' => 'PhamePostController',
|
||||||
|
'PhamePostBlogTransaction' => 'PhamePostTransactionType',
|
||||||
|
'PhamePostBodyTransaction' => 'PhamePostTransactionType',
|
||||||
'PhamePostController' => 'PhameController',
|
'PhamePostController' => 'PhameController',
|
||||||
'PhamePostEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
'PhamePostEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
||||||
'PhamePostEditController' => 'PhamePostController',
|
'PhamePostEditController' => 'PhamePostController',
|
||||||
'PhamePostEditEngine' => 'PhabricatorEditEngine',
|
'PhamePostEditEngine' => 'PhabricatorEditEngine',
|
||||||
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PhamePostFulltextEngine' => 'PhabricatorFulltextEngine',
|
'PhamePostFulltextEngine' => 'PhabricatorFulltextEngine',
|
||||||
|
'PhamePostHeaderImageTransaction' => 'PhamePostTransactionType',
|
||||||
'PhamePostHeaderPictureController' => 'PhamePostController',
|
'PhamePostHeaderPictureController' => 'PhamePostController',
|
||||||
'PhamePostHistoryController' => 'PhamePostController',
|
'PhamePostHistoryController' => 'PhamePostController',
|
||||||
'PhamePostListController' => 'PhamePostController',
|
'PhamePostListController' => 'PhamePostController',
|
||||||
|
@ -9771,10 +9781,14 @@ phutil_register_library_map(array(
|
||||||
'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||||
'PhamePostSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
'PhamePostSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||||
'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhamePostTransaction' => 'PhabricatorApplicationTransaction',
|
'PhamePostSubtitleTransaction' => 'PhamePostTransactionType',
|
||||||
|
'PhamePostTitleTransaction' => 'PhamePostTransactionType',
|
||||||
|
'PhamePostTransaction' => 'PhabricatorModularTransaction',
|
||||||
'PhamePostTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
'PhamePostTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||||
'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
|
'PhamePostTransactionType' => 'PhabricatorModularTransactionType',
|
||||||
'PhamePostViewController' => 'PhameLiveController',
|
'PhamePostViewController' => 'PhameLiveController',
|
||||||
|
'PhamePostVisibilityTransaction' => 'PhamePostTransactionType',
|
||||||
'PhameSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
'PhameSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||||
'PhameSite' => 'PhabricatorSite',
|
'PhameSite' => 'PhabricatorSite',
|
||||||
'PhluxController' => 'PhabricatorController',
|
'PhluxController' => 'PhabricatorController',
|
||||||
|
|
|
@ -26,7 +26,7 @@ final class PhamePostArchiveController extends PhamePostController {
|
||||||
|
|
||||||
$new_value = PhameConstants::VISIBILITY_ARCHIVED;
|
$new_value = PhameConstants::VISIBILITY_ARCHIVED;
|
||||||
$xactions[] = id(new PhamePostTransaction())
|
$xactions[] = id(new PhamePostTransaction())
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
|
->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE)
|
||||||
->setNewValue($new_value);
|
->setNewValue($new_value);
|
||||||
|
|
||||||
id(new PhamePostEditor())
|
id(new PhamePostEditor())
|
||||||
|
|
|
@ -61,7 +61,7 @@ final class PhamePostHeaderPictureController
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
$xactions[] = id(new PhamePostTransaction())
|
$xactions[] = id(new PhamePostTransaction())
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_HEADERIMAGE)
|
->setTransactionType(PhamePostHeaderImageTransaction::TRANSACTIONTYPE)
|
||||||
->setNewValue($new_value);
|
->setNewValue($new_value);
|
||||||
|
|
||||||
$editor = id(new PhamePostEditor())
|
$editor = id(new PhamePostEditor())
|
||||||
|
|
|
@ -28,7 +28,7 @@ final class PhamePostMoveController extends PhamePostController {
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
$xactions[] = id(new PhamePostTransaction())
|
$xactions[] = id(new PhamePostTransaction())
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_BLOG)
|
->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE)
|
||||||
->setNewValue($v_blog);
|
->setNewValue($v_blog);
|
||||||
|
|
||||||
$editor = id(new PhamePostEditor())
|
$editor = id(new PhamePostEditor())
|
||||||
|
|
|
@ -34,7 +34,7 @@ final class PhamePostPublishController extends PhamePostController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$xactions[] = id(new PhamePostTransaction())
|
$xactions[] = id(new PhamePostTransaction())
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
|
->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE)
|
||||||
->setNewValue($new_value);
|
->setNewValue($new_value);
|
||||||
|
|
||||||
id(new PhamePostEditor())
|
id(new PhamePostEditor())
|
||||||
|
|
|
@ -84,7 +84,7 @@ final class PhamePostEditEngine
|
||||||
pht('Choose a blog to create a post on (or move a post to).'))
|
pht('Choose a blog to create a post on (or move a post to).'))
|
||||||
->setConduitTypeDescription(pht('PHID of the blog.'))
|
->setConduitTypeDescription(pht('PHID of the blog.'))
|
||||||
->setAliases(array('blogPHID'))
|
->setAliases(array('blogPHID'))
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_BLOG)
|
->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE)
|
||||||
->setHandleParameterType(new AphrontPHIDListHTTPParameterType())
|
->setHandleParameterType(new AphrontPHIDListHTTPParameterType())
|
||||||
->setSingleValue($blog_phid)
|
->setSingleValue($blog_phid)
|
||||||
->setIsReorderable(false)
|
->setIsReorderable(false)
|
||||||
|
@ -97,7 +97,7 @@ final class PhamePostEditEngine
|
||||||
->setDescription(pht('Post title.'))
|
->setDescription(pht('Post title.'))
|
||||||
->setConduitDescription(pht('Retitle the post.'))
|
->setConduitDescription(pht('Retitle the post.'))
|
||||||
->setConduitTypeDescription(pht('New post title.'))
|
->setConduitTypeDescription(pht('New post title.'))
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_TITLE)
|
->setTransactionType(PhamePostTitleTransaction::TRANSACTIONTYPE)
|
||||||
->setValue($object->getTitle()),
|
->setValue($object->getTitle()),
|
||||||
id(new PhabricatorTextEditField())
|
id(new PhabricatorTextEditField())
|
||||||
->setKey('subtitle')
|
->setKey('subtitle')
|
||||||
|
@ -105,7 +105,7 @@ final class PhamePostEditEngine
|
||||||
->setDescription(pht('Post subtitle.'))
|
->setDescription(pht('Post subtitle.'))
|
||||||
->setConduitDescription(pht('Change the post subtitle.'))
|
->setConduitDescription(pht('Change the post subtitle.'))
|
||||||
->setConduitTypeDescription(pht('New post subtitle.'))
|
->setConduitTypeDescription(pht('New post subtitle.'))
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_SUBTITLE)
|
->setTransactionType(PhamePostSubtitleTransaction::TRANSACTIONTYPE)
|
||||||
->setValue($object->getSubtitle()),
|
->setValue($object->getSubtitle()),
|
||||||
id(new PhabricatorSelectEditField())
|
id(new PhabricatorSelectEditField())
|
||||||
->setKey('visibility')
|
->setKey('visibility')
|
||||||
|
@ -113,7 +113,7 @@ final class PhamePostEditEngine
|
||||||
->setDescription(pht('Post visibility.'))
|
->setDescription(pht('Post visibility.'))
|
||||||
->setConduitDescription(pht('Change post visibility.'))
|
->setConduitDescription(pht('Change post visibility.'))
|
||||||
->setConduitTypeDescription(pht('New post visibility constant.'))
|
->setConduitTypeDescription(pht('New post visibility constant.'))
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
|
->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE)
|
||||||
->setValue($object->getVisibility())
|
->setValue($object->getVisibility())
|
||||||
->setOptions(PhameConstants::getPhamePostStatusMap()),
|
->setOptions(PhameConstants::getPhamePostStatusMap()),
|
||||||
id(new PhabricatorRemarkupEditField())
|
id(new PhabricatorRemarkupEditField())
|
||||||
|
@ -122,7 +122,7 @@ final class PhamePostEditEngine
|
||||||
->setDescription(pht('Post body.'))
|
->setDescription(pht('Post body.'))
|
||||||
->setConduitDescription(pht('Change post body.'))
|
->setConduitDescription(pht('Change post body.'))
|
||||||
->setConduitTypeDescription(pht('New post body.'))
|
->setConduitTypeDescription(pht('New post body.'))
|
||||||
->setTransactionType(PhamePostTransaction::TYPE_BODY)
|
->setTransactionType(PhamePostBodyTransaction::TRANSACTIONTYPE)
|
||||||
->setValue($object->getBody())
|
->setValue($object->getBody())
|
||||||
->setPreviewPanel(
|
->setPreviewPanel(
|
||||||
id(new PHUIRemarkupPreviewPanel())
|
id(new PHUIRemarkupPreviewPanel())
|
||||||
|
|
|
@ -11,177 +11,21 @@ final class PhamePostEditor
|
||||||
return pht('Phame Posts');
|
return pht('Phame Posts');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCreateObjectTitle($author, $object) {
|
||||||
|
return pht('%s created this post.', $author);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreateObjectTitleForFeed($author, $object) {
|
||||||
|
return pht('%s created %s.', $author, $object);
|
||||||
|
}
|
||||||
|
|
||||||
public function getTransactionTypes() {
|
public function getTransactionTypes() {
|
||||||
$types = parent::getTransactionTypes();
|
$types = parent::getTransactionTypes();
|
||||||
|
|
||||||
$types[] = PhamePostTransaction::TYPE_BLOG;
|
|
||||||
$types[] = PhamePostTransaction::TYPE_TITLE;
|
|
||||||
$types[] = PhamePostTransaction::TYPE_SUBTITLE;
|
|
||||||
$types[] = PhamePostTransaction::TYPE_BODY;
|
|
||||||
$types[] = PhamePostTransaction::TYPE_VISIBILITY;
|
|
||||||
$types[] = PhamePostTransaction::TYPE_HEADERIMAGE;
|
|
||||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCustomTransactionOldValue(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case PhamePostTransaction::TYPE_BLOG:
|
|
||||||
return $object->getBlogPHID();
|
|
||||||
case PhamePostTransaction::TYPE_TITLE:
|
|
||||||
return $object->getTitle();
|
|
||||||
case PhamePostTransaction::TYPE_SUBTITLE:
|
|
||||||
return $object->getSubtitle();
|
|
||||||
case PhamePostTransaction::TYPE_BODY:
|
|
||||||
return $object->getBody();
|
|
||||||
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
||||||
return $object->getVisibility();
|
|
||||||
case PhamePostTransaction::TYPE_HEADERIMAGE:
|
|
||||||
return $object->getHeaderImagePHID();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getCustomTransactionNewValue(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case PhamePostTransaction::TYPE_TITLE:
|
|
||||||
case PhamePostTransaction::TYPE_SUBTITLE:
|
|
||||||
case PhamePostTransaction::TYPE_BODY:
|
|
||||||
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
||||||
case PhamePostTransaction::TYPE_HEADERIMAGE:
|
|
||||||
case PhamePostTransaction::TYPE_BLOG:
|
|
||||||
return $xaction->getNewValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function applyCustomInternalTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case PhamePostTransaction::TYPE_TITLE:
|
|
||||||
return $object->setTitle($xaction->getNewValue());
|
|
||||||
case PhamePostTransaction::TYPE_SUBTITLE:
|
|
||||||
return $object->setSubtitle($xaction->getNewValue());
|
|
||||||
case PhamePostTransaction::TYPE_BODY:
|
|
||||||
return $object->setBody($xaction->getNewValue());
|
|
||||||
case PhamePostTransaction::TYPE_BLOG:
|
|
||||||
return $object->setBlogPHID($xaction->getNewValue());
|
|
||||||
case PhamePostTransaction::TYPE_HEADERIMAGE:
|
|
||||||
return $object->setHeaderImagePHID($xaction->getNewValue());
|
|
||||||
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
||||||
if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) {
|
|
||||||
$object->setDatePublished(0);
|
|
||||||
} else if ($xaction->getNewValue() ==
|
|
||||||
PhameConstants::VISIBILITY_ARCHIVED) {
|
|
||||||
$object->setDatePublished(0);
|
|
||||||
} else {
|
|
||||||
$object->setDatePublished(PhabricatorTime::getNow());
|
|
||||||
}
|
|
||||||
return $object->setVisibility($xaction->getNewValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::applyCustomInternalTransaction($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function applyCustomExternalTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case PhamePostTransaction::TYPE_TITLE:
|
|
||||||
case PhamePostTransaction::TYPE_SUBTITLE:
|
|
||||||
case PhamePostTransaction::TYPE_BODY:
|
|
||||||
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
||||||
case PhamePostTransaction::TYPE_HEADERIMAGE:
|
|
||||||
case PhamePostTransaction::TYPE_BLOG:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::applyCustomExternalTransaction($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function validateTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
$type,
|
|
||||||
array $xactions) {
|
|
||||||
|
|
||||||
$errors = parent::validateTransaction($object, $type, $xactions);
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case PhamePostTransaction::TYPE_TITLE:
|
|
||||||
$missing = $this->validateIsEmptyTextField(
|
|
||||||
$object->getTitle(),
|
|
||||||
$xactions);
|
|
||||||
|
|
||||||
if ($missing) {
|
|
||||||
$error = new PhabricatorApplicationTransactionValidationError(
|
|
||||||
$type,
|
|
||||||
pht('Required'),
|
|
||||||
pht('Title is required.'),
|
|
||||||
nonempty(last($xactions), null));
|
|
||||||
|
|
||||||
$error->setIsMissingFieldError(true);
|
|
||||||
$errors[] = $error;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PhamePostTransaction::TYPE_BLOG:
|
|
||||||
if ($this->getIsNewObject()) {
|
|
||||||
if (!$xactions) {
|
|
||||||
$error = new PhabricatorApplicationTransactionValidationError(
|
|
||||||
$type,
|
|
||||||
pht('Required'),
|
|
||||||
pht(
|
|
||||||
'When creating a post, you must specify which blog it '.
|
|
||||||
'should belong to.'),
|
|
||||||
null);
|
|
||||||
|
|
||||||
$error->setIsMissingFieldError(true);
|
|
||||||
|
|
||||||
$errors[] = $error;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($xactions as $xaction) {
|
|
||||||
$new_phid = $xaction->getNewValue();
|
|
||||||
|
|
||||||
$blog = id(new PhameBlogQuery())
|
|
||||||
->setViewer($this->getActor())
|
|
||||||
->withPHIDs(array($new_phid))
|
|
||||||
->requireCapabilities(
|
|
||||||
array(
|
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
|
||||||
))
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
if ($blog) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
|
||||||
$type,
|
|
||||||
pht('Invalid'),
|
|
||||||
pht(
|
|
||||||
'The specified blog PHID ("%s") is not valid. You can only '.
|
|
||||||
'create a post on (or move a post into) a blog which you '.
|
|
||||||
'have permission to see and edit.',
|
|
||||||
$new_phid),
|
|
||||||
$xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function shouldSendMail(
|
protected function shouldSendMail(
|
||||||
PhabricatorLiskDAO $object,
|
PhabricatorLiskDAO $object,
|
||||||
array $xactions) {
|
array $xactions) {
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PhamePostTransaction
|
final class PhamePostTransaction
|
||||||
extends PhabricatorApplicationTransaction {
|
extends PhabricatorModularTransaction {
|
||||||
|
|
||||||
const TYPE_TITLE = 'phame.post.title';
|
|
||||||
const TYPE_SUBTITLE = 'phame.post.subtitle';
|
|
||||||
const TYPE_BODY = 'phame.post.body';
|
|
||||||
const TYPE_VISIBILITY = 'phame.post.visibility';
|
|
||||||
const TYPE_HEADERIMAGE = 'phame.post.headerimage';
|
|
||||||
const TYPE_BLOG = 'phame.post.blog';
|
|
||||||
|
|
||||||
const MAILTAG_CONTENT = 'phame-post-content';
|
const MAILTAG_CONTENT = 'phame-post-content';
|
||||||
const MAILTAG_SUBSCRIBERS = 'phame-post-subscribers';
|
const MAILTAG_SUBSCRIBERS = 'phame-post-subscribers';
|
||||||
|
@ -23,71 +16,14 @@ final class PhamePostTransaction
|
||||||
return PhabricatorPhamePostPHIDType::TYPECONST;
|
return PhabricatorPhamePostPHIDType::TYPECONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBaseTransactionClass() {
|
||||||
|
return 'PhamePostTransactionType';
|
||||||
|
}
|
||||||
|
|
||||||
public function getApplicationTransactionCommentObject() {
|
public function getApplicationTransactionCommentObject() {
|
||||||
return new PhamePostTransactionComment();
|
return new PhamePostTransactionComment();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRemarkupBlocks() {
|
|
||||||
$blocks = parent::getRemarkupBlocks();
|
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case self::TYPE_BODY:
|
|
||||||
$blocks[] = $this->getNewValue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function shouldHide() {
|
|
||||||
return parent::shouldHide();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRequiredHandlePHIDs() {
|
|
||||||
$phids = parent::getRequiredHandlePHIDs();
|
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case self::TYPE_BLOG:
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
|
|
||||||
if ($old) {
|
|
||||||
$phids[] = $old;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($new) {
|
|
||||||
$phids[] = $new;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $phids;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getIcon() {
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case PhabricatorTransactions::TYPE_CREATE:
|
|
||||||
return 'fa-plus';
|
|
||||||
break;
|
|
||||||
case self::TYPE_HEADERIMAGE:
|
|
||||||
return 'fa-camera-retro';
|
|
||||||
break;
|
|
||||||
case self::TYPE_VISIBILITY:
|
|
||||||
if ($new == PhameConstants::VISIBILITY_PUBLISHED) {
|
|
||||||
return 'fa-globe';
|
|
||||||
} else if ($new == PhameConstants::VISIBILITY_ARCHIVED) {
|
|
||||||
return 'fa-ban';
|
|
||||||
} else {
|
|
||||||
return 'fa-eye-slash';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return parent::getIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMailTags() {
|
public function getMailTags() {
|
||||||
$tags = parent::getMailTags();
|
$tags = parent::getMailTags();
|
||||||
|
|
||||||
|
@ -110,200 +46,4 @@ final class PhamePostTransaction
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getTitle() {
|
|
||||||
$author_phid = $this->getAuthorPHID();
|
|
||||||
$object_phid = $this->getObjectPHID();
|
|
||||||
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
|
|
||||||
$type = $this->getTransactionType();
|
|
||||||
switch ($type) {
|
|
||||||
case PhabricatorTransactions::TYPE_CREATE:
|
|
||||||
return pht(
|
|
||||||
'%s authored this post.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
case self::TYPE_BLOG:
|
|
||||||
return pht(
|
|
||||||
'%s moved this post from "%s" to "%s".',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($old),
|
|
||||||
$this->renderHandleLink($new));
|
|
||||||
case self::TYPE_TITLE:
|
|
||||||
if ($old === null) {
|
|
||||||
return pht(
|
|
||||||
'%s authored this post.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
} else {
|
|
||||||
return pht(
|
|
||||||
'%s updated the post\'s name to "%s".',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$new);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case self::TYPE_SUBTITLE:
|
|
||||||
if ($old === null) {
|
|
||||||
return pht(
|
|
||||||
'%s set the post\'s subtitle to "%s".',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$new);
|
|
||||||
} else {
|
|
||||||
return pht(
|
|
||||||
'%s updated the post\'s subtitle to "%s".',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$new);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case self::TYPE_BODY:
|
|
||||||
return pht(
|
|
||||||
'%s updated the blog post.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
break;
|
|
||||||
case self::TYPE_HEADERIMAGE:
|
|
||||||
return pht(
|
|
||||||
'%s updated the header image.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
break;
|
|
||||||
case self::TYPE_VISIBILITY:
|
|
||||||
if ($new == PhameConstants::VISIBILITY_DRAFT) {
|
|
||||||
return pht(
|
|
||||||
'%s marked this post as a draft.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
} else if ($new == PhameConstants::VISIBILITY_ARCHIVED) {
|
|
||||||
return pht(
|
|
||||||
'%s archived this post.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
} else {
|
|
||||||
return pht(
|
|
||||||
'%s published this post.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTitleForFeed() {
|
|
||||||
$author_phid = $this->getAuthorPHID();
|
|
||||||
$object_phid = $this->getObjectPHID();
|
|
||||||
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
|
|
||||||
$type = $this->getTransactionType();
|
|
||||||
switch ($type) {
|
|
||||||
case PhabricatorTransactions::TYPE_CREATE:
|
|
||||||
return pht(
|
|
||||||
'%s authored %s.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
case self::TYPE_BLOG:
|
|
||||||
return pht(
|
|
||||||
'%s moved post "%s" from "%s" to "%s".',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid),
|
|
||||||
$this->renderHandleLink($old),
|
|
||||||
$this->renderHandleLink($new));
|
|
||||||
case self::TYPE_TITLE:
|
|
||||||
if ($old === null) {
|
|
||||||
return pht(
|
|
||||||
'%s authored %s.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
} else {
|
|
||||||
return pht(
|
|
||||||
'%s updated the name for %s.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case self::TYPE_SUBTITLE:
|
|
||||||
return pht(
|
|
||||||
'%s updated the subtitle for %s.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
break;
|
|
||||||
case self::TYPE_BODY:
|
|
||||||
return pht(
|
|
||||||
'%s updated the blog post %s.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
break;
|
|
||||||
case self::TYPE_HEADERIMAGE:
|
|
||||||
return pht(
|
|
||||||
'%s updated the header image for post %s.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
break;
|
|
||||||
case self::TYPE_VISIBILITY:
|
|
||||||
if ($new == PhameConstants::VISIBILITY_DRAFT) {
|
|
||||||
return pht(
|
|
||||||
'%s marked %s as a draft.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
} else if ($new == PhameConstants::VISIBILITY_ARCHIVED) {
|
|
||||||
return pht(
|
|
||||||
'%s marked %s as archived.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
} else {
|
|
||||||
return pht(
|
|
||||||
'%s published %s.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($object_phid));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getTitleForFeed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRemarkupBodyForFeed(PhabricatorFeedStory $story) {
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case self::TYPE_BODY:
|
|
||||||
if ($old === null) {
|
|
||||||
return $this->getNewValue();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getColor() {
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case PhabricatorTransactions::TYPE_CREATE:
|
|
||||||
return PhabricatorTransactions::COLOR_GREEN;
|
|
||||||
}
|
|
||||||
return parent::getColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasChangeDetails() {
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case self::TYPE_BODY:
|
|
||||||
return ($this->getOldValue() !== null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::hasChangeDetails();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderChangeDetails(PhabricatorUser $viewer) {
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case self::TYPE_BODY:
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
|
|
||||||
return $this->renderTextCorpusChangeDetails(
|
|
||||||
$viewer,
|
|
||||||
$old,
|
|
||||||
$new);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::renderChangeDetails($viewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ final class PhameBlogNameTransaction
|
||||||
|
|
||||||
public function getTitleForFeed() {
|
public function getTitleForFeed() {
|
||||||
return pht(
|
return pht(
|
||||||
'%s renamed %s blog froms %s to %s.',
|
'%s renamed %s blog from %s to %s.',
|
||||||
$this->renderAuthor(),
|
$this->renderAuthor(),
|
||||||
$this->renderObject(),
|
$this->renderObject(),
|
||||||
$this->renderOldValue(),
|
$this->renderOldValue(),
|
||||||
|
|
|
@ -45,11 +45,11 @@ final class PhameBlogStatusTransaction
|
||||||
|
|
||||||
public function getIcon() {
|
public function getIcon() {
|
||||||
$new = $this->getNewValue();
|
$new = $this->getNewValue();
|
||||||
if ($new == PhameBlog::STATUS_ARCHIVED) {
|
if ($new == PhameBlog::STATUS_ARCHIVED) {
|
||||||
return 'fa-ban';
|
return 'fa-ban';
|
||||||
} else {
|
} else {
|
||||||
return 'fa-check';
|
return 'fa-check';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
64
src/applications/phame/xaction/PhamePostBlogTransaction.php
Normal file
64
src/applications/phame/xaction/PhamePostBlogTransaction.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhamePostBlogTransaction
|
||||||
|
extends PhamePostTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'phame.post.blog';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getBlogPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$object->setBlogPHID($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
return pht(
|
||||||
|
'%s changed the blog for this post.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitleForFeed() {
|
||||||
|
return pht(
|
||||||
|
'%s changed the blog for post %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateTransactions($object, array $xactions) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
if ($this->isEmptyTextTransaction($object->getBlogPHID(), $xactions)) {
|
||||||
|
$errors[] = $this->newRequiredError(
|
||||||
|
pht('Posts must be attached to a blog.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($xactions as $xaction) {
|
||||||
|
$new_phid = $xaction->getNewValue();
|
||||||
|
|
||||||
|
$blog = id(new PhameBlogQuery())
|
||||||
|
->setViewer($this->getActor())
|
||||||
|
->withPHIDs(array($new_phid))
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
if ($blog) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht('The specified blog PHID ("%s") is not valid. You can only '.
|
||||||
|
'create a post on (or move a post into) a blog which you '.
|
||||||
|
'have permission to see and edit.',
|
||||||
|
$new_phid));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
src/applications/phame/xaction/PhamePostBodyTransaction.php
Normal file
60
src/applications/phame/xaction/PhamePostBodyTransaction.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhamePostBodyTransaction
|
||||||
|
extends PhamePostTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'phame.post.body';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$object->setBody($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
return pht(
|
||||||
|
'%s updated the post content.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitleForFeed() {
|
||||||
|
return pht(
|
||||||
|
'%s updated the post content for %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasChangeDetailView() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMailDiffSectionHeader() {
|
||||||
|
return pht('CHANGES TO POST CONTENT');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newChangeDetailView() {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
|
return id(new PhabricatorApplicationTransactionTextDiffDetailView())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->setOldText($this->getOldValue())
|
||||||
|
->setNewText($this->getNewValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newRemarkupChanges() {
|
||||||
|
$changes = array();
|
||||||
|
|
||||||
|
$changes[] = $this->newRemarkupChange()
|
||||||
|
->setOldValue($this->getOldValue())
|
||||||
|
->setNewValue($this->getNewValue());
|
||||||
|
|
||||||
|
return $changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIcon() {
|
||||||
|
return 'fa-file-text-o';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhamePostHeaderImageTransaction
|
||||||
|
extends PhamePostTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'phame.post.headerimage';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getHeaderImagePHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$object->setHeaderImagePHID($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
return pht(
|
||||||
|
'%s changed the header image for this post.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitleForFeed() {
|
||||||
|
return pht(
|
||||||
|
'%s changed the header image for post %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIcon() {
|
||||||
|
return 'fa-camera';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhamePostSubtitleTransaction
|
||||||
|
extends PhamePostTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'phame.post.subtitle';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getSubtitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$object->setSubtitle($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
$old = $this->getOldValue();
|
||||||
|
if ($old === null) {
|
||||||
|
return pht(
|
||||||
|
'%s set this post\'s subtitle to "%s".',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderNewValue());
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'%s updated the post\'s subtitle to "%s".',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderNewValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitleForFeed() {
|
||||||
|
$old = $this->getOldValue();
|
||||||
|
if ($old === null) {
|
||||||
|
return pht(
|
||||||
|
'%s set the subtitle for %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'%s updated the subtitle for %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateTransactions($object, array $xactions) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
$max_length = $object->getColumnMaximumByteLength('subtitle');
|
||||||
|
foreach ($xactions as $xaction) {
|
||||||
|
$new_value = $xaction->getNewValue();
|
||||||
|
$new_length = strlen($new_value);
|
||||||
|
if ($new_length > $max_length) {
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht('The subtitle can be no longer than %s characters.',
|
||||||
|
new PhutilNumber($max_length)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
55
src/applications/phame/xaction/PhamePostTitleTransaction.php
Normal file
55
src/applications/phame/xaction/PhamePostTitleTransaction.php
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhamePostTitleTransaction
|
||||||
|
extends PhamePostTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'phame.post.title';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$object->setTitle($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
return pht(
|
||||||
|
'%s renamed this blog post from %s to %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderOldValue(),
|
||||||
|
$this->renderNewValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitleForFeed() {
|
||||||
|
return pht(
|
||||||
|
'%s renamed %s blog post from %s to %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject(),
|
||||||
|
$this->renderOldValue(),
|
||||||
|
$this->renderNewValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateTransactions($object, array $xactions) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) {
|
||||||
|
$errors[] = $this->newRequiredError(
|
||||||
|
pht('Posts must have a title.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$max_length = $object->getColumnMaximumByteLength('title');
|
||||||
|
foreach ($xactions as $xaction) {
|
||||||
|
$new_value = $xaction->getNewValue();
|
||||||
|
$new_length = strlen($new_value);
|
||||||
|
if ($new_length > $max_length) {
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht('The title can be no longer than %s characters.',
|
||||||
|
new PhutilNumber($max_length)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhamePostTransactionType
|
||||||
|
extends PhabricatorModularTransactionType {}
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhamePostVisibilityTransaction
|
||||||
|
extends PhamePostTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'phame.post.visibility';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
if ($value == PhameConstants::VISIBILITY_DRAFT) {
|
||||||
|
$object->setDatePublished(0);
|
||||||
|
} else if ($value == PhameConstants::VISIBILITY_ARCHIVED) {
|
||||||
|
$object->setDatePublished(0);
|
||||||
|
} else {
|
||||||
|
$object->setDatePublished(PhabricatorTime::getNow());
|
||||||
|
}
|
||||||
|
$object->setVisibility($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
if ($new == PhameConstants::VISIBILITY_DRAFT) {
|
||||||
|
return pht(
|
||||||
|
'%s marked this post as a draft.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
} else if ($new == PhameConstants::VISIBILITY_ARCHIVED) {
|
||||||
|
return pht(
|
||||||
|
'%s archived this post.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'%s published this post.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitleForFeed() {
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
if ($new == PhameConstants::VISIBILITY_DRAFT) {
|
||||||
|
return pht(
|
||||||
|
'%s marked %s as a draft.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
} else if ($new == PhameConstants::VISIBILITY_ARCHIVED) {
|
||||||
|
return pht(
|
||||||
|
'%s marked %s as archived.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'%s published %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIcon() {
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
if ($new == PhameConstants::VISIBILITY_PUBLISHED) {
|
||||||
|
return 'fa-rss';
|
||||||
|
} else if ($new == PhameConstants::VISIBILITY_ARCHIVED) {
|
||||||
|
return 'fa-ban';
|
||||||
|
} else {
|
||||||
|
return 'fa-eye-slash';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue