[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/resources/sql/patches/ -> 20130611.migrateoauth.php (source)

   1  <?php
   2  
   3  // NOTE: We aren't using PhabricatorUserOAuthInfo anywhere here because it is
   4  // getting nuked in a future diff.
   5  
   6  $table = new PhabricatorUser();
   7  $table_name = 'user_oauthinfo';
   8  $conn_w = $table->establishConnection('w');
   9  
  10  $xaccount = new PhabricatorExternalAccount();
  11  
  12  echo "Migrating OAuth to ExternalAccount...\n";
  13  
  14  $domain_map = array(
  15    'disqus'      => 'disqus.com',
  16    'facebook'    => 'facebook.com',
  17    'github'      => 'github.com',
  18    'google'      => 'google.com',
  19  );
  20  
  21  try {
  22    $phabricator_oauth_uri = new PhutilURI(
  23      PhabricatorEnv::getEnvConfig('phabricator.oauth-uri'));
  24    $domain_map['phabricator'] = $phabricator_oauth_uri->getDomain();
  25  } catch (Exception $ex) {
  26    // Ignore; this likely indicates that we have removed `phabricator.oauth-uri`
  27    // in some future diff.
  28  }
  29  
  30  $rows = queryfx_all(
  31    $conn_w,
  32    'SELECT * FROM user_oauthinfo');
  33  foreach ($rows as $row) {
  34    echo "Migrating row ID #".$row['id'].".\n";
  35    $user = id(new PhabricatorUser())->loadOneWhere(
  36      'id = %d',
  37      $row['userID']);
  38    if (!$user) {
  39      echo "Bad user ID!\n";
  40      continue;
  41    }
  42  
  43    $domain = idx($domain_map, $row['oauthProvider']);
  44    if (empty($domain)) {
  45      echo "Unknown OAuth provider!\n";
  46      continue;
  47    }
  48  
  49  
  50    $xaccount = id(new PhabricatorExternalAccount())
  51      ->setUserPHID($user->getPHID())
  52      ->setAccountType($row['oauthProvider'])
  53      ->setAccountDomain($domain)
  54      ->setAccountID($row['oauthUID'])
  55      ->setAccountURI($row['accountURI'])
  56      ->setUsername($row['accountName'])
  57      ->setDateCreated($row['dateCreated']);
  58  
  59    try {
  60      $xaccount->save();
  61    } catch (Exception $ex) {
  62      phlog($ex);
  63    }
  64  }
  65  
  66  echo "Done.\n";


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1