From 89dcf9792a0ab575805941f97e0c2d88821d746e Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 14 Nov 2019 11:24:22 -0800 Subject: [PATCH] Give "PhabricatorUserEmail" a PHID Summary: Ref T13444. To interact meaningfully with "DestructionEngine", objects need a PHID. The "UserEmail" object currently does not have one (or a real "Query"). Provide basic PHID support so "DestructionEngine" can interact with the object more powerfully. Test Plan: - Ran migrations, checked data in database, saw sensible PHIDs assigned. - Added a new email address to my account, saw it get a PHID. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13444 Differential Revision: https://secure.phabricator.com/D20913 --- .../autopatches/20191114.email.01.phid.sql | 2 + .../20191114.email.02.populate.php | 18 ++++++ src/__phutil_library_map__.php | 4 ++ .../PhabricatorPeopleUserEmailPHIDType.php | 35 ++++++++++++ .../query/PhabricatorPeopleUserEmailQuery.php | 55 +++++++++++++++++++ .../people/storage/PhabricatorUserEmail.php | 5 ++ 6 files changed, 119 insertions(+) create mode 100644 resources/sql/autopatches/20191114.email.01.phid.sql create mode 100644 resources/sql/autopatches/20191114.email.02.populate.php create mode 100644 src/applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php create mode 100644 src/applications/people/query/PhabricatorPeopleUserEmailQuery.php diff --git a/resources/sql/autopatches/20191114.email.01.phid.sql b/resources/sql/autopatches/20191114.email.01.phid.sql new file mode 100644 index 0000000000..3851d6e0ec --- /dev/null +++ b/resources/sql/autopatches/20191114.email.01.phid.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_user.user_email + ADD phid VARBINARY(64) NOT NULL; diff --git a/resources/sql/autopatches/20191114.email.02.populate.php b/resources/sql/autopatches/20191114.email.02.populate.php new file mode 100644 index 0000000000..96ef13ea58 --- /dev/null +++ b/resources/sql/autopatches/20191114.email.02.populate.php @@ -0,0 +1,18 @@ +establishConnection('w'); + +$iterator = new LiskRawMigrationIterator($conn, $table->getTableName()); +foreach ($iterator as $row) { + $phid = $row['phid']; + + if (!strlen($phid)) { + queryfx( + $conn, + 'UPDATE %R SET phid = %s WHERE id = %d', + $table, + $table->generatePHID(), + $row['id']); + } +} diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ffb824f177..30627e8b59 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4121,6 +4121,8 @@ phutil_register_library_map(array( 'PhabricatorPeopleTasksProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php', 'PhabricatorPeopleTestDataGenerator' => 'applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php', 'PhabricatorPeopleTransactionQuery' => 'applications/people/query/PhabricatorPeopleTransactionQuery.php', + 'PhabricatorPeopleUserEmailPHIDType' => 'applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php', + 'PhabricatorPeopleUserEmailQuery' => 'applications/people/query/PhabricatorPeopleUserEmailQuery.php', 'PhabricatorPeopleUserFunctionDatasource' => 'applications/people/typeahead/PhabricatorPeopleUserFunctionDatasource.php', 'PhabricatorPeopleUserPHIDType' => 'applications/people/phid/PhabricatorPeopleUserPHIDType.php', 'PhabricatorPeopleUsernameMailEngine' => 'applications/people/mail/PhabricatorPeopleUsernameMailEngine.php', @@ -10617,6 +10619,8 @@ phutil_register_library_map(array( 'PhabricatorPeopleTasksProfileMenuItem' => 'PhabricatorProfileMenuItem', 'PhabricatorPeopleTestDataGenerator' => 'PhabricatorTestDataGenerator', 'PhabricatorPeopleTransactionQuery' => 'PhabricatorApplicationTransactionQuery', + 'PhabricatorPeopleUserEmailPHIDType' => 'PhabricatorPHIDType', + 'PhabricatorPeopleUserEmailQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorPeopleUserFunctionDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorPeopleUserPHIDType' => 'PhabricatorPHIDType', 'PhabricatorPeopleUsernameMailEngine' => 'PhabricatorPeopleMailEngine', diff --git a/src/applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php b/src/applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php new file mode 100644 index 0000000000..0aadc149f6 --- /dev/null +++ b/src/applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php @@ -0,0 +1,35 @@ +withPHIDs($phids); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + return null; + } + +} diff --git a/src/applications/people/query/PhabricatorPeopleUserEmailQuery.php b/src/applications/people/query/PhabricatorPeopleUserEmailQuery.php new file mode 100644 index 0000000000..f0330f34f9 --- /dev/null +++ b/src/applications/people/query/PhabricatorPeopleUserEmailQuery.php @@ -0,0 +1,55 @@ +ids = $ids; + return $this; + } + + public function withPHIDs(array $phids) { + $this->phids = $phids; + return $this; + } + + public function newResultObject() { + return new PhabricatorUserEmail(); + } + + protected function loadPage() { + return $this->loadStandardPage($this->newResultObject()); + } + + protected function getPrimaryTableAlias() { + return 'email'; + } + + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); + + if ($this->ids !== null) { + $where[] = qsprintf( + $conn, + 'email.id IN (%Ld)', + $this->ids); + } + + if ($this->phids !== null) { + $where[] = qsprintf( + $conn, + 'email.phid IN (%Ls)', + $this->phids); + } + + return $where; + } + + public function getQueryApplicationClass() { + return 'PhabricatorPeopleApplication'; + } + +} diff --git a/src/applications/people/storage/PhabricatorUserEmail.php b/src/applications/people/storage/PhabricatorUserEmail.php index f626e8f133..cf2c61dc03 100644 --- a/src/applications/people/storage/PhabricatorUserEmail.php +++ b/src/applications/people/storage/PhabricatorUserEmail.php @@ -18,6 +18,7 @@ final class PhabricatorUserEmail protected function getConfiguration() { return array( + self::CONFIG_AUX_PHID => true, self::CONFIG_COLUMN_SCHEMA => array( 'address' => 'sort128', 'isVerified' => 'bool', @@ -36,6 +37,10 @@ final class PhabricatorUserEmail ) + parent::getConfiguration(); } + public function getPHIDType() { + return PhabricatorPeopleUserEmailPHIDType::TYPECONST; + } + public function getVerificationURI() { return '/emailverify/'.$this->getVerificationCode().'/'; }