forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20130611.migrateoauth.php
66 lines (54 loc) · 1.65 KB
/
20130611.migrateoauth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// NOTE: We aren't using PhabricatorUserOAuthInfo anywhere here because it is
// getting nuked in a future diff.
$table = new PhabricatorUser();
$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']);
if (empty($domain)) {
echo pht('Unknown OAuth provider!')."\n";
continue;
}
$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";