mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +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:
parent
2b41ed01c6
commit
c3ecea9788
8 changed files with 147 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_phame.phame_blog
|
||||
ADD mailKey binary(20) NOT NULL;
|
18
resources/sql/autopatches/20151107.phame.blog.mailkey.2.php
Normal file
18
resources/sql/autopatches/20151107.phame.blog.mailkey.2.php
Normal 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);
|
||||
}
|
|
@ -3256,10 +3256,12 @@ phutil_register_library_map(array(
|
|||
'PhameBlogListController' => 'applications/phame/controller/blog/PhameBlogListController.php',
|
||||
'PhameBlogLiveController' => 'applications/phame/controller/blog/PhameBlogLiveController.php',
|
||||
'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php',
|
||||
'PhameBlogReplyHandler' => 'applications/phame/mail/PhameBlogReplyHandler.php',
|
||||
'PhameBlogSearchEngine' => 'applications/phame/query/PhameBlogSearchEngine.php',
|
||||
'PhameBlogSite' => 'applications/phame/site/PhameBlogSite.php',
|
||||
'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php',
|
||||
'PhameBlogTransaction' => 'applications/phame/storage/PhameBlogTransaction.php',
|
||||
'PhameBlogTransactionQuery' => 'applications/phame/query/PhameBlogTransactionQuery.php',
|
||||
'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php',
|
||||
'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php',
|
||||
'PhameConduitAPIMethod' => 'applications/phame/conduit/PhameConduitAPIMethod.php',
|
||||
|
@ -7521,10 +7523,12 @@ phutil_register_library_map(array(
|
|||
'PhameBlogListController' => 'PhameBlogController',
|
||||
'PhameBlogLiveController' => 'PhameBlogController',
|
||||
'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhameBlogReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||
'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhameBlogSite' => 'PhameSite',
|
||||
'PhameBlogSkin' => 'PhabricatorController',
|
||||
'PhameBlogTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'PhameBlogTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhameBlogViewController' => 'PhameBlogController',
|
||||
'PhameCelerityResources' => 'CelerityResources',
|
||||
'PhameConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
|
|
|
@ -162,15 +162,66 @@ final class PhameBlogEditor
|
|||
protected function shouldSendMail(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function shouldPublishFeedStory(
|
||||
PhabricatorLiskDAO $object,
|
||||
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() {
|
||||
return false;
|
||||
}
|
||||
|
|
21
src/applications/phame/mail/PhameBlogReplyHandler.php
Normal file
21
src/applications/phame/mail/PhameBlogReplyHandler.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
10
src/applications/phame/query/PhameBlogTransactionQuery.php
Normal file
10
src/applications/phame/query/PhameBlogTransactionQuery.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class PhameBlogTransactionQuery
|
||||
extends PhabricatorApplicationTransactionQuery {
|
||||
|
||||
public function getTemplateApplicationTransaction() {
|
||||
return new PhameBlogTransaction();
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ final class PhameBlog extends PhameDAO
|
|||
protected $viewPolicy;
|
||||
protected $editPolicy;
|
||||
protected $joinPolicy;
|
||||
protected $mailKey;
|
||||
|
||||
private static $requestBlog;
|
||||
|
||||
|
@ -34,6 +35,7 @@ final class PhameBlog extends PhameDAO
|
|||
'name' => 'text64',
|
||||
'description' => 'text',
|
||||
'domain' => 'text128?',
|
||||
'mailKey' => 'bytes20',
|
||||
|
||||
// T6203/NULLABILITY
|
||||
// These policies should always be non-null.
|
||||
|
@ -55,6 +57,13 @@ final class PhameBlog extends PhameDAO
|
|||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if (!$this->getMailKey()) {
|
||||
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
||||
}
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPhameBlogPHIDType::TYPECONST);
|
||||
|
@ -214,6 +223,11 @@ final class PhameBlog extends PhameDAO
|
|||
return $base;
|
||||
}
|
||||
|
||||
public function getViewURI() {
|
||||
$uri = '/phame/blog/view/'.$this->getID().'/';
|
||||
return PhabricatorEnv::getProductionURI($uri);
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */
|
||||
|
||||
|
|
|
@ -8,6 +8,10 @@ final class PhameBlogTransaction
|
|||
const TYPE_DOMAIN = 'phame.blog.domain';
|
||||
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() {
|
||||
return 'phame';
|
||||
}
|
||||
|
@ -44,6 +48,26 @@ final class PhameBlogTransaction
|
|||
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() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
$object_phid = $this->getObjectPHID();
|
||||
|
@ -53,7 +77,7 @@ final class PhameBlogTransaction
|
|||
|
||||
$type = $this->getTransactionType();
|
||||
switch ($type) {
|
||||
case self:TYPE_NAME:
|
||||
case self::TYPE_NAME:
|
||||
if ($old === null) {
|
||||
return pht(
|
||||
'%s created this blog.',
|
||||
|
|
Loading…
Reference in a new issue