X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=blobdiff_plain;f=maintenance%2FremoveUnusedAccounts.php;h=ca90468c18051a8878be1cd8bf3d96935d4c6afe;hb=e22efbce178309cb4dd537633b634bfc9e17d571;hp=e066300c58ba203706068405a18bc1fd30182713;hpb=967a96e7fa5910f8fc451590decb381dbfb481ba;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/removeUnusedAccounts.php b/maintenance/removeUnusedAccounts.php index e066300c58..ca90468c18 100644 --- a/maintenance/removeUnusedAccounts.php +++ b/maintenance/removeUnusedAccounts.php @@ -39,8 +39,6 @@ class RemoveUnusedAccounts extends Maintenance { } public function execute() { - global $wgActorTableSchemaMigrationStage; - $this->output( "Remove unused accounts\n\n" ); # Do an initial scan for inactive accounts and report the result @@ -48,18 +46,14 @@ class RemoveUnusedAccounts extends Maintenance { $delUser = []; $delActor = []; $dbr = $this->getDB( DB_REPLICA ); - if ( $wgActorTableSchemaMigrationStage > MIGRATION_OLD ) { - $res = $dbr->select( - [ 'user', 'actor' ], - [ 'user_id', 'user_name', 'user_touched', 'actor_id' ], - '', - __METHOD__, - [], - [ 'actor' => [ 'LEFT JOIN', 'user_id = actor_user' ] ] - ); - } else { - $res = $dbr->select( 'user', [ 'user_id', 'user_name', 'user_touched' ], '', __METHOD__ ); - } + $res = $dbr->select( + [ 'user', 'actor' ], + [ 'user_id', 'user_name', 'user_touched', 'actor_id' ], + '', + __METHOD__, + [], + [ 'actor' => [ 'LEFT JOIN', 'user_id = actor_user' ] ] + ); if ( $this->hasOption( 'ignore-groups' ) ) { $excludedGroups = explode( ',', $this->getOption( 'ignore-groups' ) ); } else { @@ -75,12 +69,12 @@ class RemoveUnusedAccounts extends Maintenance { # group or if it's touched within the $touchedSeconds seconds. $instance = User::newFromId( $row->user_id ); if ( count( array_intersect( $instance->getEffectiveGroups(), $excludedGroups ) ) == 0 - && $this->isInactiveAccount( $row->user_id, $row->actor_id, true ) + && $this->isInactiveAccount( $row->user_id, $row->actor_id ?? null, true ) && wfTimestamp( TS_UNIX, $row->user_touched ) < wfTimestamp( TS_UNIX, time() - $touchedSeconds ) ) { # Inactive; print out the name and flag it $delUser[] = $row->user_id; - if ( $row->actor_id ) { + if ( isset( $row->actor_id ) && $row->actor_id ) { $delActor[] = $row->actor_id; } $this->output( $row->user_name . "\n" ); @@ -94,30 +88,22 @@ class RemoveUnusedAccounts extends Maintenance { $this->output( "\nDeleting unused accounts..." ); $dbw = $this->getDB( DB_MASTER ); $dbw->delete( 'user', [ 'user_id' => $delUser ], __METHOD__ ); - if ( $wgActorTableSchemaMigrationStage > MIGRATION_OLD ) { - # Keep actor rows referenced from ipblocks - $keep = $dbw->selectFieldValues( - 'ipblocks', 'ipb_by_actor', [ 'ipb_by_actor' => $delActor ], __METHOD__ - ); - $del = array_diff( $delActor, $keep ); - if ( $del ) { - $dbw->delete( 'actor', [ 'actor_id' => $del ], __METHOD__ ); - } - if ( $keep ) { - $dbw->update( 'actor', [ 'actor_user' => 0 ], [ 'actor_id' => $keep ], __METHOD__ ); - } + # Keep actor rows referenced from ipblocks + $keep = $dbw->selectFieldValues( + 'ipblocks', 'ipb_by_actor', [ 'ipb_by_actor' => $delActor ], __METHOD__ + ); + $del = array_diff( $delActor, $keep ); + if ( $del ) { + $dbw->delete( 'actor', [ 'actor_id' => $del ], __METHOD__ ); + } + if ( $keep ) { + $dbw->update( 'actor', [ 'actor_user' => 0 ], [ 'actor_id' => $keep ], __METHOD__ ); } $dbw->delete( 'user_groups', [ 'ug_user' => $delUser ], __METHOD__ ); $dbw->delete( 'user_former_groups', [ 'ufg_user' => $delUser ], __METHOD__ ); $dbw->delete( 'user_properties', [ 'up_user' => $delUser ], __METHOD__ ); - if ( $wgActorTableSchemaMigrationStage > MIGRATION_OLD ) { - $dbw->delete( 'logging', [ 'log_actor' => $delActor ], __METHOD__ ); - $dbw->delete( 'recentchanges', [ 'rc_actor' => $delActor ], __METHOD__ ); - } - if ( $wgActorTableSchemaMigrationStage < MIGRATION_NEW ) { - $dbw->delete( 'logging', [ 'log_user' => $delUser ], __METHOD__ ); - $dbw->delete( 'recentchanges', [ 'rc_user' => $delUser ], __METHOD__ ); - } + $dbw->delete( 'logging', [ 'log_actor' => $delActor ], __METHOD__ ); + $dbw->delete( 'recentchanges', [ 'rc_actor' => $delActor ], __METHOD__ ); $this->output( "done.\n" ); # Update the site_stats.ss_users field $users = $dbw->selectField( 'user', 'COUNT(*)', [], __METHOD__ ); @@ -138,7 +124,7 @@ class RemoveUnusedAccounts extends Maintenance { * (No edits, no deleted edits, no log entries, no current/old uploads) * * @param int $id User's ID - * @param int $actor User's actor ID + * @param int|null $actor User's actor ID * @param bool $master Perform checking on the master * @return bool */