From ed30476e706c1f6912124de1d7cc75e1288c97a1 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Tue, 4 Apr 2006 02:50:58 +0000 Subject: [PATCH] Check that accounts have no uploads prior to calling them unused --- maintenance/removeUnusedAccounts.php | 6 +++--- maintenance/userFunctions.inc | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/maintenance/removeUnusedAccounts.php b/maintenance/removeUnusedAccounts.php index 1c6213c4ed..2c967b1d51 100644 --- a/maintenance/removeUnusedAccounts.php +++ b/maintenance/removeUnusedAccounts.php @@ -15,7 +15,7 @@ $options = array( 'delete','help' ); require_once( 'commandLine.inc' ); require_once( 'userFunctions.inc' ); -echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" ); +echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits and uploaded no files.\n\n" ); # Check parameters if( @$options['help'] ) { @@ -34,8 +34,8 @@ 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 - if( CountEdits( $user, false ) == 0 ) { - # User has no edits, mark them for deletion + if( CountEdits( $user, false ) == 0 && CountImages( $user, false ) == 0 ) { + # User has no edits or images, mark them for deletion $del[] = $user; $count++; } diff --git a/maintenance/userFunctions.inc b/maintenance/userFunctions.inc index 42429e86f2..314da61ed1 100644 --- a/maintenance/userFunctions.inc +++ b/maintenance/userFunctions.inc @@ -29,6 +29,27 @@ function CountEdits( $user, $slave = true ) { return( $count ); } +/** + * Count the number of images the specified user has uploaded + * + * @param integer $user User ID + * @param bool $slave Whether or not a slave can be used + * @return integer + */ +function CountImages( $user, $slave = true ) { + $dbw =& wfGetDB( $slave ? DB_SLAVE: DB_MASTER ); + # Count current images + $res = $dbw->select( 'image', 'COUNT(rev_id) AS count', array( 'img_user' => $user ) ); + $row = $dbw->fetchObject( $res ); + $count = $row->count; + # Count deleted edits + $res = $dbw->select( 'oldimage', 'COUNT(*) AS count', array( 'oi_user' => $user ) ); + $row = $dbw->fetchObject( $res ); + $count += $row->count; + # Done + return( $count ); +} + /** * Retrieve all valid user IDs * -- 2.20.1