From 7c0e33c34d6f7c49f7e4c5cad86e90af09333fee Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 16 Mar 2021 15:04:07 -0700 Subject: [PATCH] Modernize "mailKey" for Almanac Bindings Summary: Ref T13065. Ref T13641. Migrate "mailKey" and drop the column. Test Plan: Ran "bin/storage upgrade", got a clean report and saw binding mail keys in the mail properties table. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13641, T13065 Differential Revision: https://secure.phabricator.com/D21630 --- .../20210316.almanac.07.binding-mailkey.php | 28 +++++++++++++++++++ ...0210316.almanac.08.binding-dropmailkey.sql | 2 ++ .../almanac/storage/AlmanacBinding.php | 17 ++++------- 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 resources/sql/autopatches/20210316.almanac.07.binding-mailkey.php create mode 100644 resources/sql/autopatches/20210316.almanac.08.binding-dropmailkey.sql diff --git a/resources/sql/autopatches/20210316.almanac.07.binding-mailkey.php b/resources/sql/autopatches/20210316.almanac.07.binding-mailkey.php new file mode 100644 index 0000000000..84c1725876 --- /dev/null +++ b/resources/sql/autopatches/20210316.almanac.07.binding-mailkey.php @@ -0,0 +1,28 @@ +establishConnection('w'); + +$properties_table = new PhabricatorMetaMTAMailProperties(); +$conn = $properties_table->establishConnection('w'); + +$iterator = new LiskRawMigrationIterator( + $binding_conn, + $binding_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/20210316.almanac.08.binding-dropmailkey.sql b/resources/sql/autopatches/20210316.almanac.08.binding-dropmailkey.sql new file mode 100644 index 0000000000..ebcf31254d --- /dev/null +++ b/resources/sql/autopatches/20210316.almanac.08.binding-dropmailkey.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_almanac.almanac_binding + DROP mailKey; diff --git a/src/applications/almanac/storage/AlmanacBinding.php b/src/applications/almanac/storage/AlmanacBinding.php index a7096fc51f..011a085151 100644 --- a/src/applications/almanac/storage/AlmanacBinding.php +++ b/src/applications/almanac/storage/AlmanacBinding.php @@ -13,7 +13,6 @@ final class AlmanacBinding protected $servicePHID; protected $devicePHID; protected $interfacePHID; - protected $mailKey; protected $isDisabled; private $service = self::ATTACHABLE; @@ -33,7 +32,6 @@ final class AlmanacBinding return array( self::CONFIG_AUX_PHID => true, self::CONFIG_COLUMN_SCHEMA => array( - 'mailKey' => 'bytes20', 'isDisabled' => 'bool', ), self::CONFIG_KEY_SCHEMA => array( @@ -51,15 +49,8 @@ final class AlmanacBinding ) + parent::getConfiguration(); } - public function generatePHID() { - return PhabricatorPHID::generateNewPHID(AlmanacBindingPHIDType::TYPECONST); - } - - public function save() { - if (!$this->mailKey) { - $this->mailKey = Filesystem::readRandomCharacters(20); - } - return parent::save(); + public function getPHIDType() { + return AlmanacBindingPHIDType::TYPECONST; } public function getName() { @@ -67,7 +58,9 @@ final class AlmanacBinding } public function getURI() { - return '/almanac/binding/'.$this->getID().'/'; + return urisprintf( + '/almanac/binding/%s/', + $this->getID()); } public function getService() { -- 2.51.2