4 * Remove unused user accounts from the database
5 * An unused account is one which has made no edits
8 * @subpackage Maintenance
9 * @author Rob Church <robchur@gmail.com>
13 * @todo Don't delete sysops or bureaucrats
16 $options = array( 'help', 'delete' );
17 require_once( 'commandLine.inc' );
18 require_once( 'removeUnusedAccounts.inc' );
19 echo( "Remove Unused Accounts\n\n" );
20 $fname = 'removeUnusedAccounts';
22 if( isset( $options['help'] ) ) {
27 # Do an initial scan for inactive accounts and report the result
28 echo( "Checking for unused user accounts...\n" );
30 $dbr =& wfGetDB( DB_SLAVE
);
31 $res = $dbr->select( 'user', array( 'user_id', 'user_name' ), '', $fname );
32 while( $row = $dbr->fetchObject( $res ) ) {
33 # Check the account, but ignore it if it's the primary administrator
34 if( $row->user_id
> 1 && isInactiveAccount( $row->user_id
, true ) ) {
35 # Inactive; print out the name and flag it
36 $del[] = $row->user_id
;
37 echo( $row->user_name
. "\n" );
40 $count = count( $del );
41 echo( "...found {$count}.\n" );
43 # If required, go back and delete each marked account
44 if( $count > 0 && isset( $options['delete'] ) ) {
45 echo( "\nDeleting inactive accounts..." );
46 $dbw =& wfGetDB( DB_MASTER
);
47 #$set = implode( ',', $del );
48 $dbw->delete( 'user', array( 'user_id' => $del ), $fname );
52 echo( "\nRun the script again with --delete to remove them from the database.\n" );