From b1533e5468b1d4a9486a1113c5469050697e49fc Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 25 May 2022 17:07:37 -0700 Subject: [PATCH] Migrate "SlowvotePoll" to modern mailkey storage Summary: Ref T13682. Ref T13065. Migrate and update "SlowvotePoll" to use more modern mailkey storage (in the mail application, rather than onboard). Also make other minor modernization changes. Test Plan: Created a new poll. Ran migration, verified mail key copied properly in database. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13682, T13065 Differential Revision: https://secure.phabricator.com/D21842 --- .../20220525.slowvote.01.mailkey.php | 28 +++++++++++++++++++ .../20220525.slowvote.02.mailkey-drop.sql | 2 ++ .../storage/PhabricatorSlowvotePoll.php | 17 +++-------- 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 resources/sql/autopatches/20220525.slowvote.01.mailkey.php create mode 100644 resources/sql/autopatches/20220525.slowvote.02.mailkey-drop.sql diff --git a/resources/sql/autopatches/20220525.slowvote.01.mailkey.php b/resources/sql/autopatches/20220525.slowvote.01.mailkey.php new file mode 100644 index 0000000000..ed0355e105 --- /dev/null +++ b/resources/sql/autopatches/20220525.slowvote.01.mailkey.php @@ -0,0 +1,28 @@ +establishConnection('w'); + +$properties_table = new PhabricatorMetaMTAMailProperties(); +$conn = $properties_table->establishConnection('w'); + +$iterator = new LiskRawMigrationIterator( + $poll_conn, + $poll_table->getTableName()); + +foreach ($iterator as $row) { + queryfx( + $conn, + 'INSERT IGNORE INTO %R + (objectPHID, mailProperties, dateCreated, dateModified) + VALUES + (%s, %s, %d, %d)', + $properties_table, + $row['phid'], + phutil_json_encode( + array( + 'mailKey' => $row['mailKey'], + )), + PhabricatorTime::getNow(), + PhabricatorTime::getNow()); +} diff --git a/resources/sql/autopatches/20220525.slowvote.02.mailkey-drop.sql b/resources/sql/autopatches/20220525.slowvote.02.mailkey-drop.sql new file mode 100644 index 0000000000..54e65fd14c --- /dev/null +++ b/resources/sql/autopatches/20220525.slowvote.02.mailkey-drop.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll + DROP mailKey; diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php index 78e136762f..a78e030dc6 100644 --- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php +++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php @@ -1,6 +1,7 @@ 'uint32', 'description' => 'text', 'isClosed' => 'bool', - 'mailKey' => 'bytes20', ), self::CONFIG_KEY_SCHEMA => array( ), ) + parent::getConfiguration(); } - public function generatePHID() { - return PhabricatorPHID::generateNewPHID( - PhabricatorSlowvotePollPHIDType::TYPECONST); + public function getPHIDType() { + return PhabricatorSlowvotePollPHIDType::TYPECONST; } public function getOptions() { @@ -112,13 +110,6 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO return '/'.$this->getMonogram(); } - public function save() { - if (!$this->getMailKey()) { - $this->setMailKey(Filesystem::readRandomCharacters(20)); - } - return parent::save(); - } - /* -( PhabricatorApplicationTransactionInterface )------------------------- */