From 58f0f37873104236bb813ef322b002be9bc7801b Mon Sep 17 00:00:00 2001 From: Edward Speyer Date: Wed, 8 May 2013 10:38:07 +0100 Subject: [PATCH] Add mail keys to ReleephRequests Summary: Adding mail-keys; required for `PhabricatorApplicationTransaction` support. Test Plan: Upgrade an old database with this patch, observe the matrix: {F42620} Reviewers: wez, epriestley Reviewed By: epriestley CC: epriestley, aran Maniphest Tasks: T2720 Differential Revision: https://secure.phabricator.com/D5852 --- .../sql/patches/20130507.releephrqmailkey.sql | 2 ++ .../patches/20130507.releephrqmailkeypop.php | 27 +++++++++++++++++++ .../releeph/storage/ReleephRequest.php | 8 ++++++ .../patch/PhabricatorBuiltinPatchList.php | 8 ++++++ 4 files changed, 45 insertions(+) create mode 100644 resources/sql/patches/20130507.releephrqmailkey.sql create mode 100644 resources/sql/patches/20130507.releephrqmailkeypop.php diff --git a/resources/sql/patches/20130507.releephrqmailkey.sql b/resources/sql/patches/20130507.releephrqmailkey.sql new file mode 100644 index 0000000000..154a2cb22a --- /dev/null +++ b/resources/sql/patches/20130507.releephrqmailkey.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_releeph.releeph_request + ADD COLUMN `mailKey` varchar(20) NOT NULL; diff --git a/resources/sql/patches/20130507.releephrqmailkeypop.php b/resources/sql/patches/20130507.releephrqmailkeypop.php new file mode 100644 index 0000000000..49c1bc6495 --- /dev/null +++ b/resources/sql/patches/20130507.releephrqmailkeypop.php @@ -0,0 +1,27 @@ +openTransaction(); + +// From ponder-mailkey-populate.php... +foreach (new LiskMigrationIterator($table) as $rq) { + $id = $rq->getID(); + + echo "RQ{$id}: "; + if (!$rq->getMailKey()) { + queryfx( + $rq->establishConnection('w'), + 'UPDATE %T SET mailKey = %s WHERE id = %d', + $rq->getTableName(), + Filesystem::readRandomCharacters(20), + $id); + echo("Generated Key\n"); + } else { + echo "-\n"; + } +} + +$table->saveTransaction(); +echo "Done.\n"; diff --git a/src/applications/releeph/storage/ReleephRequest.php b/src/applications/releeph/storage/ReleephRequest.php index 67ab8d79d2..28505ad25d 100644 --- a/src/applications/releeph/storage/ReleephRequest.php +++ b/src/applications/releeph/storage/ReleephRequest.php @@ -9,6 +9,7 @@ final class ReleephRequest extends ReleephDAO { protected $userIntents = array(); protected $inBranch; protected $pickStatus; + protected $mailKey; // Information about the thing being requested protected $requestCommitPHID; @@ -153,6 +154,13 @@ final class ReleephRequest extends ReleephDAO { ReleephPHIDConstants::PHID_TYPE_RERQ); } + public function save() { + if (!$this->getMailKey()) { + $this->setMailKey(Filesystem::readRandomCharacters(20)); + } + return parent::save(); + } + /* -( Helpful accessors )--------------------------------------------------- */ diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php index c17ffd3d26..a86f8845eb 100644 --- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php @@ -1274,6 +1274,14 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'sql', 'name' => $this->getPatchPath('20130507.releephrqsimplifycols.sql'), ), + '20130507.releephrqmailkey.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('20130507.releephrqmailkey.sql'), + ), + '20130507.releephrqmailkeypop.php' => array( + 'type' => 'php', + 'name' => $this->getPatchPath('20130507.releephrqmailkeypop.php'), + ), ); } }