Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/phame/editor/PhamePostEditor.php b/src/applications/phame/editor/PhamePostEditor.php
index e3cd1a4417..c816ecfed6 100644
--- a/src/applications/phame/editor/PhamePostEditor.php
+++ b/src/applications/phame/editor/PhamePostEditor.php
@@ -1,255 +1,257 @@
<?php
final class PhamePostEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorPhameApplication';
}
public function getEditorObjectsDescription() {
return pht('Phame Posts');
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhamePostTransaction::TYPE_TITLE;
$types[] = PhamePostTransaction::TYPE_PHAME_TITLE;
$types[] = PhamePostTransaction::TYPE_BODY;
$types[] = PhamePostTransaction::TYPE_VISIBILITY;
$types[] = PhabricatorTransactions::TYPE_COMMENT;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhamePostTransaction::TYPE_TITLE:
return $object->getTitle();
case PhamePostTransaction::TYPE_PHAME_TITLE:
return $object->getPhameTitle();
case PhamePostTransaction::TYPE_BODY:
return $object->getBody();
case PhamePostTransaction::TYPE_VISIBILITY:
return $object->getVisibility();
}
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhamePostTransaction::TYPE_TITLE:
case PhamePostTransaction::TYPE_PHAME_TITLE:
case PhamePostTransaction::TYPE_BODY:
case PhamePostTransaction::TYPE_VISIBILITY:
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_PHAME_TITLE:
return $object->setPhameTitle($xaction->getNewValue());
case PhamePostTransaction::TYPE_BODY:
return $object->setBody($xaction->getNewValue());
case PhamePostTransaction::TYPE_VISIBILITY:
if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) {
$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_PHAME_TITLE:
case PhamePostTransaction::TYPE_BODY:
case PhamePostTransaction::TYPE_VISIBILITY:
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_PHAME_TITLE:
if (!$xactions) {
continue;
}
$missing = $this->validateIsEmptyTextField(
$object->getPhameTitle(),
$xactions);
$phame_title = last($xactions)->getNewValue();
if ($missing || $phame_title == '/') {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Required'),
pht('Phame title is required.'),
nonempty(last($xactions), null));
$error->setIsMissingFieldError(true);
$errors[] = $error;
}
$duplicate_post = id(new PhamePostQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPhameTitles(array($phame_title))
->executeOne();
if ($duplicate_post && $duplicate_post->getID() != $object->getID()) {
$error_text = pht(
'Phame title must be unique; another post already has this phame '.
'title.');
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Not Unique'),
$error_text,
nonempty(last($xactions), null));
$errors[] = $error;
}
break;
}
return $errors;
}
protected function shouldSendMail(
PhabricatorLiskDAO $object,
array $xactions) {
if ($object->isDraft()) {
return false;
}
return true;
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
if ($object->isDraft()) {
return false;
}
return true;
}
protected function getMailTo(PhabricatorLiskDAO $object) {
$phids = array();
$phids[] = $object->getBloggerPHID();
$phids[] = $this->requireActor()->getPHID();
$blog_phid = $object->getBlogPHID();
if ($blog_phid) {
$cc_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$blog_phid);
foreach ($cc_phids as $cc) {
$phids[] = $cc;
}
}
return $phids;
}
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
$phid = $object->getPHID();
$title = $object->getTitle();
return id(new PhabricatorMetaMTAMail())
->setSubject($title)
->addHeader('Thread-Topic', $phid);
}
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
return id(new PhamePostReplyHandler())
->setMailReceiver($object);
}
protected function buildMailBody(
PhabricatorLiskDAO $object,
array $xactions) {
$body = parent::buildMailBody($object, $xactions);
// We don't send mail if the object is a draft, and we only want
// to include the full body of the post on the either the
// first creation or if it was created as a draft, once it goes live.
if ($this->getIsNewObject()) {
$body->addRemarkupSection(null, $object->getBody());
} else {
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PhamePostTransaction::TYPE_VISIBILITY:
if (!$object->isDraft()) {
$body->addRemarkupSection(null, $object->getBody());
}
break;
}
}
}
$body->addLinkSection(
pht('POST DETAIL'),
PhabricatorEnv::getProductionURI($object->getViewURI()));
return $body;
}
public function getMailTagsMap() {
return array(
PhamePostTransaction::MAILTAG_CONTENT =>
pht("A post's content changes."),
+ PhamePostTransaction::MAILTAG_SUBSCRIBERS =>
+ pht("A post's subscribers change."),
PhamePostTransaction::MAILTAG_COMMENT =>
pht('Someone comments on a post.'),
PhamePostTransaction::MAILTAG_OTHER =>
pht('Other post activity not listed above occurs.'),
);
}
protected function getMailSubjectPrefix() {
return '[Phame]';
}
protected function supportsSearch() {
return false;
}
}
diff --git a/src/applications/phame/storage/PhamePostTransaction.php b/src/applications/phame/storage/PhamePostTransaction.php
index 5e28b87198..063bc4ad66 100644
--- a/src/applications/phame/storage/PhamePostTransaction.php
+++ b/src/applications/phame/storage/PhamePostTransaction.php
@@ -1,249 +1,253 @@
<?php
final class PhamePostTransaction
extends PhabricatorApplicationTransaction {
const TYPE_TITLE = 'phame.post.title';
const TYPE_PHAME_TITLE = 'phame.post.phame.title';
const TYPE_BODY = 'phame.post.body';
const TYPE_VISIBILITY = 'phame.post.visibility';
const MAILTAG_CONTENT = 'phame-post-content';
+ const MAILTAG_SUBSCRIBERS = 'phame-post-subscribers';
const MAILTAG_COMMENT = 'phame-post-comment';
const MAILTAG_OTHER = 'phame-post-other';
public function getApplicationName() {
return 'phame';
}
public function getApplicationTransactionType() {
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() {
$old = $this->getOldValue();
switch ($this->getTransactionType()) {
case self::TYPE_PHAME_TITLE:
case self::TYPE_BODY:
return ($old === null);
}
return parent::shouldHide();
}
public function getIcon() {
$old = $this->getOldValue();
switch ($this->getTransactionType()) {
case self::TYPE_TITLE:
if ($old === null) {
return 'fa-plus';
} else {
return 'fa-pencil';
}
break;
case self::TYPE_PHAME_TITLE:
case self::TYPE_BODY:
case self::TYPE_VISIBILITY:
return 'fa-pencil';
break;
}
return parent::getIcon();
}
public function getMailTags() {
$tags = parent::getMailTags();
switch ($this->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
$tags[] = self::MAILTAG_COMMENT;
break;
+ case PhabricatorTransactions::TYPE_SUBSCRIBERS:
+ $tags[] = self::MAILTAG_SUBSCRIBERS;
+ break;
case self::TYPE_TITLE:
case self::TYPE_PHAME_TITLE:
case self::TYPE_BODY:
$tags[] = self::MAILTAG_CONTENT;
break;
default:
$tags[] = self::MAILTAG_OTHER;
break;
}
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 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_BODY:
return pht(
'%s updated the blog post.',
$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 {
return pht(
'%s published this post.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_PHAME_TITLE:
return pht(
'%s updated the post\'s Phame title to "%s".',
$this->renderHandleLink($author_phid),
rtrim($new, '/'));
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 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_BODY:
return pht(
'%s updated the blog 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 {
return pht(
'%s published %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
}
break;
case self::TYPE_PHAME_TITLE:
return pht(
'%s updated the Phame title for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
}
return parent::getTitleForFeed();
}
public function getRemarkupBodyForFeed(PhabricatorFeedStory $story) {
$text = null;
switch ($this->getTransactionType()) {
case self::TYPE_TITLE:
if ($this->getOldValue() === null) {
$post = $story->getPrimaryObject();
$text = $post->getBody();
}
break;
case self::TYPE_VISIBILITY:
if ($this->getNewValue() == PhameConstants::VISIBILITY_PUBLISHED) {
$post = $story->getPrimaryObject();
$text = $post->getBody();
}
break;
case self::TYPE_BODY:
$text = $this->getNewValue();
break;
}
return $text;
}
public function getColor() {
$old = $this->getOldValue();
switch ($this->getTransactionType()) {
case self::TYPE_TITLE:
if ($old === null) {
return PhabricatorTransactions::COLOR_GREEN;
}
break;
}
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);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Mar 14, 12:36 PM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
71870
Default Alt Text
(15 KB)

Event Timeline