From a962aeaf85af471b2c8887294da45772bba487b8 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Sat, 25 Jul 2015 15:47:07 -0700 Subject: [PATCH] Add mailKeys to Countdown Summary: Adds mailkeys and reply handler support Test Plan: Edit Countdown, New Countdown, no errors. Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D13713 --- .../20150725.countdown.mailkey.1.sql | 2 ++ .../20150725.countdown.mailkey.2.php | 18 ++++++++++++ src/__phutil_library_map__.php | 2 ++ .../editor/PhabricatorCountdownEditor.php | 7 +++++ .../mail/PhabricatorCountdownMailReceiver.php | 28 +++++++++++++++++++ .../storage/PhabricatorCountdown.php | 10 ++++++- 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 resources/sql/autopatches/20150725.countdown.mailkey.1.sql create mode 100644 resources/sql/autopatches/20150725.countdown.mailkey.2.php create mode 100644 src/applications/countdown/mail/PhabricatorCountdownMailReceiver.php diff --git a/resources/sql/autopatches/20150725.countdown.mailkey.1.sql b/resources/sql/autopatches/20150725.countdown.mailkey.1.sql new file mode 100644 index 0000000000..c53441e1cb --- /dev/null +++ b/resources/sql/autopatches/20150725.countdown.mailkey.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_countdown.countdown + ADD mailKey binary(20) NOT NULL; diff --git a/resources/sql/autopatches/20150725.countdown.mailkey.2.php b/resources/sql/autopatches/20150725.countdown.mailkey.2.php new file mode 100644 index 0000000000..c07a763942 --- /dev/null +++ b/resources/sql/autopatches/20150725.countdown.mailkey.2.php @@ -0,0 +1,18 @@ +establishConnection('w'); +$iterator = new LiskMigrationIterator($table); +foreach ($iterator as $countdown) { + $id = $countdown->getID(); + + echo pht('Adding mail key for countdown %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 7fed06cd35..1ec46fffa7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1832,6 +1832,7 @@ phutil_register_library_map(array( 'PhabricatorCountdownEditController' => 'applications/countdown/controller/PhabricatorCountdownEditController.php', 'PhabricatorCountdownEditor' => 'applications/countdown/editor/PhabricatorCountdownEditor.php', 'PhabricatorCountdownListController' => 'applications/countdown/controller/PhabricatorCountdownListController.php', + 'PhabricatorCountdownMailReceiver' => 'applications/countdown/mail/PhabricatorCountdownMailReceiver.php', 'PhabricatorCountdownQuery' => 'applications/countdown/query/PhabricatorCountdownQuery.php', 'PhabricatorCountdownRemarkupRule' => 'applications/countdown/remarkup/PhabricatorCountdownRemarkupRule.php', 'PhabricatorCountdownReplyHandler' => 'applications/countdown/mail/PhabricatorCountdownReplyHandler.php', @@ -5648,6 +5649,7 @@ phutil_register_library_map(array( 'PhabricatorCountdownEditController' => 'PhabricatorCountdownController', 'PhabricatorCountdownEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorCountdownListController' => 'PhabricatorCountdownController', + 'PhabricatorCountdownMailReceiver' => 'PhabricatorObjectMailReceiver', 'PhabricatorCountdownQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorCountdownRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'PhabricatorCountdownReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', diff --git a/src/applications/countdown/editor/PhabricatorCountdownEditor.php b/src/applications/countdown/editor/PhabricatorCountdownEditor.php index 7438e4ac02..05c5bbb7de 100644 --- a/src/applications/countdown/editor/PhabricatorCountdownEditor.php +++ b/src/applications/countdown/editor/PhabricatorCountdownEditor.php @@ -172,6 +172,13 @@ final class PhabricatorCountdownEditor array $xactions) { $body = parent::buildMailBody($object, $xactions); + $description = $object->getDescription(); + + if (strlen($description)) { + $body->addTextSection( + pht('COUNTDOWN DESCRIPTION'), + $object->getDescription()); + } $body->addLinkSection( pht('COUNTDOWN DETAIL'), diff --git a/src/applications/countdown/mail/PhabricatorCountdownMailReceiver.php b/src/applications/countdown/mail/PhabricatorCountdownMailReceiver.php new file mode 100644 index 0000000000..d0218de59b --- /dev/null +++ b/src/applications/countdown/mail/PhabricatorCountdownMailReceiver.php @@ -0,0 +1,28 @@ +setViewer($viewer) + ->withIDs(array($id)) + ->executeOne(); + } + + protected function getTransactionReplyHandler() { + return new PhabricatorCountdownReplyHandler(); + } + +} diff --git a/src/applications/countdown/storage/PhabricatorCountdown.php b/src/applications/countdown/storage/PhabricatorCountdown.php index 01fd5d2509..8753c66223 100644 --- a/src/applications/countdown/storage/PhabricatorCountdown.php +++ b/src/applications/countdown/storage/PhabricatorCountdown.php @@ -16,7 +16,7 @@ final class PhabricatorCountdown extends PhabricatorCountdownDAO protected $description; protected $viewPolicy; protected $editPolicy; - + protected $mailKey; protected $spacePHID; public static function initializeNewCountdown(PhabricatorUser $actor) { @@ -41,6 +41,7 @@ final class PhabricatorCountdown extends PhabricatorCountdownDAO self::CONFIG_COLUMN_SCHEMA => array( 'title' => 'text255', 'description' => 'text', + 'mailKey' => 'bytes20', ), ) + parent::getConfiguration(); } @@ -54,6 +55,13 @@ final class PhabricatorCountdown extends PhabricatorCountdownDAO return 'C'.$this->getID(); } + public function save() { + if (!$this->getMailKey()) { + $this->setMailKey(Filesystem::readRandomCharacters(20)); + } + return parent::save(); + } + /* -( PhabricatorSubscribableInterface )----------------------------------- */