Handle session reset errors in invalidateSessionsForUser.php
authorGergő Tisza <gtisza@wikimedia.org>
Fri, 17 Jun 2016 00:12:38 +0000 (00:12 +0000)
committerGergő Tisza <gtisza@wikimedia.org>
Sat, 18 Jun 2016 11:01:20 +0000 (11:01 +0000)
Also, do not skip session reset if the user does not exist locally.

Change-Id: I5a55e4a6f2d296576ee76e212ed379225251e128

maintenance/invalidateUserSessions.php

index 4b567ae..11e3372 100644 (file)
@@ -70,11 +70,17 @@ class InvalidateUserSesssions extends Maintenance {
                foreach ( $usernames as $username ) {
                        $i++;
                        $user = User::newFromName( $username );
-                       if ( $user->getId() ) {
+                       try {
                                $sessionManager->invalidateSessionsForUser( $user );
-                               $this->output( "Invalidated sessions for user $username\n" );
-                       } else {
-                               $this->output( "Could not find user $username\n" );
+                               if ( $user->getId() ) {
+                                       $this->output( "Invalidated sessions for user $username\n" );
+                               } else {
+                                       # session invalidation might still work if there is a central identity provider
+                                       $this->output( "Could not find user $username, tried to invalidate anyway\n" );
+                               }
+                       } catch ( Exception $e ) {
+                               $this->output( "Failed to invalidate sessions for user $username | "
+                                       . str_replace( [ "\r", "\n" ], ' ', $e->getMessage() ) . "\n" );
                        }
 
                        if ( $i % $this->mBatchSize ) {