Manual talk:RemoveUnusedAccounts.php

From MediaWiki.org
Jump to: navigation, search

[edit] How to avoid the deletion of recently created accounts

Replace in RemoveUnusedAccounts.php the lines below:

$res = $dbr->select( 'user', array( 'user_id', 'user_name' ), '', $fname );
while( $row = $dbr->fetchObject( $res ) ) {
        # Check the account, but ignore it if it's the primary administrator
 if( $row->user_id > 1 && isInactiveAccount( $row->user_id, true ) ) {

by these:

$res = $dbr->select( 'user', array( 'user_id', 'user_name', 'user_registration' ), '', $fname );
# Only checks accounts registered more than 10 days ago
$timestamp = date("YmdHis", time() - 86400 * 10);
echo( "\nChecking only accounts registered before: " . $timestamp . "\n" );
while( $row = $dbr->fetchObject( $res ) ) {
        # Check the account, but ignore it if it's the primary administrator
 if( $row->user_id > 1 && isInactiveAccount( $row->user_id, true ) && $row->user_registration < $timestamp ) {

In the example above, only unused accounts registered more than 10 days ago will be deleted. You may replace "10" by the number of days most convenient for you. Capmo 07:11, 11 December 2008 (UTC)

Here's an update to this patch according to the code as of today. Also moved the user_registration check to before the isInactiveAccount for performance reasons.
Original lines:
        $res = $dbr->select( 'user', array( 'user_id', 'user_name', 'user_touched' ), '', __METHOD__ );
# ..
            if ( count( array_intersect( $instance->getEffectiveGroups(), $excludedGroups ) ) == 0
                && $this->isInactiveAccount( $row->user_id, true )
                && wfTimestamp( TS_UNIX, $row->user_touched ) < wfTimestamp( TS_UNIX, time() - $touchedSeconds )
                ) {
Patched (untested):
        $res = $dbr->select( 'user', array( 'user_id', 'user_name', 'user_touched', 'user_registration' ), '', __METHOD__ );
# ..
            # Only checks accounts registered more than 10 days ago
            $ts10DaysAgo = date("YmdHis", time() - 86400 * 10);
 
            if ( count( array_intersect( $instance->getEffectiveGroups(), $excludedGroups ) ) == 0
                && $row->user_registration < $ts10DaysAgo
                && $this->isInactiveAccount( $row->user_id, true )
                && wfTimestamp( TS_UNIX, $row->user_touched ) < wfTimestamp( TS_UNIX, time() - $touchedSeconds )
                ) {
Krinkle 18:37, 27 January 2012 (UTC)
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox