/** * 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"; } } }
public function execute() { global $wgUser; $wgUser = User::newFromName('Maintenance script'); RequestContext::getMain()->setUser($wgUser); $dbr = CentralAuthUser::getCentralSlaveDB(); if ($this->getOption('fix', false) !== false) { $this->fix = true; } if ($this->getOption('safe-migrate', false) !== false) { $this->safe = true; $this->migrate = true; } if ($this->getOption('migrate', false) !== false) { $this->migrate = true; } if ($this->getOption('suppressrc', false) !== false) { $this->suppressRC = true; } $end = $dbr->selectField('globaluser', 'MAX(gu_id)'); for ($cur = 0; $cur <= $end; $cur += $this->mBatchSize) { $this->output("PROGRESS: {$cur} / {$end}\n"); $result = $dbr->select(array('globaluser', 'localuser'), array('gu_name'), array('lu_name' => null, "gu_id >= {$cur}", 'gu_id < ' . ($cur + $this->mBatchSize)), __METHOD__, array('ORDER BY' => 'gu_id'), array('localuser' => array('LEFT JOIN', 'gu_name=lu_name'))); foreach ($result as $row) { $this->process($row->gu_name); } if ($this->fix) { CentralAuthUser::waitForSlaves(); } } $this->output("done.\n"); }
public function execute() { if (!$this->getOption('nowarn')) { $this->output("The script is about to reset the user_token for ALL USERS in the database.\n"); $this->output("This may log some of them out and is not necessary unless you believe your\n"); $this->output("user table has been compromised.\n"); $this->output("\n"); $this->output("Abort with control-c in the next five seconds (skip this countdown with --nowarn) ... "); wfCountDown(5); } // We list user by user_id from one of the slave database $dbr = CentralAuthUser::getCentralDB(DB_SLAVE); $maxid = $this->getOption('maxid', -1); if ($maxid == -1) { $maxid = $dbr->selectField('globaluser', 'MAX(gu_id)', array(), __METHOD__); } $min = $this->getOption('minid', 0); $max = $min + $this->mBatchSize; do { $result = $dbr->select('globaluser', array('gu_id', 'gu_name'), array('gu_id > ' . $dbr->addQuotes($min), 'gu_id <= ' . $dbr->addQuotes($max)), __METHOD__); foreach ($result as $user) { $this->updateUser($user->gu_name); } $min = $max; $max = $min + $this->mBatchSize; if ($max > $maxid) { $max = $maxid; } CentralAuthUser::waitForSlaves(); } while ($min < $maxid); }
public function execute() { $this->dbBackground = CentralAuthUser::getCentralSlaveDB(); if ($this->getOption('safe', false) !== false) { $this->safe = true; } if ($this->getOption('auto', false) !== false) { $this->autoMigrate = true; } if ($this->getOption('resettoken', false) !== false) { $this->resetToken = true; } if ($this->getOption('suppressrc', false) !== false) { $this->suppressRC = true; } // Check to see if we are processing a single username if ($this->getOption('username', false) !== false) { $username = $this->getOption('username'); $homewiki = $this->getOption('homewiki', null); $this->migrate($username, $homewiki); } elseif ($this->getOption('userlist', false) !== false) { $list = $this->getOption('userlist'); if (!is_file($list)) { $this->output("ERROR - File not found: {$list}"); exit(1); } $file = fopen($list, 'r'); if ($file === false) { $this->output("ERROR - Could not open file: {$list}"); exit(1); } while (strlen($line = trim(fgets($file)))) { $values = explode("\t", $line); switch (count($values)) { case 1: $this->migrate($values[0]); break; case 2: $this->migrate($values[0], $values[1]); break; default: $this->output("ERROR: Invalid account specification: '{$line}'\n"); continue; } if ($this->total % $this->batchSize == 0) { $this->output("Waiting for slaves to catch up ... "); CentralAuthUser::waitForSlaves(); $this->output("done\n"); } } fclose($file); } else { $this->output("ERROR - No username or list of usernames given\n"); exit(1); } $this->migratePassOneReport(); $this->output("done.\n"); }
public function execute() { $dbw = CentralAuthUser::getCentralDB(); $dbr = CentralAuthUser::getCentralSlaveDB(); $total = 0; do { $rows = $dbr->select(array('users_to_rename', 'localuser'), array('utr_id', 'utr_name', 'utr_wiki'), array(), __METHOD__, array('LIMIT' => $this->mBatchSize), array('localuser' => array('INNER JOIN', 'utr_wiki=lu_wiki AND utr_name=lu_name'))); $ids = array(); foreach ($rows as $row) { $ids[] = $row->utr_id; $this->output("{$row->utr_name}@{$row->utr_wiki} is now attached!\n"); } if ($ids) { $count = count($ids); $this->output("Deleting {$count} users...\n"); $dbw->delete('users_to_rename', array('utr_id' => $ids), __METHOD__); $total += $count; } CentralAuthUser::waitForSlaves(); } while ($rows->numRows() >= $this->mBatchSize); $this->output("Removed {$total} users in total.\n"); }
public function execute() { $db = CentralAuthUser::getCentralSlaveDB(); $conds = array(); $count = 0; do { $result = $db->select('globaluser', array('gu_name'), array_merge($conds, array('gu_home_db IS NULL OR gu_home_db = ""')), __METHOD__, array('LIMIT' => $this->mBatchSize, 'ORDER BY' => 'gu_name')); foreach ($result as $row) { $central = new CentralAuthUser($row->gu_name); $central->mStateDirty = true; $central->saveSettings(); $count++; } $this->output("{$count}\n"); CentralAuthUser::waitForSlaves(); if ($result->numRows() < $this->mBatchSize) { break; } $conds = array('gu_name > ' . $db->addQuotes($row->gu_name)); } while (true); $this->output("done.\n"); }
public function execute() { if (!class_exists('CentralAuthUser')) { $this->error('CentralAuth is not installed on this wiki.', 1); } $dbw = CentralAuthUser::getCentralDB(); while (true) { $rowsToRename = $this->findUsers(wfWikiID(), $dbw); if (!$rowsToRename) { break; } foreach ($rowsToRename as $row) { $this->rename($row, $dbw); } CentralAuthUser::waitForSlaves(); $count = $this->getCurrentRenameCount($dbw); while ($count > 50) { $this->output("There are currently {$count} renames queued, pausing...\n"); sleep(5); $count = $this->getCurrentRenameCount($dbw); } } }
public function execute() { $dbw = CentralAuthUser::getCentralDB(); $databaseUpdates = new UsersToRenameDatabaseUpdates($dbw); // CentralAuthUser::chooseHomeWiki is expensive and called // multiple times, so lets cache it. $cache = new MapCacheLRU($this->mBatchSize); do { $rows = $this->doQuery(); $insertRows = array(); foreach ($rows as $row) { $this->lName = $row->name; $this->lWiki = $row->wiki; if ($cache->has($row->name)) { $attachableWikis = $cache->get($row->name); } else { $ca = new CentralAuthUser($row->name); $attachableWikis = array(); $unattached = $ca->queryUnattached(); if ($ca->exists()) { $home = $ca->getHomeWiki(); $attachableWikis[] = $home; foreach ($unattached as $wiki => $info) { if ($ca->getEmailAuthenticationTimestamp() && $info['email'] === $ca->getEmail() && !is_null($info['emailAuthenticated'])) { $attachableWikis[] = $wiki; } } } else { $home = $ca->chooseHomeWiki($unattached); $attachableWikis[] = $home; if ($unattached[$home]['email'] && isset($unattached[$home]['emailAuthenticated'])) { foreach ($unattached as $wiki => $info) { if ($wiki !== $home && $unattached[$home]['email'] === $info['email'] && isset($info['emailAuthenticated'])) { $attachableWikis[] = $wiki; } } } } $cache->set($row->name, $attachableWikis); } if (!in_array($row->wiki, $attachableWikis)) { // Unattached account which is not attachable, // so they're getting renamed :( $this->output("{$row->name}@{$row->wiki} is going to be renamed.\n"); $insertRows[] = (array) $row; } } $databaseUpdates->batchInsert($insertRows); $count = $dbw->affectedRows(); $this->output("Inserted {$count} users who we will rename\n"); $this->output("Waiting for slaves...\n"); CentralAuthUser::waitForSlaves(); } while ($count !== 0); }
public function execute() { if (!class_exists('MassMessageServerSideJob')) { $this->error('This script requires the MassMessage extension', 1); } $message = $this->getLocalizedText($this->getOption('message')); $message = str_replace('{{WIKI}}', wfWikiID(), $message); $message .= " ~~~~~\n<!-- SUL finalisation notification -->"; $dbw = CentralAuthUser::getCentralDB(); $updates = new UsersToRenameDatabaseUpdates($dbw); $commonParams = array('subject' => $this->getLocalizedText($this->getOption('subject'))); while (true) { $jobs = array(); $markNotified = array(); $rows = $updates->findUsers(wfWikiID(), 0, $this->mBatchSize); if ($rows->numRows() === 0) { break; } $lb = new LinkBatch(); foreach ($rows as $row) { $title = Title::makeTitleSafe(NS_USER_TALK, $row->utr_name); if (!$title) { $this->output("ERROR: Invalid username for {$row->utr_name}\n"); continue; } $lb->addObj($title); } $lb->execute(); foreach ($rows as $row) { $title = 'User talk:' . $row->utr_name; $titleObj = Title::newFromText($title); if ($titleObj->isRedirect()) { // @fixme find a way to notify users with a redirected user-talk $this->output("Skipping {$title} because it is a redirect\n"); $updates->markRedirectSkipped($row->utr_name, $row->utr_wiki); continue; } $jobs[] = new MassMessageServerSideJob(Title::newFromText($title), array('title' => $title, 'message' => str_replace('{{subst:PAGENAME}}', $row->utr_name, $message)) + $commonParams); $this->output("Will notify {$row->utr_name}\n"); $markNotified[] = $row; } $count = count($jobs); $this->output("Queued job for {$count} users.\n"); JobQueueGroup::singleton()->push($jobs); foreach ($markNotified as $row) { $updates->markNotified($row->utr_name, $row->utr_wiki); } $this->output("Waiting for slaves..."); CentralAuthUser::waitForSlaves(); // users_to_rename wfWaitForSlaves(); // And on the local wiki! $this->output(" done.\n"); $queued = $this->getQueuedCount(); while ($queued > 100000) { $this->output("Currently {$queued} jobs, sleeping for 5 seconds...\n"); sleep(5); $queued = $this->getQueuedCount(); } } }
protected function waitForSlaves() { CentralAuthUser::waitForSlaves(); }