From: Rob Church Date: Mon, 16 Jan 2006 13:57:29 +0000 (+0000) Subject: Make user functions more generalised so other maintenance scripts can use them X-Git-Tag: 1.6.0~511 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/journal.php?a=commitdiff_plain;h=3236f915eb89f09e1160c10ce1a657f0e40e081a;p=lhc%2Fweb%2Fwiklou.git Make user functions more generalised so other maintenance scripts can use them --- diff --git a/maintenance/removeUnusedAccounts.inc b/maintenance/removeUnusedAccounts.inc deleted file mode 100644 index 0323304e8f..0000000000 --- a/maintenance/removeUnusedAccounts.inc +++ /dev/null @@ -1,52 +0,0 @@ - - */ - -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 ); -} - -# 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; - } - return( $users ); -} - -# 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(); -} - -?> \ No newline at end of file diff --git a/maintenance/removeUnusedAccounts.php b/maintenance/removeUnusedAccounts.php index a507de6301..09192fd33e 100644 --- a/maintenance/removeUnusedAccounts.php +++ b/maintenance/removeUnusedAccounts.php @@ -9,9 +9,11 @@ * @author Rob Church */ +define( 'ACTION_REPORT', 0 ); +define( 'ACTION_DELETE', 1 ); $options = array( 'delete','help' ); require_once( 'commandLine.inc' ); -require_once( 'removeUnusedAccounts.inc' ); +require_once( 'userFunctions.inc' ); echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" ); diff --git a/maintenance/userFunctions.inc b/maintenance/userFunctions.inc new file mode 100644 index 0000000000..8e43a6d203 --- /dev/null +++ b/maintenance/userFunctions.inc @@ -0,0 +1,49 @@ + + */ + +# 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 ); +} + +# 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; + } + return( $users ); +} + +# 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(); +} + +?> \ No newline at end of file