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

Change subject: Detach accounts during global rename
......................................................................


Detach accounts during global rename

Delete localuser rows when changing the globaluser record so that
dangling records are not left during the rename process. As each local
wiki account is renamed it will be reattached.

Bug: T119736
Change-Id: I282cd12cb18a557a3ab4375db9238925470f3897
---
M includes/CentralAuthUser.php
M includes/GlobalRename/GlobalRenameUser.php
M includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php
M includes/LocalRenameJob/LocalRenameUserJob.php
4 files changed, 33 insertions(+), 12 deletions(-)

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



diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php
index 083400c..7899806 100644
--- a/includes/CentralAuthUser.php
+++ b/includes/CentralAuthUser.php
@@ -1758,11 +1758,12 @@
         * @param $wikiID String
         * @param $method String
         * @param $sendToRC bool
+        * @param string|int $ts MediaWiki timestamp or 0 for current time
         *
         * Prerequisites:
         * - completed migration state
         */
-       public function attach( $wikiID, $method = 'new', $sendToRC = true ) {
+       public function attach( $wikiID, $method = 'new', $sendToRC = true, $ts 
= 0 ) {
                $this->checkWriteMode();
                $dbw = CentralAuthUtils::getCentralDB();
                $dbw->begin( __METHOD__ );
@@ -1770,7 +1771,7 @@
                        array(
                                'lu_wiki'               => $wikiID,
                                'lu_name'               => $this->mName,
-                               'lu_attached_timestamp' => $dbw->timestamp(),
+                               'lu_attached_timestamp' => $dbw->timestamp( $ts 
),
                                'lu_attached_method'    => $method ),
                        __METHOD__,
                        array( 'IGNORE' )
@@ -2860,4 +2861,4 @@
        private function clearLocalUserCache( $wikiId, $userId ) {
                User::purge( $wikiId, $userId );
        }
-}
\ No newline at end of file
+}
diff --git a/includes/GlobalRename/GlobalRenameUser.php 
b/includes/GlobalRename/GlobalRenameUser.php
index f3a6c8d..885b7a2 100644
--- a/includes/GlobalRename/GlobalRenameUser.php
+++ b/includes/GlobalRename/GlobalRenameUser.php
@@ -102,13 +102,16 @@
         * @return Status
         */
        public function rename( array $options ) {
-               $wikis = $this->oldCAUser->listAttached();
+               $wikisAttached = $this->oldCAUser->queryAttached();
 
-               $status = $this->setRenameStatuses( $wikis );
+               $status = $this->setRenameStatuses( array_keys( $wikisAttached 
) );
                if ( !$status->isOK() ) {
                        return $status;
                }
 
+               // Rename the user centrally and unattach the old user from all
+               // attached wikis. Each will be reattached as its 
LocalRenameUserJob
+               // runs.
                $this->databaseUpdates->update(
                        $this->oldUser->getName(),
                        $this->newUser->getName()
@@ -128,7 +131,7 @@
                $this->oldCAUser->quickInvalidateCache();
                $this->newCAUser->quickInvalidateCache();
 
-               $this->injectLocalRenameUserJobs( $wikis, $options );
+               $this->injectLocalRenameUserJobs( $wikisAttached, $options );
 
                $this->logger->log(
                        $this->oldUser->getName(),
@@ -166,13 +169,15 @@
        }
 
        /**
+        * @param array $wikisAttached Attached wiki info
         * @param array $options
-        * @param array $wikis
         *
         * @return Status
         */
-       private function injectLocalRenameUserJobs( array $wikis, array 
$options ) {
-               $job = $this->getJob( $options );
+       private function injectLocalRenameUserJobs(
+               array $wikisAttached, array $options
+       ) {
+               $job = $this->getJob( $options, $wikisAttached );
                $statuses = $this->renameuserStatus->getStatuses( 
GlobalRenameUserStatus::READ_LATEST );
                foreach ( $statuses as $wiki => $status ) {
                        if ( $status === 'queued' ) {
@@ -184,14 +189,16 @@
 
        /**
         * @param array $options
+        * @param array $wikisAttached Attached wiki info
         *
         * @return Job
         */
-       private function getJob( array $options ) {
+       private function getJob( array $options, array $wikisAttached ) {
                $params = array(
                        'from' => $this->oldUser->getName(),
                        'to' => $this->newUser->getName(),
                        'renamer' => $this->performingUser->getName(),
+                       'reattach' => $wikisAttached,
                        'movepages' => $options['movepages'],
                        'suppressredirects' => $options['suppressredirects'],
                        'promotetoglobal' => false,
diff --git a/includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php 
b/includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php
index d97170e..a68186a 100644
--- a/includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php
+++ b/includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php
@@ -30,9 +30,8 @@
                        __METHOD__
                );
 
-               $dbw->update(
+               $dbw->delete(
                        'localuser',
-                       array( 'lu_name' => $newname ),
                        array( 'lu_name' => $oldname ),
                        __METHOD__
                );
diff --git a/includes/LocalRenameJob/LocalRenameUserJob.php 
b/includes/LocalRenameJob/LocalRenameUserJob.php
index 85f3fbf..5d2a754 100644
--- a/includes/LocalRenameJob/LocalRenameUserJob.php
+++ b/includes/LocalRenameJob/LocalRenameUserJob.php
@@ -19,6 +19,9 @@
                if ( !isset( $params['reason'] ) ) {
                        $params['reason'] = '';
                }
+               if ( !isset( $params['reattach'] ) ) {
+                       $params['reattach'] = false;
+               }
                parent::__construct( 'LocalRenameUserJob', $title, $params, $id 
);
        }
 
@@ -62,6 +65,17 @@
                        // until a sysadmin intervenes...
                        throw new Exception( 'RenameuserSQL::rename returned 
false.' );
                }
+               if ( $this->params['reattach'] ) {
+                       $caUser = CentralAuthUser::getInstanceByName( 
$this->params['to'] );
+                       $wikiId = wfWikiID();
+                       $details = $this->params['reattach'][$wikiId];
+                       $caUser->attach(
+                               $wikiId,
+                               $details['attachedMethod'],
+                               false,
+                               $details['attachedTimestamp']
+                       );
+               }
 
                if ( $this->params['movepages'] ) {
                        $this->movePages( $oldUser );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I282cd12cb18a557a3ab4375db9238925470f3897
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <bda...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
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