From 4e7b5defc300b6af060277a35c956c5c745c00cd Mon Sep 17 00:00:00 2001 From: Chad Little Date: Tue, 4 Aug 2015 10:49:15 -0700 Subject: [PATCH] Add mailKeys to Ponder Answer Summary: Ref T3846. Adds mailkey generation and migration. Test Plan: Ran the migration, see keys in mysql. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T3846 Differential Revision: https://secure.phabricator.com/D13785 --- .../20150804.ponder.answer.mailkey.1.sql | 2 ++ .../20150804.ponder.answer.mailkey.2.php | 18 ++++++++++++++++++ .../ponder/storage/PonderAnswer.php | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 resources/sql/autopatches/20150804.ponder.answer.mailkey.1.sql create mode 100644 resources/sql/autopatches/20150804.ponder.answer.mailkey.2.php diff --git a/resources/sql/autopatches/20150804.ponder.answer.mailkey.1.sql b/resources/sql/autopatches/20150804.ponder.answer.mailkey.1.sql new file mode 100644 index 0000000000..63ba3494f9 --- /dev/null +++ b/resources/sql/autopatches/20150804.ponder.answer.mailkey.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_ponder.ponder_answer + ADD mailKey binary(20) NOT NULL; diff --git a/resources/sql/autopatches/20150804.ponder.answer.mailkey.2.php b/resources/sql/autopatches/20150804.ponder.answer.mailkey.2.php new file mode 100644 index 0000000000..e643a5dab5 --- /dev/null +++ b/resources/sql/autopatches/20150804.ponder.answer.mailkey.2.php @@ -0,0 +1,18 @@ +establishConnection('w'); +$iterator = new LiskMigrationIterator($table); +foreach ($iterator as $answer) { + $id = $answer->getID(); + + echo pht('Adding mail key for Answer %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/applications/ponder/storage/PonderAnswer.php b/src/applications/ponder/storage/PonderAnswer.php index 57e0e2ea21..10ada70c5e 100644 --- a/src/applications/ponder/storage/PonderAnswer.php +++ b/src/applications/ponder/storage/PonderAnswer.php @@ -18,6 +18,7 @@ final class PonderAnswer extends PonderDAO protected $content; protected $contentSource; + protected $mailKey; protected $voteCount; private $vote; @@ -71,6 +72,7 @@ final class PonderAnswer extends PonderDAO self::CONFIG_COLUMN_SCHEMA => array( 'voteCount' => 'sint32', 'content' => 'text', + 'mailKey' => 'bytes20', // T6203/NULLABILITY // This should always exist. @@ -113,6 +115,13 @@ final class PonderAnswer extends PonderDAO return self::MARKUP_FIELD_CONTENT; } + public function save() { + if (!$this->getMailKey()) { + $this->setMailKey(Filesystem::readRandomCharacters(20)); + } + return parent::save(); + } + /* -( PhabricatorApplicationTransactionInterface )------------------------- */