From dc510354c339209c4da1ee25eea126b1881c8b64 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 4 May 2018 13:41:03 -0700 Subject: [PATCH] Remove explicit "mailKey" from Owners packages Summary: Depends on D19426. Ref T13130. Ref T13065. While I'm making changes to Owners for "Ignore generated paths", clean up the "mailKey" column. We recently (D19399) added code to automatically generate and manage mail keys so we don't need a ton of `mailKey` properties in the future. Migrate existing mail keys and blow away the explicit column on packages. Test Plan: Ran migration, manually looked at the database and saw sensible data. Edited a package to send some mail, which looked good. Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13130, T13065 Differential Revision: https://secure.phabricator.com/D19427 --- .../20180504.owners.01.mailkey.php | 26 +++++++++++++++++++ .../autopatches/20180504.owners.02.rmkey.sql | 2 ++ .../storage/PhabricatorOwnersPackage.php | 15 ++--------- 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 resources/sql/autopatches/20180504.owners.01.mailkey.php create mode 100644 resources/sql/autopatches/20180504.owners.02.rmkey.sql diff --git a/resources/sql/autopatches/20180504.owners.01.mailkey.php b/resources/sql/autopatches/20180504.owners.01.mailkey.php new file mode 100644 index 0000000000..c1b5550f9f --- /dev/null +++ b/resources/sql/autopatches/20180504.owners.01.mailkey.php @@ -0,0 +1,26 @@ +establishConnection('w'); +$packages_name = $packages_table->getTableName(); + +$properties_table = new PhabricatorMetaMTAMailProperties(); +$conn = $properties_table->establishConnection('w'); + +$iterator = new LiskRawMigrationIterator($packages_conn, $packages_name); +foreach ($iterator as $package) { + queryfx( + $conn, + 'INSERT IGNORE INTO %T + (objectPHID, mailProperties, dateCreated, dateModified) + VALUES + (%s, %s, %d, %d)', + $properties_table->getTableName(), + $package['phid'], + phutil_json_encode( + array( + 'mailKey' => $package['mailKey'], + )), + PhabricatorTime::getNow(), + PhabricatorTime::getNow()); +} diff --git a/resources/sql/autopatches/20180504.owners.02.rmkey.sql b/resources/sql/autopatches/20180504.owners.02.rmkey.sql new file mode 100644 index 0000000000..5b8f240307 --- /dev/null +++ b/resources/sql/autopatches/20180504.owners.02.rmkey.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_owners.owners_package + DROP mailKey; diff --git a/src/applications/owners/storage/PhabricatorOwnersPackage.php b/src/applications/owners/storage/PhabricatorOwnersPackage.php index 5e856190ec..37ded17f1b 100644 --- a/src/applications/owners/storage/PhabricatorOwnersPackage.php +++ b/src/applications/owners/storage/PhabricatorOwnersPackage.php @@ -16,7 +16,6 @@ final class PhabricatorOwnersPackage protected $auditingEnabled; protected $autoReview; protected $description; - protected $mailKey; protected $status; protected $viewPolicy; protected $editPolicy; @@ -122,7 +121,6 @@ final class PhabricatorOwnersPackage 'name' => 'sort', 'description' => 'text', 'auditingEnabled' => 'bool', - 'mailKey' => 'bytes20', 'status' => 'text32', 'autoReview' => 'text32', 'dominion' => 'text32', @@ -130,17 +128,8 @@ final class PhabricatorOwnersPackage ) + parent::getConfiguration(); } - public function generatePHID() { - return PhabricatorPHID::generateNewPHID( - PhabricatorOwnersPackagePHIDType::TYPECONST); - } - - public function save() { - if (!$this->getMailKey()) { - $this->setMailKey(Filesystem::readRandomCharacters(20)); - } - - return parent::save(); + public function getPHIDType() { + return PhabricatorOwnersPackagePHIDType::TYPECONST; } public function isArchived() {