Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/patches/20130611.nukeldap.php
| <?php | <?php | ||||
| // NOTE: We aren't using PhabricatorUserLDAPInfo anywhere here because it is | // NOTE: We aren't using PhabricatorUserLDAPInfo anywhere here because it is | ||||
| // being nuked by this change | // being nuked by this change | ||||
| $table = new PhabricatorUser(); | $table = new PhabricatorUser(); | ||||
| $table_name = 'user_ldapinfo'; | $table_name = 'user_ldapinfo'; | ||||
| $conn_w = $table->establishConnection('w'); | $conn_w = $table->establishConnection('w'); | ||||
| $xaccount = new PhabricatorExternalAccount(); | $xaccount = new PhabricatorExternalAccount(); | ||||
| echo "Migrating LDAP to ExternalAccount...\n"; | echo pht('Migrating LDAP to %s...', 'ExternalAccount')."\n"; | ||||
| $rows = queryfx_all($conn_w, 'SELECT * FROM %T', $table_name); | $rows = queryfx_all($conn_w, 'SELECT * FROM %T', $table_name); | ||||
| foreach ($rows as $row) { | foreach ($rows as $row) { | ||||
| echo "Migrating row ID #".$row['id'].".\n"; | echo pht('Migrating row ID #%d.', $row['id'])."\n"; | ||||
| $user = id(new PhabricatorUser())->loadOneWhere( | $user = id(new PhabricatorUser())->loadOneWhere( | ||||
| 'id = %d', | 'id = %d', | ||||
| $row['userID']); | $row['userID']); | ||||
| if (!$user) { | if (!$user) { | ||||
| echo "Bad user ID!\n"; | echo pht('Bad user ID!')."\n"; | ||||
| continue; | continue; | ||||
| } | } | ||||
| $xaccount = id(new PhabricatorExternalAccount()) | $xaccount = id(new PhabricatorExternalAccount()) | ||||
| ->setUserPHID($user->getPHID()) | ->setUserPHID($user->getPHID()) | ||||
| ->setAccountType('ldap') | ->setAccountType('ldap') | ||||
| ->setAccountDomain('self') | ->setAccountDomain('self') | ||||
| ->setAccountID($row['ldapUsername']) | ->setAccountID($row['ldapUsername']) | ||||
| ->setUsername($row['ldapUsername']) | ->setUsername($row['ldapUsername']) | ||||
| ->setDateCreated($row['dateCreated']); | ->setDateCreated($row['dateCreated']); | ||||
| try { | try { | ||||
| $xaccount->save(); | $xaccount->save(); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| phlog($ex); | phlog($ex); | ||||
| } | } | ||||
| } | } | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||