1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 12:52:42 +01:00

Add mail support to PhameBlog

Summary: Add some mailkeys, allow feed stories to be published.

Test Plan: New Blog, Edit Blog

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14434
This commit is contained in:
Chad Little 2015-11-08 07:50:01 -08:00
parent 2b41ed01c6
commit c3ecea9788
8 changed files with 147 additions and 3 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phame.phame_blog
ADD mailKey binary(20) NOT NULL;

View file

@ -0,0 +1,18 @@
<?php
$table = new PhameBlog();
$conn_w = $table->establishConnection('w');
$iterator = new LiskMigrationIterator($table);
foreach ($iterator as $blog) {
$id = $blog->getID();
echo pht('Adding mail key for Blog %d...', $id);
echo "\n";
queryfx(
$conn_w,
'UPDATE %T SET mailKey = %s WHERE id = %d',
$table->getTableName(),
Filesystem::readRandomCharacters(20),
$id);
}

View file

@ -3256,10 +3256,12 @@ phutil_register_library_map(array(
'PhameBlogListController' => 'applications/phame/controller/blog/PhameBlogListController.php', 'PhameBlogListController' => 'applications/phame/controller/blog/PhameBlogListController.php',
'PhameBlogLiveController' => 'applications/phame/controller/blog/PhameBlogLiveController.php', 'PhameBlogLiveController' => 'applications/phame/controller/blog/PhameBlogLiveController.php',
'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php', 'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php',
'PhameBlogReplyHandler' => 'applications/phame/mail/PhameBlogReplyHandler.php',
'PhameBlogSearchEngine' => 'applications/phame/query/PhameBlogSearchEngine.php', 'PhameBlogSearchEngine' => 'applications/phame/query/PhameBlogSearchEngine.php',
'PhameBlogSite' => 'applications/phame/site/PhameBlogSite.php', 'PhameBlogSite' => 'applications/phame/site/PhameBlogSite.php',
'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php', 'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php',
'PhameBlogTransaction' => 'applications/phame/storage/PhameBlogTransaction.php', 'PhameBlogTransaction' => 'applications/phame/storage/PhameBlogTransaction.php',
'PhameBlogTransactionQuery' => 'applications/phame/query/PhameBlogTransactionQuery.php',
'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php', 'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php',
'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php', 'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php',
'PhameConduitAPIMethod' => 'applications/phame/conduit/PhameConduitAPIMethod.php', 'PhameConduitAPIMethod' => 'applications/phame/conduit/PhameConduitAPIMethod.php',
@ -7521,10 +7523,12 @@ phutil_register_library_map(array(
'PhameBlogListController' => 'PhameBlogController', 'PhameBlogListController' => 'PhameBlogController',
'PhameBlogLiveController' => 'PhameBlogController', 'PhameBlogLiveController' => 'PhameBlogController',
'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhameBlogReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhameBlogSite' => 'PhameSite', 'PhameBlogSite' => 'PhameSite',
'PhameBlogSkin' => 'PhabricatorController', 'PhameBlogSkin' => 'PhabricatorController',
'PhameBlogTransaction' => 'PhabricatorApplicationTransaction', 'PhameBlogTransaction' => 'PhabricatorApplicationTransaction',
'PhameBlogTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhameBlogViewController' => 'PhameBlogController', 'PhameBlogViewController' => 'PhameBlogController',
'PhameCelerityResources' => 'CelerityResources', 'PhameCelerityResources' => 'CelerityResources',
'PhameConduitAPIMethod' => 'ConduitAPIMethod', 'PhameConduitAPIMethod' => 'ConduitAPIMethod',

View file

@ -162,15 +162,66 @@ final class PhameBlogEditor
protected function shouldSendMail( protected function shouldSendMail(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
return false; return true;
} }
protected function shouldPublishFeedStory( protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {
return false; return true;
} }
protected function getMailTo(PhabricatorLiskDAO $object) {
$phids = array();
$phids[] = $this->requireActor()->getPHID();
$phids[] = $object->getCreatorPHID();
return $phids;
}
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
$phid = $object->getPHID();
$name = $object->getName();
return id(new PhabricatorMetaMTAMail())
->setSubject($name)
->addHeader('Thread-Topic', $phid);
}
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
return id(new PhameBlogReplyHandler())
->setMailReceiver($object);
}
protected function buildMailBody(
PhabricatorLiskDAO $object,
array $xactions) {
$body = parent::buildMailBody($object, $xactions);
$body->addLinkSection(
pht('BLOG DETAIL'),
PhabricatorEnv::getProductionURI($object->getViewURI()));
return $body;
}
public function getMailTagsMap() {
return array(
PhameBlogTransaction::MAILTAG_DETAILS =>
pht("A blog's details change."),
PhameBlogTransaction::MAILTAG_SUBSCRIBERS =>
pht("A blog's subscribers change."),
PhameBlogTransaction::MAILTAG_OTHER =>
pht('Other blog activity not listed above occurs.'),
);
}
protected function getMailSubjectPrefix() {
return '[Phame]';
}
protected function supportsSearch() { protected function supportsSearch() {
return false; return false;
} }

View file

@ -0,0 +1,21 @@
<?php
final class PhameBlogReplyHandler
extends PhabricatorApplicationTransactionReplyHandler {
public function validateMailReceiver($mail_receiver) {
if (!($mail_receiver instanceof PhameBlog)) {
throw new Exception(
pht('Mail receiver is not a %s.', 'PhameBlog'));
}
}
public function getObjectPrefix() {
return PhabricatorPhameBlogPHIDType::TYPECONST;
}
protected function shouldCreateCommentFromMailBody() {
return false;
}
}

View file

@ -0,0 +1,10 @@
<?php
final class PhameBlogTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new PhameBlogTransaction();
}
}

