From 755140c57ceca2f91a3418bee22de11a04c9755e Mon Sep 17 00:00:00 2001 From: Rob Church Date: Thu, 5 Jan 2006 23:52:18 +0000 Subject: [PATCH] * Cleanup main code * Correct a couple of major oversights in the commenting (no, they aren't arrays of User objects, that would be mad, and to what avail?) --- maintenance/removeUnusedAccounts.inc | 26 +++++------------ maintenance/removeUnusedAccounts.php | 43 +++++++++++----------------- 2 files changed, 23 insertions(+), 46 deletions(-) diff --git a/maintenance/removeUnusedAccounts.inc b/maintenance/removeUnusedAccounts.inc index 376b6c9f81..74f5420cb9 100644 --- a/maintenance/removeUnusedAccounts.inc +++ b/maintenance/removeUnusedAccounts.inc @@ -11,16 +11,11 @@ define( 'ACTION_REPORT', 0 ); define( 'ACTION_DELETE', 1 ); -/** - * Count the number of edits the specified user has made - * @param $user_id A database user id. - * @return integer Number of edits made by the given user. - */ +# 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 been replicated to the slaves yet, we'll end up - # falsely marking them as inactive. This could (and usually would) lead - # to their deletion. + # We've *got* to pull this stuff off the master. If the user *has* made an edit, but it hasn't + # been replicated to the slaves yet, we'll end up falsely marking them as inactive. This could + # (and usually would) lead to their deletion. $dbw =& wfGetDB( DB_MASTER ); $sql = 'SELECT COUNT(rev_id) AS count FROM ' . $dbw->tableName( 'revision' ) . ' WHERE rev_user = ' . $user_id; $res = $dbw->query( $sql ); @@ -28,10 +23,7 @@ function CountEdits( $user_id ) { return( $row->count ); } -/** - * Return an array containing all valid user IDs - * @return array Array of User:: object(s). - */ +# Return an array containing all valid user IDs function GetUsers() { # We're safe enough pulling this off a slave $dbr =& wfGetDB( DB_SLAVE ); @@ -44,11 +36,7 @@ function GetUsers() { return( $users ); } -/** - * Delete one or more users. - * You will probably use GetUsers() first to get a list of users :o) - * @param array An array of User:: object(s) - */ +# Delete one or more users function DeleteUsers( $users ) { # Need a master, obviously $dbw =& wfGetDB( DB_MASTER ); @@ -61,4 +49,4 @@ function DeleteUsers( $users ) { $dbw->commit(); } -?> +?> \ No newline at end of file diff --git a/maintenance/removeUnusedAccounts.php b/maintenance/removeUnusedAccounts.php index a3a893835b..6809f2a7f0 100644 --- a/maintenance/removeUnusedAccounts.php +++ b/maintenance/removeUnusedAccounts.php @@ -9,32 +9,18 @@ * @author Rob Church */ -# Options available $options = array( 'delete','help' ); - require_once( 'commandLine.inc' ); require_once( 'removeUnusedAccounts.inc' ); -# Default action (just report): -$action = ACTION_REPORT; +echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" ); -# Handle parameters -if(@$options['help']) { -echo << 0 ) ) { - echo( " Deleting..." ); - DeleteUsers( $del ); - echo( "done.\n" ); -} else { - echo "\nYou can delete them by using the '--delete' switch (see help).\n"; +if( $count > 0 ) { + if( ( $delete ) || ( $count > 0 ) ) { + echo( " Deleting..." ); + DeleteUsers( $del ); + echo( "done.\n" ); + } else { + echo "Run the script with the --delete option to remove them from the database.\n"; + } } +echo( "\n" ); ?> -- 2.20.1