From 2532cb9613586e21eaac1f5ff56d5caff716dd96 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 8 Oct 2012 20:14:58 -0700 Subject: [PATCH] Add mail keys to Ponder questions Summary: We need to go slightly farther to stub reply handler functionality for Ponder in at least some configurations, where we rely on the presence of a unique random key to generate per-object or per-object+user reply addresses. This should probably be formalized in an interface since it's currently pretty ad-hoc. Test Plan: - Made comments in Ponder under a per-user email configuration. - Ran migration, verified mail keys were generated. - Ran migration again (with --apply), verified existing questions were skipped. - Created a new question, verified mail key generation. Reviewers: pieter Reviewed By: pieter CC: aran Maniphest Tasks: T1873 Differential Revision: https://secure.phabricator.com/D3665 --- .../sql/patches/ponder-mailkey-populate.php | 37 +++++++++++++++++++ resources/sql/patches/ponder-mailkey.sql | 2 + src/applications/ponder/mail/PonderMail.php | 1 + .../ponder/storage/PonderQuestion.php | 9 +++++ .../patch/PhabricatorBuiltinPatchList.php | 9 ++++- 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 resources/sql/patches/ponder-mailkey-populate.php create mode 100644 resources/sql/patches/ponder-mailkey.sql diff --git a/resources/sql/patches/ponder-mailkey-populate.php b/resources/sql/patches/ponder-mailkey-populate.php new file mode 100644 index 0000000000..549ae093ae --- /dev/null +++ b/resources/sql/patches/ponder-mailkey-populate.php @@ -0,0 +1,37 @@ +getID(); + + echo "Question {$id}: "; + if (!$question->getMailKey()) { + queryfx( + $question->establishConnection('w'), + 'UPDATE %T SET mailKey = %s WHERE id = %d', + $question->getTableName(), + Filesystem::readRandomCharacters(20), + $id); + echo "Generated Key\n"; + } else { + echo "-\n"; + } +} + +echo "Done.\n"; diff --git a/resources/sql/patches/ponder-mailkey.sql b/resources/sql/patches/ponder-mailkey.sql new file mode 100644 index 0000000000..611647d119 --- /dev/null +++ b/resources/sql/patches/ponder-mailkey.sql @@ -0,0 +1,2 @@ +ALTER TABLE `{$NAMESPACE}_ponder`.ponder_question + ADD mailKey VARCHAR(20) NOT NULL COLLATE utf8_bin; diff --git a/src/applications/ponder/mail/PonderMail.php b/src/applications/ponder/mail/PonderMail.php index 38348ddc8d..d9f10d2333 100644 --- a/src/applications/ponder/mail/PonderMail.php +++ b/src/applications/ponder/mail/PonderMail.php @@ -106,6 +106,7 @@ abstract class PonderMail { ->loadHandles(); $reply_handler = new PonderReplyHandler(); + $reply_handler->setMailReceiver($question); $body = new PhabricatorMetaMTAMailBody(); $body->addRawSection($this->renderBody()); diff --git a/src/applications/ponder/storage/PonderQuestion.php b/src/applications/ponder/storage/PonderQuestion.php index d82132b4ea..3e5878e9a3 100644 --- a/src/applications/ponder/storage/PonderQuestion.php +++ b/src/applications/ponder/storage/PonderQuestion.php @@ -34,6 +34,7 @@ final class PonderQuestion extends PonderDAO protected $voteCount; protected $answerCount; protected $heat; + protected $mailKey; private $answers; private $vote; @@ -175,4 +176,12 @@ final class PonderQuestion extends PonderDAO public function isAutomaticallySubscribed($phid) { return false; } + + public function save() { + if (!$this->getMailKey()) { + $this->setMailKey(Filesystem::readRandomCharacters(20)); + } + return parent::save(); + } + } diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php index 561023fbb1..b7406f2b11 100644 --- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php @@ -996,7 +996,14 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'sql', 'name' => $this->getPatchPath('phamedomain.sql'), ), - + 'ponder-mailkey.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('ponder-mailkey.sql'), + ), + 'ponder-mailkey-populate.php' => array( + 'type' => 'php', + 'name' => $this->getPatchPath('ponder-mailkey-populate.php'), + ), ); }