• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.5 How do I easily ban 350 accounts that I have the user_id for?

Brogan

XenForo moderator
Staff member
#2
Unless there is some common criteria which will enable you to use the Batch Updater Users function, you will have to do them one at a time.
 

Stuart Wright

Well-known member
#3
Unless there is some common criteria which will enable you to use the Batch Updater Users function, you will have to do them one at a time.
There are common attributes of their accounts. They all set their timezone as Asia/Bangkok and they all registered since 19th Jan and they all use emails with top level domains of @topmail or @xmail or @postx or @xmailer or @mailx or @mailer or @bestmail or @mailerx or @postmail or @xpost plus two dots (e.g. @xpost.asd.ru)
Most have uploaded avatars.
None of this helps, though. I need a process to ban them based on their user_ids.
 

whynot

Well-known member
#5
and they all registered since 19th Jan and they all use emails with top level domains of @topmail or @xmail or @postx or @xmailer or @mailx or @mailer or @bestmail or @mailerx or @postmail or @xpost plus two dots (e.g. @xpost.asd.ru)
Batch update > Email=xpost.asd.ru > Registered between = 19 Jan-28 Jan > Search > Ban users (permanently)
 

whynot

Well-known member
#7
I believe that you should ban them one by one as Brogan suggested.
But banning hundreds, thousands of them is worthless.
Most probably they are going to use a different name, email address, etc. to register again.
 

James

Well-known member
#8
I'm wondering if anyone could rustle up an addon that could recursively loop through the ids and ban them. Have you considered posting in addon requests?

Edit: or it could be added to @ThemeHouse Ban essentials.. Or @Daniel Hood Moderator Essentials.
 

James

Well-known member
#10
use phpmyadmin and sort the fields so that those 350 all come up in a row ---easy to delete then
He wants to ban them not delete & deleting direct from the db without knowledge of exactly what to delete can cause caching and orphan record issues.
 

Xon

Well-known member
#12
@Stuart Wright I used the following php script to clean up ~200000 spam accounts stuck in waiting from approval for ~5 years.

It will require some SQL experience to modify it, and needs to be run from the commandline to avoid timeouts.

Code:
<?php
return;
$startTime = microtime(true);
$fileDir = dirname(__FILE__) . '/html';

@set_time_limit(120);
ignore_user_abort(true);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$dependencies = new XenForo_Dependencies_Public();
$dependencies->preLoadData();

$db = XenForo_Application::get('db');
$user_ids = $db->fetchAll("
$user_ids = $db->fetchAll("
select user.*
from xf_user user
join xf_user_profile on user.user_id = xf_user_profile.user_id
where
user.is_banned = 0 and user.message_count = 0 and user.like_count = 0 and profile.signature = ''
and profile.occupation = ''
and user.user_state = 'email_confirm'
and user.register_date < unix_timestamp('2014-01-01')
and user.register_date > unix_timestamp('2011-01-01')
and user.last_activity < unix_timestamp('2015-01-01')
");

$spamCleanerModel = XenForo_model::create('XenForo_Model_SpamCleaner');

$options = array(
  'action_threads'  => 1,
  'delete_messages' => 1,
  'delete_conversations' => 1,
  'ban_user'        => 1,
  'check_ips'       => XenForo_Input::UINT,
  'email_user'      => 0,
  'email'           => '',
);


$visitor =  XenForo_Visitor::setup(1);
print "Profile doing the nuking: ".$visitor['user_id'].'-'.$visitor['username']."\n";
print "Nuking ".count($user_ids )." spam accounts\n";
$count = 0;
foreach($user_ids as $user )
{
        print $user['user_id'].'-'.$user['username']."\n";

        $log = array();
        $errorKey = '';
        $log = $spamCleanerModel->cleanUp($user, $options, $log, $errorKey);

        if ($log)
        {
                $count++;
        }
        else
        {
                print $errorKey. "\n";
                break;
        }
}

$time = microtime(true) - $startTime;

echo "\nNuked $count in $time secounds\n";
 

Stuart Wright

Well-known member
#13
@Stuart Wright I used the following php script to clean up ~200000 spam accounts stuck in waiting from approval for ~5 years.

It will require some SQL experience to modify it, and needs to be run from the commandline to avoid timeouts.

Code:
<?php
return;
$startTime = microtime(true);
$fileDir = dirname(__FILE__) . '/html';

@set_time_limit(120);
ignore_user_abort(true);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$dependencies = new XenForo_Dependencies_Public();
$dependencies->preLoadData();

$db = XenForo_Application::get('db');
$user_ids = $db->fetchAll("
$user_ids = $db->fetchAll("
select user.*
from xf_user user
join xf_user_profile on user.user_id = xf_user_profile.user_id
where
user.is_banned = 0 and user.message_count = 0 and user.like_count = 0 and profile.signature = ''
and profile.occupation = ''
and user.user_state = 'email_confirm'
and user.register_date < unix_timestamp('2014-01-01')
and user.register_date > unix_timestamp('2011-01-01')
and user.last_activity < unix_timestamp('2015-01-01')
");

$spamCleanerModel = XenForo_model::create('XenForo_Model_SpamCleaner');

$options = array(
  'action_threads'  => 1,
  'delete_messages' => 1,
  'delete_conversations' => 1,
  'ban_user'        => 1,
  'check_ips'       => XenForo_Input::UINT,
  'email_user'      => 0,
  'email'           => '',
);


$visitor =  XenForo_Visitor::setup(1);
print "Profile doing the nuking: ".$visitor['user_id'].'-'.$visitor['username']."\n";
print "Nuking ".count($user_ids )." spam accounts\n";
$count = 0;
foreach($user_ids as $user )
{
        print $user['user_id'].'-'.$user['username']."\n";

        $log = array();
        $errorKey = '';
        $log = $spamCleanerModel->cleanUp($user, $options, $log, $errorKey);

        if ($log)
        {
                $count++;
        }
        else
        {
                print $errorKey. "\n";
                break;
        }
}

$time = microtime(true) - $startTime;

echo "\nNuked $count in $time secounds\n";
Thank you.
Quick question. Are lines 19 and 20 supposed to be identical?
Code:
$user_ids = $db->fetchAll("
$user_ids = $db->fetchAll("
 

Xon

Well-known member
#16
Thank you.
Quick question. Are lines 19 and 20 supposed to be identical?
Code:
$user_ids = $db->fetchAll("
$user_ids = $db->fetchAll("
Sorry, a copy & paste error.

Also removed the initial 'return;' on line 2.

Nuked 243 in 63.214022874832 seconds.
Many thanks, @Xon.
Not a problem. You may need to tune to selection criteria a bit.

The return statement was to ensure the script couldn't be run by mistake, especially as I had a variant which deleted the zero-content spam account.