cleanupUsersWithNoId.php: Handle missing fields
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 12 Nov 2019 15:08:24 +0000 (10:08 -0500)
committerReedy <reedy@wikimedia.org>
Thu, 28 May 2020 19:25:57 +0000 (19:25 +0000)
The maintenance script might be run to clean up users with no ID in the
`revision` table even after the other tables have had the ID and name
fields removed (in favor of the actor ID fields). Handle this situation
so as to not error out.

Bug: T238043
Change-Id: Ie84dab4218d816106bf4b0e61f020148730220f0
(cherry picked from commit f5b78e9c313d8c54cffe61cc24fe82367b023d31)

maintenance/cleanupUsersWithNoId.php

index f7fd9d5..5232f91 100644 (file)
@@ -131,13 +131,18 @@ class CleanupUsersWithNoId extends LoggedUpdateMaintenance {
                        return;
                }
 
+               $dbw = $this->getDB( DB_MASTER );
+               if ( !$dbw->fieldExists( $table, $idField ) ||
+                       !$dbw->fieldExists( $table, $nameField )
+               ) {
+                       $this->output( "Skipping $table, fields $idField and/or $nameField do not exist\n" );
+                       return;
+               }
+
                $primaryKey = (array)$primaryKey;
                $pkFilter = array_flip( $primaryKey );
-               $this->output(
-                       "Beginning cleanup of $table\n"
-               );
+               $this->output( "Beginning cleanup of $table\n" );
 
-               $dbw = $this->getDB( DB_MASTER );
                $next = '1=1';
                $countAssigned = 0;
                $countPrefixed = 0;