From c3ecea9788c1fdc2656b485e84ed933d08ae64d5 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Sun, 8 Nov 2015 07:50:01 -0800 Subject: [PATCH] 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 --- .../20151107.phame.blog.mailkey.1.sql | 2 + .../20151107.phame.blog.mailkey.2.php | 18 ++++++ src/__phutil_library_map__.php | 4 ++ .../phame/editor/PhameBlogEditor.php | 55 ++++++++++++++++++- .../phame/mail/PhameBlogReplyHandler.php | 21 +++++++ .../phame/query/PhameBlogTransactionQuery.php | 10 ++++ src/applications/phame/storage/PhameBlog.php | 14 +++++ .../phame/storage/PhameBlogTransaction.php | 26 ++++++++- 8 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 resources/sql/autopatches/20151107.phame.blog.mailkey.1.sql create mode 100644 resources/sql/autopatches/20151107.phame.blog.mailkey.2.php create mode 100644 src/applications/phame/mail/PhameBlogReplyHandler.php create mode 100644 src/applications/phame/query/PhameBlogTransactionQuery.php diff --git a/resources/sql/autopatches/20151107.phame.blog.mailkey.1.sql b/resources/sql/autopatches/20151107.phame.blog.mailkey.1.sql new file mode 100644 index 0000000000..764f50766c --- /dev/null +++ b/resources/sql/autopatches/20151107.phame.blog.mailkey.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_phame.phame_blog + ADD mailKey binary(20) NOT NULL; diff --git a/resources/sql/autopatches/20151107.phame.blog.mailkey.2.php b/resources/sql/autopatches/20151107.phame.blog.mailkey.2.php new file mode 100644 index 0000000000..c6f316aa47 --- /dev/null +++ b/resources/sql/autopatches/20151107.phame.blog.mailkey.2.php @@ -0,0 +1,18 @@ +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); +} diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 65fab9c53b..b9b654a572 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/phame/editor/PhameBlogEditor.php b/src/applications/phame/editor/PhameBlogEditor.php index a44bec422b..7c793aff63 100644 --- a/src/applications/phame/editor/PhameBlogEditor.php +++ b/src/applications/phame/editor/PhameBlogEditor.php @@ -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; } diff --git a/src/applications/phame/mail/PhameBlogReplyHandler.php b/src/applications/phame/mail/PhameBlogReplyHandler.php new file mode 100644 index 0000000000..a6e245709e --- /dev/null +++ b/src/applications/phame/mail/PhameBlogReplyHandler.php @@ -0,0 +1,21 @@ + '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 )-------------------------- */ diff --git a/src/applications/phame/storage/PhameBlogTransaction.php b/src/applications/phame/storage/PhameBlogTransaction.php index f1e558e240..0954e72a37 100644 --- a/src/applications/phame/storage/PhameBlogTransaction.php +++ b/src/applications/phame/storage/PhameBlogTransaction.php @@ -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.',