jenkins-bot has submitted this change and it was merged.

Change subject: Auto-migrate matching accounts where no global account exists
......................................................................


Auto-migrate matching accounts where no global account exists

Only does this in safe cases, where all unattached accounts match.

Bug: 70392
Change-Id: I3a219d86a8837ed9c0c3788604dc3229ee1245ee
---
M CentralAuthPlugin.php
M CentralAuthUser.php
2 files changed, 20 insertions(+), 3 deletions(-)

Approvals:
  CSteipp: Looks good to me, approved
  jenkins-bot: Verified

Objections:
  Legoktm: There's a problem with this change, please improve



diff --git a/CentralAuthPlugin.php b/CentralAuthPlugin.php
index 3495f4c..94d634e 100644
--- a/CentralAuthPlugin.php
+++ b/CentralAuthPlugin.php
@@ -43,6 +43,16 @@
                                'CentralAuth',
                                "plugin: no global account for '$username'"
                        );
+                       // See if all the unattached accounts match passwords
+                       // and can be globalized. (bug 70392)
+                       if ( $wgCentralAuthAutoMigrate ) {
+                               $ok = $central->storeAndMigrate( array( 
$password ), /* $sendToRC = */ true, /* $safe = */ true );
+                               if ( $ok ) {
+                                       wfDebugLog( 'CentralAuth',
+                                               "wgCentralAuthAutoMigrate 
successful in creating a global account for '$username''" );
+                                       return true;
+                               }
+                       }
                        return false;
                }
 
diff --git a/CentralAuthUser.php b/CentralAuthUser.php
index 0d4d395..2d5b013 100644
--- a/CentralAuthUser.php
+++ b/CentralAuthUser.php
@@ -635,13 +635,14 @@
        /**
         * @param array $passwords
         * @param bool $sendToRC
+        * @param bool $safe Only allow migration if all users can be migrated
         * @return bool
         */
-       public function storeAndMigrate( $passwords = array(), $sendToRC = true 
) {
+       public function storeAndMigrate( $passwords = array(), $sendToRC = 
true, $safe = false ) {
                $dbw = self::getCentralDB();
                $dbw->begin();
 
-               $ret = $this->attemptAutoMigration( $passwords, $sendToRC );
+               $ret = $this->attemptAutoMigration( $passwords, $sendToRC, 
$safe );
 
                $dbw->commit();
                return $ret;
@@ -823,9 +824,10 @@
         *
         * @param $passwords Array
         * @param $sendToRC bool
+        * @param $safe bool Only migrate if all accounts can be merged
         * @return bool Whether full automatic migration completed successfully.
         */
-       protected function attemptAutoMigration( $passwords = array(), 
$sendToRC = true ) {
+       protected function attemptAutoMigration( $passwords = array(), 
$sendToRC = true, $safe = false ) {
                $migrationSet = $this->queryUnattached();
                if ( empty( $migrationSet ) ) {
                        wfDebugLog( 'CentralAuth', 'no accounts to merge, 
failed migration' );
@@ -849,6 +851,11 @@
                // Pick all the local accounts matching the "master" home 
account
                $attach = $this->prepareMigration( $migrationSet, $passwords );
 
+               if ( $safe && count( $attach ) !== count( $migrationSet ) ) {
+                       wfDebugLog( 'CentralAuth', "Safe auto-migration for 
'$this->mName' failed" );
+                       return false;
+               }
+
                // storeGlobalData clears $this->mHomeWiki
                $homeWiki = $this->mHomeWiki;
                // Actually do the migration

-- 
To view, visit https://gerrit.wikimedia.org/r/158578
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3a219d86a8837ed9c0c3788604dc3229ee1245ee
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: CSteipp <cste...@wikimedia.org>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Nemo bis <federicol...@tiscali.it>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to