1. 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?

Discussion in 'XenForo Questions and Support' started by Stuart Wright, Jan 28, 2016.

  1. Stuart Wright

    Stuart Wright Well-Known Member

    I have a spreadsheet of 350 user_ids I need to ban.
    Is there a quick way to do this please?
  2. Brogan

    Brogan XenForo Moderator Staff Member

    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.
  3. Stuart Wright

    Stuart Wright Well-Known Member

    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.
  4. RobParker

    RobParker Well-Known Member

    Can an SQL query not do it? Or is banning more complicated than setting a variable in the database?
  5. whynot

    whynot Well-Known Member

    Batch update > Email=xpost.asd.ru > Registered between = 19 Jan-28 Jan > Search > Ban users (permanently)
  6. Stuart Wright

    Stuart Wright Well-Known Member

    The 350 emails are different.

    Actually I need to run the spam decimator on them all.
  7. whynot

    whynot Well-Known Member

    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.
  8. James

    James Well-Known Member

    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.
  9. Joeychgo

    Joeychgo Well-Known Member

    use phpmyadmin and sort the fields so that those 350 all come up in a row ---easy to delete then
  10. James

    James Well-Known Member

    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.
  11. Stuart Wright

    Stuart Wright Well-Known Member

    Daniel is on the case.
    James likes this.
  12. Xon

    Xon Well-Known Member

    @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.

    $startTime = microtime(true);
    $fileDir = dirname(__FILE__) . '/html';
    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();
    $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
    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)
                    print $errorKey. "\n";
    $time = microtime(true) - $startTime;
    echo "\nNuked $count in $time secounds\n";
  13. Stuart Wright

    Stuart Wright Well-Known Member

    Thank you.
    Quick question. Are lines 19 and 20 supposed to be identical?
    $user_ids = $db->fetchAll("
    $user_ids = $db->fetchAll("
  14. Daniel Hood

    Daniel Hood Well-Known Member

    No, erase one of them. I'm assuming he meant to use the shortcut key for "undo" and hit the one that duplicates the line without noticing.
    Xon and Stuart Wright like this.
  15. Stuart Wright

    Stuart Wright Well-Known Member

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

    Nuked 243 in 63.214022874832 seconds.
    Many thanks, @Xon.
    Daniel Hood likes this.
  16. Xon

    Xon Well-Known Member

    Sorry, a copy & paste error.

    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.

Share This Page