From 3f443c7e259cae6767ff124c3a96094fcbe622a5 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Sat, 26 Jul 2008 23:42:29 +0000 Subject: [PATCH] Ignore sysops+bcrats and accounts touched in the last week. Patch by Louperivois. --- maintenance/removeUnusedAccounts.inc | 2 ++ maintenance/removeUnusedAccounts.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/maintenance/removeUnusedAccounts.inc b/maintenance/removeUnusedAccounts.inc index 8f90027259..a21dcc7a6e 100644 --- a/maintenance/removeUnusedAccounts.inc +++ b/maintenance/removeUnusedAccounts.inc @@ -38,6 +38,8 @@ function isInactiveAccount( $id, $master = false ) { */ function showHelp() { echo( "Delete unused user accounts from the database.\n\n" ); + echo( "Accounts touched within the last week will be ignored.\n\n" ); + echo( "Sysops and bureaucrats will be ignored.\n\n" ); echo( "USAGE: php removeUnusedAccounts.php [--delete]\n\n" ); echo( " --delete : Delete accounts which are discovered to be inactive\n" ); echo( "\n" ); diff --git a/maintenance/removeUnusedAccounts.php b/maintenance/removeUnusedAccounts.php index 636832cbd3..324f3c7b42 100644 --- a/maintenance/removeUnusedAccounts.php +++ b/maintenance/removeUnusedAccounts.php @@ -8,9 +8,6 @@ * @author Rob Church */ -/** - * @todo Don't delete sysops or bureaucrats - */ $options = array( 'help', 'delete' ); require_once( 'commandLine.inc' ); @@ -27,10 +24,15 @@ if( isset( $options['help'] ) ) { echo( "Checking for unused user accounts...\n" ); $del = array(); $dbr = wfGetDB( DB_SLAVE ); -$res = $dbr->select( 'user', array( 'user_id', 'user_name' ), '', $fname ); +$res = $dbr->select( 'user', array( 'user_id', 'user_name', 'user_touched' ), '', $fname ); +$excludedGroups = array( 'sysop', 'bureaucrat' ); while( $row = $dbr->fetchObject( $res ) ) { - # Check the account, but ignore it if it's the primary administrator - if( $row->user_id > 1 && isInactiveAccount( $row->user_id, true ) ) { + # Check the account, but ignore it if it's within the "sysop" or "bureaucrat" group. + $instance = User::newFromId( $row->user_id ); + if( count( array_intersect( $instance->getGroups(), $excludedGroups ) ) == 0 + && isInactiveAccount( $row->user_id, true ) + && wfTimestamp( TS_UNIX, $row->user_touched ) < wfTimestamp( TS_UNIX, time() - 604800 ) + ) { # Inactive; print out the name and flag it $del[] = $row->user_id; echo( $row->user_name . "\n" ); @@ -53,5 +55,3 @@ if( $count > 0 && isset( $options['delete'] ) ) { echo( "\nRun the script again with --delete to remove them from the database.\n" ); } echo( "\n" ); - - -- 2.20.1