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 | |||||
// being nuked by this change | |||||
$table = new PhabricatorUser(); | $table = new PhabricatorUser(); | ||||
$conn = $table->establishConnection('w'); | |||||
$table_name = 'user_ldapinfo'; | $table_name = 'user_ldapinfo'; | ||||
$conn_w = $table->establishConnection('w'); | |||||
$xaccount = new PhabricatorExternalAccount(); | |||||
echo pht('Migrating LDAP to %s...', 'ExternalAccount')."\n"; | |||||
$rows = queryfx_all($conn_w, 'SELECT * FROM %T', $table_name); | foreach (new LiskRawMigrationIterator($conn, $table_name) as $row) { | ||||
foreach ($rows as $row) { | throw new Exception( | ||||
echo pht('Migrating row ID #%d.', $row['id'])."\n"; | pht( | ||||
$user = id(new PhabricatorUser())->loadOneWhere( | 'Your Phabricator install has ancient LDAP account data and is '. | ||||
'id = %d', | 'too old to upgrade directly to a modern version of Phabricator. '. | ||||
$row['userID']); | 'Upgrade to a version released between June 2013 and February 2019 '. | ||||
if (!$user) { | 'first, then upgrade to a modern version.')); | ||||
echo pht('Bad user ID!')."\n"; | |||||
continue; | |||||
} | } | ||||
$xaccount = id(new PhabricatorExternalAccount()) | |||||
->setUserPHID($user->getPHID()) | |||||
->setAccountType('ldap') | |||||
->setAccountDomain('self') | |||||
->setAccountID($row['ldapUsername']) | |||||
->setUsername($row['ldapUsername']) | |||||
->setDateCreated($row['dateCreated']); | |||||
try { | |||||
$xaccount->save(); | |||||
} catch (Exception $ex) { | |||||
phlog($ex); | |||||
} | |||||
} | |||||
echo pht('Done.')."\n"; |