X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FremoveUnusedAccounts.inc;h=02c07c1f95bc2e48d40494df57ac0b06a145a0d7;hb=eecfbfb0bb2918bdbeb47c8daf0fbdb2295f0000;hp=74f5420cb9cda1b6ca9c9c63bc755f5eab9e7e98;hpb=755140c57ceca2f91a3418bee22de11a04c9755e;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/removeUnusedAccounts.inc b/maintenance/removeUnusedAccounts.inc index 74f5420cb9..02c07c1f95 100644 --- a/maintenance/removeUnusedAccounts.inc +++ b/maintenance/removeUnusedAccounts.inc @@ -1,52 +1,46 @@ */ -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 - # 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 ); - $row = $dbw->fetchObject( $res ); - return( $row->count ); -} +/** + * Could the specified user account be deemed inactive? + * (No edits, no deleted edits, no log entries, no current/old uploads) + * + * @param $id User's ID + * @param $master Perform checking on the master + * @return bool + */ +function isInactiveAccount( $id, $master = false ) { + $dbo = wfGetDB( $master ? DB_MASTER : DB_SLAVE ); + $fname = 'isInactiveAccount'; + $checks = array( 'revision' => 'rev', 'archive' => 'ar', 'logging' => 'log', + 'image' => 'img', 'oldimage' => 'oi' ); + $count = 0; -# Return an array containing all valid user IDs -function GetUsers() { - # We're safe enough pulling this off a slave - $dbr =& wfGetDB( DB_SLAVE ); - $sql = 'SELECT user_id FROM ' . $dbr->tableName( 'user' ); - $res = $dbr->query( $sql ); - $users = array(); - while( $row = $dbr->fetchObject( $res ) ) { - $users[] = $row->user_id; + $dbo->immediateBegin(); + foreach( $checks as $table => $fprefix ) { + $conds = array( $fprefix . '_user' => $id ); + $count += (int)$dbo->selectField( $table, 'COUNT(*)', $conds, $fname ); } - return( $users ); -} + $dbo->immediateCommit(); -# Delete one or more users -function DeleteUsers( $users ) { - # Need a master, obviously - $dbw =& wfGetDB( DB_MASTER ); - # We'll do it all in one go, for speed - $dbw->begin(); - $table = $dbw->tableName( 'user' ); - foreach( $users as $user ) { - $dbw->query( 'DELETE FROM ' . $table . ' WHERE user_id = ' . $user . ' LIMIT 1' ); - } - $dbw->commit(); + return $count == 0; } -?> \ No newline at end of file +/** + * Show help for the maintenance script + */ +function showHelp() { + echo( "Delete unused user accounts from the database.\n\n" ); + echo( "USAGE: php removeUnusedAccounts.php [--delete]\n\n" ); + echo( " --delete : Delete accounts which are discovered to be inactive\n" ); + echo( " --ignore-touched=x : Ignore accounts touched within the lasts x days\n" ); + echo( " --ignore-groups=x,y : Ignore accounts within these groups\n" ); + echo( "\n" ); +}