Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/patches/20130611.migrateoauth.php
<?php | <?php | ||||
// NOTE: We aren't using PhabricatorUserOAuthInfo anywhere here because it is | |||||
// getting nuked in a future diff. | |||||
$table = new PhabricatorUser(); | $table = new PhabricatorUser(); | ||||
$conn = $table->establishConnection('w'); | |||||
$table_name = 'user_oauthinfo'; | $table_name = 'user_oauthinfo'; | ||||
$conn_w = $table->establishConnection('w'); | |||||
$xaccount = new PhabricatorExternalAccount(); | |||||
echo pht('Migrating OAuth to %s...', 'ExternalAccount')."\n"; | |||||
$domain_map = array( | |||||
'disqus' => 'disqus.com', | |||||
'facebook' => 'facebook.com', | |||||
'github' => 'github.com', | |||||
'google' => 'google.com', | |||||
); | |||||
try { | |||||
$phabricator_oauth_uri = new PhutilURI( | |||||
PhabricatorEnv::getEnvConfig('phabricator.oauth-uri')); | |||||
$domain_map['phabricator'] = $phabricator_oauth_uri->getDomain(); | |||||
} catch (Exception $ex) { | |||||
// Ignore; this likely indicates that we have removed `phabricator.oauth-uri` | |||||
// in some future diff. | |||||
} | |||||
$rows = queryfx_all( | |||||
$conn_w, | |||||
'SELECT * FROM user_oauthinfo'); | |||||
foreach ($rows as $row) { | |||||
echo pht('Migrating row ID #%d.', $row['id'])."\n"; | |||||
$user = id(new PhabricatorUser())->loadOneWhere( | |||||
'id = %d', | |||||
$row['userID']); | |||||
if (!$user) { | |||||
echo pht('Bad user ID!')."\n"; | |||||
continue; | |||||
} | |||||
$domain = idx($domain_map, $row['oauthProvider']); | foreach (new LiskRawMigrationIterator($conn, $table_name) as $row) { | ||||
if (empty($domain)) { | throw new Exception( | ||||
echo pht('Unknown OAuth provider!')."\n"; | pht( | ||||
continue; | 'Your Phabricator install has ancient OAuth account data and is '. | ||||
'too old to upgrade directly to a modern version of Phabricator. '. | |||||
'Upgrade to a version released between June 2013 and February 2019 '. | |||||
'first, then upgrade to a modern version.')); | |||||
} | } | ||||
$xaccount = id(new PhabricatorExternalAccount()) | |||||
->setUserPHID($user->getPHID()) | |||||
->setAccountType($row['oauthProvider']) | |||||
->setAccountDomain($domain) | |||||
->setAccountID($row['oauthUID']) | |||||
->setAccountURI($row['accountURI']) | |||||
->setUsername($row['accountName']) | |||||
->setDateCreated($row['dateCreated']); | |||||
try { | |||||
$xaccount->save(); | |||||
} catch (Exception $ex) { | |||||
phlog($ex); | |||||
} | |||||
} | |||||
echo pht('Done.')."\n"; |