Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15288700
D17818.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
37 KB
Referenced Files
None
Subscribers
None
D17818.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -4272,12 +4272,15 @@
'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php',
'PhamePost' => 'applications/phame/storage/PhamePost.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',
'PhamePostEditConduitAPIMethod' => 'applications/phame/conduit/PhamePostEditConduitAPIMethod.php',
'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php',
'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php',
'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php',
'PhamePostFulltextEngine' => 'applications/phame/search/PhamePostFulltextEngine.php',
+ 'PhamePostHeaderImageTransaction' => 'applications/phame/xaction/PhamePostHeaderImageTransaction.php',
'PhamePostHeaderPictureController' => 'applications/phame/controller/post/PhamePostHeaderPictureController.php',
'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php',
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
@@ -4290,10 +4293,14 @@
'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php',
'PhamePostSearchConduitAPIMethod' => 'applications/phame/conduit/PhamePostSearchConduitAPIMethod.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',
'PhamePostTransactionComment' => 'applications/phame/storage/PhamePostTransactionComment.php',
'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php',
+ 'PhamePostTransactionType' => 'applications/phame/xaction/PhamePostTransactionType.php',
'PhamePostViewController' => 'applications/phame/controller/post/PhamePostViewController.php',
+ 'PhamePostVisibilityTransaction' => 'applications/phame/xaction/PhamePostVisibilityTransaction.php',
'PhameSchemaSpec' => 'applications/phame/storage/PhameSchemaSpec.php',
'PhameSite' => 'applications/phame/site/PhameSite.php',
'PhluxController' => 'applications/phlux/controller/PhluxController.php',
@@ -9753,12 +9760,15 @@
'PhabricatorFulltextInterface',
),
'PhamePostArchiveController' => 'PhamePostController',
+ 'PhamePostBlogTransaction' => 'PhamePostTransactionType',
+ 'PhamePostBodyTransaction' => 'PhamePostTransactionType',
'PhamePostController' => 'PhameController',
'PhamePostEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PhamePostEditController' => 'PhamePostController',
'PhamePostEditEngine' => 'PhabricatorEditEngine',
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
'PhamePostFulltextEngine' => 'PhabricatorFulltextEngine',
+ 'PhamePostHeaderImageTransaction' => 'PhamePostTransactionType',
'PhamePostHeaderPictureController' => 'PhamePostController',
'PhamePostHistoryController' => 'PhamePostController',
'PhamePostListController' => 'PhamePostController',
@@ -9771,10 +9781,14 @@
'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'PhamePostSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine',
- 'PhamePostTransaction' => 'PhabricatorApplicationTransaction',
+ 'PhamePostSubtitleTransaction' => 'PhamePostTransactionType',
+ 'PhamePostTitleTransaction' => 'PhamePostTransactionType',
+ 'PhamePostTransaction' => 'PhabricatorModularTransaction',
'PhamePostTransactionComment' => 'PhabricatorApplicationTransactionComment',
'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+ 'PhamePostTransactionType' => 'PhabricatorModularTransactionType',
'PhamePostViewController' => 'PhameLiveController',
+ 'PhamePostVisibilityTransaction' => 'PhamePostTransactionType',
'PhameSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PhameSite' => 'PhabricatorSite',
'PhluxController' => 'PhabricatorController',
diff --git a/src/applications/phame/controller/post/PhamePostArchiveController.php b/src/applications/phame/controller/post/PhamePostArchiveController.php
--- a/src/applications/phame/controller/post/PhamePostArchiveController.php
+++ b/src/applications/phame/controller/post/PhamePostArchiveController.php
@@ -26,7 +26,7 @@
$new_value = PhameConstants::VISIBILITY_ARCHIVED;
$xactions[] = id(new PhamePostTransaction())
- ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
+ ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE)
->setNewValue($new_value);
id(new PhamePostEditor())
diff --git a/src/applications/phame/controller/post/PhamePostHeaderPictureController.php b/src/applications/phame/controller/post/PhamePostHeaderPictureController.php
--- a/src/applications/phame/controller/post/PhamePostHeaderPictureController.php
+++ b/src/applications/phame/controller/post/PhamePostHeaderPictureController.php
@@ -61,7 +61,7 @@
$xactions = array();
$xactions[] = id(new PhamePostTransaction())
- ->setTransactionType(PhamePostTransaction::TYPE_HEADERIMAGE)
+ ->setTransactionType(PhamePostHeaderImageTransaction::TRANSACTIONTYPE)
->setNewValue($new_value);
$editor = id(new PhamePostEditor())
diff --git a/src/applications/phame/controller/post/PhamePostMoveController.php b/src/applications/phame/controller/post/PhamePostMoveController.php
--- a/src/applications/phame/controller/post/PhamePostMoveController.php
+++ b/src/applications/phame/controller/post/PhamePostMoveController.php
@@ -28,7 +28,7 @@
$xactions = array();
$xactions[] = id(new PhamePostTransaction())
- ->setTransactionType(PhamePostTransaction::TYPE_BLOG)
+ ->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE)
->setNewValue($v_blog);
$editor = id(new PhamePostEditor())
diff --git a/src/applications/phame/controller/post/PhamePostPublishController.php b/src/applications/phame/controller/post/PhamePostPublishController.php
--- a/src/applications/phame/controller/post/PhamePostPublishController.php
+++ b/src/applications/phame/controller/post/PhamePostPublishController.php
@@ -34,7 +34,7 @@
}
$xactions[] = id(new PhamePostTransaction())
- ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
+ ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE)
->setNewValue($new_value);
id(new PhamePostEditor())
diff --git a/src/applications/phame/editor/PhamePostEditEngine.php b/src/applications/phame/editor/PhamePostEditEngine.php
--- a/src/applications/phame/editor/PhamePostEditEngine.php
+++ b/src/applications/phame/editor/PhamePostEditEngine.php
@@ -84,7 +84,7 @@
pht('Choose a blog to create a post on (or move a post to).'))
->setConduitTypeDescription(pht('PHID of the blog.'))
->setAliases(array('blogPHID'))
- ->setTransactionType(PhamePostTransaction::TYPE_BLOG)
+ ->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE)
->setHandleParameterType(new AphrontPHIDListHTTPParameterType())
->setSingleValue($blog_phid)
->setIsReorderable(false)
@@ -97,7 +97,7 @@
->setDescription(pht('Post title.'))
->setConduitDescription(pht('Retitle the post.'))
->setConduitTypeDescription(pht('New post title.'))
- ->setTransactionType(PhamePostTransaction::TYPE_TITLE)
+ ->setTransactionType(PhamePostTitleTransaction::TRANSACTIONTYPE)
->setValue($object->getTitle()),
id(new PhabricatorTextEditField())
->setKey('subtitle')
@@ -105,7 +105,7 @@
->setDescription(pht('Post subtitle.'))
->setConduitDescription(pht('Change the post subtitle.'))
->setConduitTypeDescription(pht('New post subtitle.'))
- ->setTransactionType(PhamePostTransaction::TYPE_SUBTITLE)
+ ->setTransactionType(PhamePostSubtitleTransaction::TRANSACTIONTYPE)
->setValue($object->getSubtitle()),
id(new PhabricatorSelectEditField())
->setKey('visibility')
@@ -113,7 +113,7 @@
->setDescription(pht('Post visibility.'))
->setConduitDescription(pht('Change post visibility.'))
->setConduitTypeDescription(pht('New post visibility constant.'))
- ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
+ ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE)
->setValue($object->getVisibility())
->setOptions(PhameConstants::getPhamePostStatusMap()),
id(new PhabricatorRemarkupEditField())
@@ -122,7 +122,7 @@
->setDescription(pht('Post body.'))
->setConduitDescription(pht('Change post body.'))
->setConduitTypeDescription(pht('New post body.'))
- ->setTransactionType(PhamePostTransaction::TYPE_BODY)
+ ->setTransactionType(PhamePostBodyTransaction::TRANSACTIONTYPE)
->setValue($object->getBody())
->setPreviewPanel(
id(new PHUIRemarkupPreviewPanel())
diff --git a/src/applications/phame/editor/PhamePostEditor.php b/src/applications/phame/editor/PhamePostEditor.php
--- a/src/applications/phame/editor/PhamePostEditor.php
+++ b/src/applications/phame/editor/PhamePostEditor.php
@@ -11,175 +11,19 @@
return pht('Phame Posts');
}
- public function 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;
-
- 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();
- }
+ public function getCreateObjectTitle($author, $object) {
+ return pht('%s created this post.', $author);
}
- 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);
+ public function getCreateObjectTitleForFeed($author, $object) {
+ return pht('%s created %s.', $author, $object);
}
- 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);
- }
+ public function getTransactionTypes() {
+ $types = parent::getTransactionTypes();
+ $types[] = PhabricatorTransactions::TYPE_COMMENT;
- break;
- }
- return $errors;
+ return $types;
}
protected function shouldSendMail(
diff --git a/src/applications/phame/storage/PhamePostTransaction.php b/src/applications/phame/storage/PhamePostTransaction.php
--- a/src/applications/phame/storage/PhamePostTransaction.php
+++ b/src/applications/phame/storage/PhamePostTransaction.php
@@ -1,14 +1,7 @@
<?php
final class PhamePostTransaction
- extends PhabricatorApplicationTransaction {
-
- 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';
+ extends PhabricatorModularTransaction {
const MAILTAG_CONTENT = 'phame-post-content';
const MAILTAG_SUBSCRIBERS = 'phame-post-subscribers';
@@ -23,69 +16,12 @@
return PhabricatorPhamePostPHIDType::TYPECONST;
}
- public function getApplicationTransactionCommentObject() {
- 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 getBaseTransactionClass() {
+ return 'PhamePostTransactionType';
}
-
- 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 getApplicationTransactionCommentObject() {
+ return new PhamePostTransactionComment();
}
public function getMailTags() {
@@ -110,200 +46,4 @@
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);
- }
-
}
diff --git a/src/applications/phame/xaction/PhameBlogNameTransaction.php b/src/applications/phame/xaction/PhameBlogNameTransaction.php
--- a/src/applications/phame/xaction/PhameBlogNameTransaction.php
+++ b/src/applications/phame/xaction/PhameBlogNameTransaction.php
@@ -23,7 +23,7 @@
public function getTitleForFeed() {
return pht(
- '%s renamed %s blog froms %s to %s.',
+ '%s renamed %s blog from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
diff --git a/src/applications/phame/xaction/PhameBlogStatusTransaction.php b/src/applications/phame/xaction/PhameBlogStatusTransaction.php
--- a/src/applications/phame/xaction/PhameBlogStatusTransaction.php
+++ b/src/applications/phame/xaction/PhameBlogStatusTransaction.php
@@ -45,11 +45,11 @@
public function getIcon() {
$new = $this->getNewValue();
- if ($new == PhameBlog::STATUS_ARCHIVED) {
- return 'fa-ban';
- } else {
- return 'fa-check';
- }
+ if ($new == PhameBlog::STATUS_ARCHIVED) {
+ return 'fa-ban';
+ } else {
+ return 'fa-check';
}
+ }
}
diff --git a/src/applications/phame/xaction/PhamePostBlogTransaction.php b/src/applications/phame/xaction/PhamePostBlogTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/xaction/PhamePostBlogTransaction.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/phame/xaction/PhamePostBodyTransaction.php b/src/applications/phame/xaction/PhamePostBodyTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/xaction/PhamePostBodyTransaction.php
@@ -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';
+ }
+
+}
diff --git a/src/applications/phame/xaction/PhamePostHeaderImageTransaction.php b/src/applications/phame/xaction/PhamePostHeaderImageTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/xaction/PhamePostHeaderImageTransaction.php
@@ -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';
+ }
+
+}
diff --git a/src/applications/phame/xaction/PhamePostSubtitleTransaction.php b/src/applications/phame/xaction/PhamePostSubtitleTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/xaction/PhamePostSubtitleTransaction.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/phame/xaction/PhameBlogNameTransaction.php b/src/applications/phame/xaction/PhamePostTitleTransaction.php
copy from src/applications/phame/xaction/PhameBlogNameTransaction.php
copy to src/applications/phame/xaction/PhamePostTitleTransaction.php
--- a/src/applications/phame/xaction/PhameBlogNameTransaction.php
+++ b/src/applications/phame/xaction/PhamePostTitleTransaction.php
@@ -1,21 +1,21 @@
<?php
-final class PhameBlogNameTransaction
- extends PhameBlogTransactionType {
+final class PhamePostTitleTransaction
+ extends PhamePostTransactionType {
- const TRANSACTIONTYPE = 'phame.blog.name';
+ const TRANSACTIONTYPE = 'phame.post.title';
public function generateOldValue($object) {
- return $object->getName();
+ return $object->getTitle();
}
public function applyInternalEffects($object, $value) {
- $object->setName($value);
+ $object->setTitle($value);
}
public function getTitle() {
return pht(
- '%s renamed this blog from %s to %s.',
+ '%s renamed this blog post from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
@@ -23,7 +23,7 @@
public function getTitleForFeed() {
return pht(
- '%s renamed %s blog froms %s to %s.',
+ '%s renamed %s blog post from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
@@ -33,18 +33,18 @@
public function validateTransactions($object, array $xactions) {
$errors = array();
- if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
+ if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) {
$errors[] = $this->newRequiredError(
- pht('Blogs must have a name.'));
+ pht('Posts must have a title.'));
}
- $max_length = $object->getColumnMaximumByteLength('name');
+ $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 name can be no longer than %s characters.',
+ pht('The title can be no longer than %s characters.',
new PhutilNumber($max_length)));
}
}
@@ -52,8 +52,4 @@
return $errors;
}
- public function getIcon() {
- return 'fa-rss';
- }
-
}
diff --git a/src/applications/phame/xaction/PhamePostTransactionType.php b/src/applications/phame/xaction/PhamePostTransactionType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/xaction/PhamePostTransactionType.php
@@ -0,0 +1,4 @@
+<?php
+
+abstract class PhamePostTransactionType
+ extends PhabricatorModularTransactionType {}
diff --git a/src/applications/phame/xaction/PhamePostVisibilityTransaction.php b/src/applications/phame/xaction/PhamePostVisibilityTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/xaction/PhamePostVisibilityTransaction.php
@@ -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';
+ }
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 5, 8:55 PM (1 w, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7227261
Default Alt Text
D17818.diff (37 KB)
Attached To
Mode
D17818: Update PhamePost for modular transactions
Attached
Detach File
Event Timeline
Log In to Comment