Fix yet another stupid mistake
[mediawiki.git] / maintenance / removeUnusedAccounts.inc
blob0323304e8f2c14416a8651846f5a10ea2f465d94
1 <?php
3 /**
4  * Support functions for the removeUnusedAccounts script
5  *
6  * @package MediaWiki
7  * @subpackage Maintenance
8  * @author Rob Church <robchur@gmail.com>
9  */
11 define( 'ACTION_REPORT', 0 );
12 define( 'ACTION_DELETE', 1 );
14 # Count the number of edits the specified user has made
15 function CountEdits( $user_id ) {
16         # We've *got* to pull this stuff off the master. If the user *has* made an edit, but it hasn't
17         # been replicated to the slaves yet, we'll end up falsely marking them as inactive. This could
18         # (and usually would) lead to their deletion.
19         $dbw =& wfGetDB( DB_MASTER );
20         $sql = 'SELECT COUNT(rev_id) AS count FROM ' . $dbw->tableName( 'revision' ) . ' WHERE rev_user = ' . $user_id;
21         $res = $dbw->query( $sql );
22         $row = $dbw->fetchObject( $res );
23         return( $row->count );
26 # Return an array containing all valid user IDs
27 function GetUsers() {
28         # We're safe enough pulling this off a slave
29         $dbr =& wfGetDB( DB_SLAVE );
30         $sql = 'SELECT user_id FROM ' . $dbr->tableName( 'user' );
31         $res = $dbr->query( $sql );
32         $users = array();
33         while( $row = $dbr->fetchObject( $res ) ) {
34                 $users[] = $row->user_id;
35         }
36         return( $users );
39 # Delete one or more users
40 function DeleteUsers( $users ) {
41         # Need a master, obviously
42         $dbw =& wfGetDB( DB_MASTER );
43         # We'll do it all in one go, for speed
44         $dbw->begin();
45         $table = $dbw->tableName( 'user' );
46         foreach( $users as $user ) {
47                 $dbw->query( 'DELETE FROM ' . $table . ' WHERE user_id = ' . $user . ' LIMIT 1' );
48         }
49         $dbw->commit();