/** * Copy user data for this wiki into the localuser table */ function migratePassZero() { global $wgDBname; $dbr = wfGetDB(DB_SLAVE); $chunkSize = 1000; $start = microtime(true); $migrated = 0; $users = array(); // List all user accounts on this wiki in the migration table // on the central authentication server. $lastUser = $dbr->selectField('user', 'MAX(user_id)', '', __FUNCTION__); for ($min = 0; $min <= $lastUser; $min += $chunkSize) { $max = $min + $chunkSize - 1; $result = $dbr->select('user', array('user_id', 'user_name'), "user_id BETWEEN {$min} AND {$max}", __FUNCTION__); foreach ($result as $row) { $users[intval($row->user_id)] = $row->user_name; ++$migrated; } CentralAuthUser::storeMigrationData($wgDBname, $users); $users = array(); // clear the array for the next pass $delta = microtime(true) - $start; $rate = $delta == 0.0 ? 0.0 : $migrated / $delta; printf("%s %d (%0.1f%%) done in %0.1f secs (%0.3f accounts/sec).\n", $wgDBname, $migrated, min($max, $lastUser) / $lastUser * 100.0, $delta, $rate); if (($min + $chunkSize) % ($chunkSize * 10) == 0) { echo "Waiting for slaves to catch up ... "; CentralAuthUser::waitForSlaves(); echo "done\n"; } } }
/** * @covers CentralAuthUser::storeMigrationData */ public function testStoreMigrationData() { $caUsers = array('2001' => 'StoreMigrationDataUser 1', '2002' => 'StoreMigrationDataUser 2', '2003' => 'StoreMigrationDataUser 3'); CentralAuthUser::storeMigrationData('smdwiki', $caUsers); $this->assertSelect('localnames', 'ln_name', array('ln_wiki' => 'smdwiki'), array(array('StoreMigrationDataUser 1'), array('StoreMigrationDataUser 2'), array('StoreMigrationDataUser 3'))); }