@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+119
+2
resources/sql/autopatches/20191114.email.01.phid.sql
··· 1 + ALTER TABLE {$NAMESPACE}_user.user_email 2 + ADD phid VARBINARY(64) NOT NULL;
+18
resources/sql/autopatches/20191114.email.02.populate.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorUserEmail(); 4 + $conn = $table->establishConnection('w'); 5 + 6 + $iterator = new LiskRawMigrationIterator($conn, $table->getTableName()); 7 + foreach ($iterator as $row) { 8 + $phid = $row['phid']; 9 + 10 + if (!strlen($phid)) { 11 + queryfx( 12 + $conn, 13 + 'UPDATE %R SET phid = %s WHERE id = %d', 14 + $table, 15 + $table->generatePHID(), 16 + $row['id']); 17 + } 18 + }
+4
src/__phutil_library_map__.php
··· 4121 4121 'PhabricatorPeopleTasksProfileMenuItem' => 'applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php', 4122 4122 'PhabricatorPeopleTestDataGenerator' => 'applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php', 4123 4123 'PhabricatorPeopleTransactionQuery' => 'applications/people/query/PhabricatorPeopleTransactionQuery.php', 4124 + 'PhabricatorPeopleUserEmailPHIDType' => 'applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php', 4125 + 'PhabricatorPeopleUserEmailQuery' => 'applications/people/query/PhabricatorPeopleUserEmailQuery.php', 4124 4126 'PhabricatorPeopleUserFunctionDatasource' => 'applications/people/typeahead/PhabricatorPeopleUserFunctionDatasource.php', 4125 4127 'PhabricatorPeopleUserPHIDType' => 'applications/people/phid/PhabricatorPeopleUserPHIDType.php', 4126 4128 'PhabricatorPeopleUsernameMailEngine' => 'applications/people/mail/PhabricatorPeopleUsernameMailEngine.php', ··· 10617 10619 'PhabricatorPeopleTasksProfileMenuItem' => 'PhabricatorProfileMenuItem', 10618 10620 'PhabricatorPeopleTestDataGenerator' => 'PhabricatorTestDataGenerator', 10619 10621 'PhabricatorPeopleTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 10622 + 'PhabricatorPeopleUserEmailPHIDType' => 'PhabricatorPHIDType', 10623 + 'PhabricatorPeopleUserEmailQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 10620 10624 'PhabricatorPeopleUserFunctionDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 10621 10625 'PhabricatorPeopleUserPHIDType' => 'PhabricatorPHIDType', 10622 10626 'PhabricatorPeopleUsernameMailEngine' => 'PhabricatorPeopleMailEngine',
+35
src/applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php
··· 1 + <?php 2 + 3 + final class PhabricatorPeopleUserEmailPHIDType 4 + extends PhabricatorPHIDType { 5 + 6 + const TYPECONST = 'EADR'; 7 + 8 + public function getTypeName() { 9 + return pht('User Email'); 10 + } 11 + 12 + public function newObject() { 13 + return new PhabricatorUserEmail(); 14 + } 15 + 16 + public function getPHIDTypeApplicationClass() { 17 + return 'PhabricatorPeopleApplication'; 18 + } 19 + 20 + protected function buildQueryForObjects( 21 + PhabricatorObjectQuery $query, 22 + array $phids) { 23 + 24 + return id(new PhabricatorPeopleUserEmailQuery()) 25 + ->withPHIDs($phids); 26 + } 27 + 28 + public function loadHandles( 29 + PhabricatorHandleQuery $query, 30 + array $handles, 31 + array $objects) { 32 + return null; 33 + } 34 + 35 + }
+55
src/applications/people/query/PhabricatorPeopleUserEmailQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorPeopleUserEmailQuery 4 + extends PhabricatorCursorPagedPolicyAwareQuery { 5 + 6 + private $ids; 7 + private $phids; 8 + 9 + public function withIDs(array $ids) { 10 + $this->ids = $ids; 11 + return $this; 12 + } 13 + 14 + public function withPHIDs(array $phids) { 15 + $this->phids = $phids; 16 + return $this; 17 + } 18 + 19 + public function newResultObject() { 20 + return new PhabricatorUserEmail(); 21 + } 22 + 23 + protected function loadPage() { 24 + return $this->loadStandardPage($this->newResultObject()); 25 + } 26 + 27 + protected function getPrimaryTableAlias() { 28 + return 'email'; 29 + } 30 + 31 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 32 + $where = parent::buildWhereClauseParts($conn); 33 + 34 + if ($this->ids !== null) { 35 + $where[] = qsprintf( 36 + $conn, 37 + 'email.id IN (%Ld)', 38 + $this->ids); 39 + } 40 + 41 + if ($this->phids !== null) { 42 + $where[] = qsprintf( 43 + $conn, 44 + 'email.phid IN (%Ls)', 45 + $this->phids); 46 + } 47 + 48 + return $where; 49 + } 50 + 51 + public function getQueryApplicationClass() { 52 + return 'PhabricatorPeopleApplication'; 53 + } 54 + 55 + }
+5
src/applications/people/storage/PhabricatorUserEmail.php
··· 18 18 19 19 protected function getConfiguration() { 20 20 return array( 21 + self::CONFIG_AUX_PHID => true, 21 22 self::CONFIG_COLUMN_SCHEMA => array( 22 23 'address' => 'sort128', 23 24 'isVerified' => 'bool', ··· 34 35 ), 35 36 ), 36 37 ) + parent::getConfiguration(); 38 + } 39 + 40 + public function getPHIDType() { 41 + return PhabricatorPeopleUserEmailPHIDType::TYPECONST; 37 42 } 38 43 39 44 public function getVerificationURI() {