Tweak script to allow just reporting of the number of inactive accounts
authorRob Church <robchurch@users.mediawiki.org>
Wed, 4 Jan 2006 13:02:04 +0000 (13:02 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Wed, 4 Jan 2006 13:02:04 +0000 (13:02 +0000)
maintenance/removeUnusedAccounts.inc
maintenance/removeUnusedAccounts.php

index ac3b5c4..74f5420 100644 (file)
@@ -8,6 +8,9 @@
  * @author Rob Church <robchur@gmail.com>
  */
 
+define( 'ACTION_REPORT', 0 );
+define( 'ACTION_DELETE', 1 );
+
 # Count the number of edits the specified user has made 
 function CountEdits( $user_id ) {
        # We've *got* to pull this stuff off the master. If the user *has* made an edit, but it hasn't
index dd9214f..038875f 100644 (file)
 require_once( 'commandLine.inc' );
 require_once( 'removeUnusedAccounts.inc' );
 echo( "REMOVE UNUSED ACCOUNTS\nThis script will delete all users who have made no edits.\n\n" );
+echo( "Syntax: removeUnusedAccounts.php [delete]\n     * delete -> delete the accounts\n       * The first user (usually the site owner) is left alone\n\n" );
+
+# Handle parameters
+if( isset( $args[0] ) ) {
+       $param = array_shift( $args );
+       if( $param == 'delete' ) {
+               $action = ACTION_DELETE;
+       } else {
+               $action = ACTION_REPORT;
+       }
+} else {
+       $action = ACTION_REPORT;
+}
 
 $count = 0;
 $del = array();
 
 # Right, who needs deleting?
 $users = GetUsers();
-echo( "Found " . count( $users ) . " accounts.\n" );
+echo( "Found " . count( $users ) . " accounts.\n\n" );
 echo( "Locating inactive users..." );
 foreach( $users as $user ) {
        if( $user != 1 ) {      # Don't *touch* the first user account, ever
@@ -32,11 +45,11 @@ foreach( $users as $user ) {
 echo( "done.\n" );
 
 # Purge the inactive accounts we found
-echo( $count . " inactive accounts found. Deleting..." );
-DeleteUsers( $del );
-echo( "done.\n" );
-
-# We're done
-echo( "Complete.\n" );
+echo( $count . " inactive accounts found." );
+if( ( $action == ACTION_DELETE ) && ( $count > 0 ) ) {
+       echo( " Deleting..." );
+       DeleteUsers( $del );
+       echo( "done.\n" );
+}
 
 ?>
\ No newline at end of file