@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Migrate PhabricatorUserLDAPInfo to PhabricatorExternalAccount

Summary: Ref T1536. This is similar to D6172 but much simpler: we don't need to retain external interfaces here and can do a straight migration.

Test Plan: TBA

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6173

+84 -41
+41
resources/sql/patches/20130611.nukeldap.php
··· 1 + <?php 2 + 3 + // NOTE: We aren't using PhabricatorUserLDAPInfo anywhere here because it is 4 + // being nuked by this change 5 + 6 + $table = new PhabricatorUser(); 7 + $table_name = 'user_ldapinfo'; 8 + $conn_w = $table->establishConnection('w'); 9 + 10 + $xaccount = new PhabricatorExternalAccount(); 11 + 12 + echo "Migrating LDAP to ExternalAccount...\n"; 13 + 14 + $rows = queryfx_all($conn_w, 'SELECT * FROM %T', $table_name); 15 + foreach ($rows as $row) { 16 + echo "Migrating row ID #".$row['id'].".\n"; 17 + $user = id(new PhabricatorUser())->loadOneWhere( 18 + 'id = %d', 19 + $row['userID']); 20 + if (!$user) { 21 + echo "Bad user ID!\n"; 22 + continue; 23 + } 24 + 25 + 26 + $xaccount = id(new PhabricatorExternalAccount()) 27 + ->setUserPHID($user->getPHID()) 28 + ->setAccountType('ldap') 29 + ->setAccountDomain('self') 30 + ->setAccountID($row['ldapUsername']) 31 + ->setUsername($row['ldapUsername']) 32 + ->setDateCreated($row['dateCreated']); 33 + 34 + try { 35 + $xaccount->save(); 36 + } catch (Exception $ex) { 37 + phlog($ex); 38 + } 39 + } 40 + 41 + echo "Done.\n";
-2
src/__phutil_library_map__.php
··· 1554 1554 'PhabricatorUserDAO' => 'applications/people/storage/PhabricatorUserDAO.php', 1555 1555 'PhabricatorUserEditor' => 'applications/people/editor/PhabricatorUserEditor.php', 1556 1556 'PhabricatorUserEmail' => 'applications/people/storage/PhabricatorUserEmail.php', 1557 - 'PhabricatorUserLDAPInfo' => 'applications/people/storage/PhabricatorUserLDAPInfo.php', 1558 1557 'PhabricatorUserLog' => 'applications/people/storage/PhabricatorUserLog.php', 1559 1558 'PhabricatorUserOAuthInfo' => 'applications/people/storage/PhabricatorUserOAuthInfo.php', 1560 1559 'PhabricatorUserPreferences' => 'applications/settings/storage/PhabricatorUserPreferences.php', ··· 3403 3402 'PhabricatorUserDAO' => 'PhabricatorLiskDAO', 3404 3403 'PhabricatorUserEditor' => 'PhabricatorEditor', 3405 3404 'PhabricatorUserEmail' => 'PhabricatorUserDAO', 3406 - 'PhabricatorUserLDAPInfo' => 'PhabricatorUserDAO', 3407 3405 'PhabricatorUserLog' => 'PhabricatorUserDAO', 3408 3406 'PhabricatorUserPreferences' => 'PhabricatorUserDAO', 3409 3407 'PhabricatorUserProfile' => 'PhabricatorUserDAO',
+19 -12
src/applications/auth/controller/PhabricatorLDAPLoginController.php
··· 34 34 35 35 if ($current_user->getPHID()) { 36 36 if ($ldap_info->getID()) { 37 - $existing_ldap = id(new PhabricatorUserLDAPInfo())->loadOneWhere( 38 - 'userID = %d', 39 - $current_user->getID()); 37 + $existing_ldap = id(new PhabricatorExternalAccount())->loadOneWhere( 38 + 'accountType = %s AND accountDomain = %s AND userPHID = %s', 39 + 'ldap', 40 + 'self', 41 + $current_user->getPHID()); 40 42 41 - if ($ldap_info->getUserID() != $current_user->getID() || 43 + if ($ldap_info->getUserPHID() != $current_user->getPHID() || 42 44 $existing_ldap) { 43 45 $dialog = new AphrontDialogView(); 44 46 $dialog->setUser($current_user); ··· 71 73 return id(new AphrontDialogResponse())->setDialog($dialog); 72 74 } 73 75 74 - $ldap_info->setUserID($current_user->getID()); 76 + $ldap_info->setUserPHID($current_user->getPHID()); 75 77 76 78 $this->saveLDAPInfo($ldap_info); 77 79 ··· 82 84 if ($ldap_info->getID()) { 83 85 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 84 86 85 - $known_user = id(new PhabricatorUser())->load( 86 - $ldap_info->getUserID()); 87 + $known_user = id(new PhabricatorUser())->loadOneWhere( 88 + 'phid = %s', 89 + $ldap_info->getUserPHID()); 87 90 88 91 $session_key = $known_user->establishSession('web'); 89 92 ··· 152 155 } 153 156 154 157 private function retrieveLDAPInfo(PhabricatorLDAPProvider $provider) { 155 - $ldap_info = id(new PhabricatorUserLDAPInfo())->loadOneWhere( 156 - 'ldapUsername = %s', 158 + $ldap_info = id(new PhabricatorExternalAccount())->loadOneWhere( 159 + 'accountType = %s AND accountDomain = %s AND accountID = %s', 160 + 'ldap', 161 + 'self', 157 162 $provider->retrieveUsername()); 158 163 159 164 if (!$ldap_info) { 160 - $ldap_info = new PhabricatorUserLDAPInfo(); 161 - $ldap_info->setLDAPUsername($provider->retrieveUsername()); 165 + $ldap_info = id(new PhabricatorExternalAccount()) 166 + ->setAccountType('ldap') 167 + ->setAccountDomain('self') 168 + ->setAccountID($provider->retrieveUsername()); 162 169 } 163 170 164 171 return $ldap_info; 165 172 } 166 173 167 - private function saveLDAPInfo(PhabricatorUserLDAPInfo $info) { 174 + private function saveLDAPInfo(PhabricatorExternalAccount $info) { 168 175 // UNGUARDED WRITES: Logging-in users don't have their CSRF set up yet. 169 176 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 170 177 $info->save();
+1 -1
src/applications/auth/controller/PhabricatorLDAPRegistrationController.php
··· 116 116 ->setActor($user) 117 117 ->createNewUser($user, $email_obj); 118 118 119 - $ldap_info->setUserID($user->getID()); 119 + $ldap_info->setUserPHID($user->getPHID()); 120 120 $ldap_info->save(); 121 121 122 122 $session_key = $user->establishSession('web');
+7 -5
src/applications/auth/controller/PhabricatorLDAPUnlinkController.php
··· 6 6 $request = $this->getRequest(); 7 7 $user = $request->getUser(); 8 8 9 - $ldap_info = id(new PhabricatorUserLDAPInfo())->loadOneWhere( 10 - 'userID = %d', 11 - $user->getID()); 9 + $ldap_account = id(new PhabricatorExternalAccount())->loadOneWhere( 10 + 'userPHID = %s AND accountType = %s AND accountDomain = %s', 11 + $user->getPHID(), 12 + 'ldap', 13 + 'self'); 12 14 13 - if (!$ldap_info) { 15 + if (!$ldap_account) { 14 16 return new Aphront400Response(); 15 17 } 16 18 ··· 27 29 return id(new AphrontDialogResponse())->setDialog($dialog); 28 30 } 29 31 30 - $ldap_info->delete(); 32 + $ldap_account->delete(); 31 33 32 34 return id(new AphrontRedirectResponse()) 33 35 ->setURI('/settings/panel/ldap/');
+6 -4
src/applications/people/controller/PhabricatorPeopleLdapController.php
··· 96 96 ->setActor($admin) 97 97 ->createNewUser($user, $email_obj); 98 98 99 - $ldap_info = new PhabricatorUserLDAPInfo(); 100 - $ldap_info->setLDAPUsername($username); 101 - $ldap_info->setUserID($user->getID()); 102 - $ldap_info->save(); 99 + id(new PhabricatorExternalAccount()) 100 + ->setUserPHID($user->getPHID()) 101 + ->setAccountType('ldap') 102 + ->setAccountDomain('self') 103 + ->setAccountID($username) 104 + ->save(); 103 105 104 106 $header = pht('Successfully added %s', $username); 105 107 $attribute = null;
-7
src/applications/people/editor/PhabricatorUserEditor.php
··· 303 303 } 304 304 305 305 $user->openTransaction(); 306 - $ldaps = id(new PhabricatorUserLDAPInfo())->loadAllWhere( 307 - 'userID = %d', 308 - $user->getID()); 309 - foreach ($ldaps as $ldap) { 310 - $ldap->delete(); 311 - } 312 - 313 306 $externals = id(new PhabricatorExternalAccount())->loadAllWhere( 314 307 'userPHID = %s', 315 308 $user->getPHID());
-6
src/applications/people/storage/PhabricatorUserLDAPInfo.php
··· 1 - <?php 2 - 3 - final class PhabricatorUserLDAPInfo extends PhabricatorUserDAO { 4 - protected $userID; 5 - protected $ldapUsername; 6 - }
+6 -4
src/applications/settings/panel/PhabricatorSettingsPanelLDAP.php
··· 23 23 public function processRequest(AphrontRequest $request) { 24 24 $user = $request->getUser(); 25 25 26 - $ldap_info = id(new PhabricatorUserLDAPInfo())->loadOneWhere( 27 - 'userID = %d', 28 - $user->getID()); 26 + $ldap_account = id(new PhabricatorExternalAccount())->loadOneWhere( 27 + 'userPHID = %s AND accountType = %s AND accountDomain = %s', 28 + $user->getPHID(), 29 + 'ldap', 30 + 'self'); 29 31 30 32 $forms = array(); 31 33 32 - if (!$ldap_info) { 34 + if (!$ldap_account) { 33 35 $unlink = pht('Link LDAP Account'); 34 36 $unlink_form = new AphrontFormView(); 35 37 $unlink_form
+4
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1362 1362 'type' => 'php', 1363 1363 'name' => $this->getPatchPath('20130611.migrateoauth.php'), 1364 1364 ), 1365 + '20130611.nukeldap.php' => array( 1366 + 'type' => 'php', 1367 + 'name' => $this->getPatchPath('20130611.nukeldap.php'), 1368 + ), 1365 1369 ); 1366 1370 } 1367 1371 }