View file

@ -21,6 +21,7 @@ final class PhameBlog extends PhameDAO
protected $viewPolicy; protected $viewPolicy;
protected $editPolicy; protected $editPolicy;
protected $joinPolicy; protected $joinPolicy;
protected $mailKey;
private static $requestBlog; private static $requestBlog;
@ -34,6 +35,7 @@ final class PhameBlog extends PhameDAO
'name' => 'text64', 'name' => 'text64',
'description' => 'text', 'description' => 'text',
'domain' => 'text128?', 'domain' => 'text128?',
'mailKey' => 'bytes20',
// T6203/NULLABILITY // T6203/NULLABILITY
// These policies should always be non-null. // These policies should always be non-null.
@ -55,6 +57,13 @@ final class PhameBlog extends PhameDAO
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }
public function save() {
if (!$this->getMailKey()) {
$this->setMailKey(Filesystem::readRandomCharacters(20));
}
return parent::save();
}
public function generatePHID() { public function generatePHID() {
return PhabricatorPHID::generateNewPHID( return PhabricatorPHID::generateNewPHID(
PhabricatorPhameBlogPHIDType::TYPECONST); PhabricatorPhameBlogPHIDType::TYPECONST);
@ -214,6 +223,11 @@ final class PhameBlog extends PhameDAO
return $base; return $base;
} }
public function getViewURI() {
$uri = '/phame/blog/view/'.$this->getID().'/';
return PhabricatorEnv::getProductionURI($uri);
}
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */ /* -( PhabricatorPolicyInterface Implementation )-------------------------- */

View file

@ -8,6 +8,10 @@ final class PhameBlogTransaction
const TYPE_DOMAIN = 'phame.blog.domain'; const TYPE_DOMAIN = 'phame.blog.domain';
const TYPE_SKIN = 'phame.blog.skin'; const TYPE_SKIN = 'phame.blog.skin';
const MAILTAG_DETAILS = 'phame-blog-details';
const MAILTAG_SUBSCRIBERS = 'phame-blog-subscribers';
const MAILTAG_OTHER = 'phame-blog-other';
public function getApplicationName() { public function getApplicationName() {
return 'phame'; return 'phame';
} }
@ -44,6 +48,26 @@ final class PhameBlogTransaction
return parent::getIcon(); return parent::getIcon();
} }
public function getMailTags() {
$tags = parent::getMailTags();
switch ($this->getTransactionType()) {
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
$tags[] = self::MAILTAG_SUBSCRIBERS;
break;
case self::TYPE_NAME:
case self::TYPE_DESCRIPTION:
case self::TYPE_DOMAIN:
case self::TYPE_SKIN:
$tags[] = self::MAILTAG_DETAILS;
break;
default:
$tags[] = self::MAILTAG_OTHER;
break;
}
return $tags;
}
public function getTitle() { public function getTitle() {
$author_phid = $this->getAuthorPHID(); $author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID(); $object_phid = $this->getObjectPHID();
@ -53,7 +77,7 @@ final class PhameBlogTransaction
$type = $this->getTransactionType(); $type = $this->getTransactionType();
switch ($type) { switch ($type) {
case self:TYPE_NAME: case self::TYPE_NAME:
if ($old === null) { if ($old === null) {
return pht( return pht(
'%s created this blog.', '%s created this blog.',