public function execute()
 {
     $this->output("CentralAuth migration pass 1:\n");
     $this->output("Finding accounts which can be migrated without interaction...\n");
     $dbBackground = CentralAuthUser::getCentralSlaveDB();
     $result = $dbBackground->select('globalnames', array('gn_name'), array(), __METHOD__);
     foreach ($result as $row) {
         $this->fromPrefix = $row->gn_name;
         $central = new CentralAuthUser($row->gn_name);
         if ($central->storeAndMigrate()) {
             $this->migrated++;
         }
         if (++$this->total % 1000 == 0) {
             $this->migratePassOneReport();
         }
     }
     $this->migratePassOneReport();
     $this->output("done.\n");
 }
Пример #2
0
function migratePassOne()
{
    $migrated = 0;
    $total = 0;
    $chunkSize = 1000;
    $start = microtime(true);
    $dbBackground = CentralAuthUser::getCentralSlaveDB();
    $result = $dbBackground->select('globalnames', array('gn_name'), '', __METHOD__);
    foreach ($result as $row) {
        $name = $row->gn_name;
        $central = new CentralAuthUser($name);
        if ($central->storeAndMigrate()) {
            $migrated++;
        }
        if (++$total % $chunkSize == 0) {
            migratePassOneReport($migrated, $total, $start);
        }
    }
    migratePassOneReport($migrated, $total, $start);
    echo "DONE\n";
}
 function doInitialMerge()
 {
     global $wgCentralAuthDryRun;
     $globalUser = new CentralAuthUser($this->getUser()->getName());
     if ($wgCentralAuthDryRun) {
         $this->dryRunError();
         return;
     }
     if ($globalUser->exists()) {
         throw new MWException("Already exists -- race condition");
     }
     $passwords = $this->getWorkingPasswords();
     if (empty($passwords)) {
         throw new MWException("Submission error -- invalid input");
     }
     $globalUser->storeAndMigrate($passwords);
     $this->clearWorkingPasswords();
     $this->showCleanupForm();
 }
 function migrate($username, $homewiki = null)
 {
     $this->total++;
     $this->output("CentralAuth account migration for: " . $username . "\n");
     $central = new CentralAuthUser($username);
     try {
         $unattached = $central->queryUnattached();
     } catch (Exception $e) {
         // This might happen due to localnames inconsistencies (bug 67350)
         $this->output("ERROR: Fetching unattached accounts for {$username} failed.");
         return;
     }
     /**
      * Migration with an existing global account
      */
     if ($central->exists()) {
         $this->output("INFO: A global account already exists for: {$username}\n");
         if ($this->getOption('attachmissing', false) && !is_null($central->getEmailAuthenticationTimestamp())) {
             foreach ($unattached as $wiki => $local) {
                 if ($central->getEmail() === $local['email'] && !is_null($local['emailAuthenticated'])) {
                     $this->output("ATTACHING: {$username}@{$wiki}\n");
                     $central->attach($wiki, 'mail', !$this->suppressRC);
                 }
             }
         }
         if ($this->getOption('attachbroken', false)) {
             // This option is for bug 61876 / bug 39996 where the account has
             // an empty password and email set, and became unattached.
             // Since there is no way an account can have an empty password manually
             // it has to be due to a CentralAuth bug. So just attach it then.
             // But just to be on the safe side, check that it also has 0 edits.
             foreach ($unattached as $wiki => $local) {
                 if ($local['email'] === '' && $local['password'] === '' && $local['editCount'] === '0') {
                     $this->output("ATTACHING: {$username}@{$wiki}\n");
                     // Ironically, the attachment is made due to lack of a password.
                     $central->attach($wiki, 'password', !$this->suppressRC);
                 }
             }
         }
     } else {
         if (count($unattached) == 0) {
             $this->output("ERROR: No local accounts found for: {$username}\n");
             return;
         }
         if ($this->safe && count($unattached) !== 1) {
             $this->output("ERROR: More than 1 local user account found for username: {$username}\n");
             foreach ($unattached as $local) {
                 $this->output("\t" . $central->getName() . "@" . $local['wiki'] . "\n");
             }
             return;
         }
         if ($homewiki !== null) {
             if (!array_key_exists($homewiki, $unattached)) {
                 $this->output("ERROR: Unattached user not found for {$username}@{$homewiki}\n");
                 return;
             }
             $this->output("INFO: Setting homewiki for '{$username}' to {$homewiki}\n");
             $central->mHomeWiki = $homewiki;
         }
         // Check that all unattached (i.e. ALL) accounts have a confirmed email
         // address and that the addresses are all the same. We are using this
         // to match accounts to the same user, since we can't use the password.
         $emailMatch = true;
         $email = null;
         foreach ($unattached as $local) {
             if (is_null($email)) {
                 $email = $local['email'];
             }
             if ($local['email'] === $email && !is_null($local['emailAuthenticated'])) {
                 continue;
             }
             $emailMatch = false;
             break;
         }
         // All of the emails are the same and confirmed? Merge all the accounts.
         // They aren't? Skip, or merge the winner if --auto was specified.
         if ($emailMatch) {
             $this->output("Email addresses match and are confirmed for: {$username}\n");
             $central->storeAndMigrate(array(), !$this->suppressRC);
         } else {
             if (isset($central->mHomeWiki) || $this->autoMigrate) {
                 $central->storeAndMigrate(array(), !$this->suppressRC);
             } else {
                 $this->output("ERROR: Auto migration is disabled and email addresses do not match for: {$username}\n");
             }
         }
     }
     $unattachedAfter = $central->queryUnattached();
     if (count($unattachedAfter) == 0) {
         $this->migrated++;
         return;
     } elseif (count($unattachedAfter) > 0 && count($unattachedAfter) < count($unattached)) {
         $this->partial++;
         $this->output("INFO: Incomplete migration for '{$username}'\n");
     }
     if ($this->resetToken) {
         $this->output("INFO: Resetting CentralAuth auth token for '{$username}'\n");
         $central->resetAuthToken();
     }
 }