If, like me, you prefer a Python approach (rare around here probably, but still), this is a transparent and effective way to fix this problem:
# Build up a variable containing the usernames
# This list was built using drush sql-cli, then
# SELECT name FROM users
# where $your-where-condition
# order by uid asc
# OUTFILE '/tmp/users.csv'
# FIELDS TERMINATED BY ','
# ENCLOSED BY '"'
# lines terminated by ', ' ;
users = [result from SQL goes here]
for user in users:
print("Deleting spam user: %s..." % user),
os.system('drush --yes -r $your-path-to-drupal -l $your-site-url user-cancel --delete-content %s > /dev/null' % user)
The steps are basically:
- Log into your DB with
drush sql-cli -r $your-path-to-drupal -l $your-site-url
- Run the SQL above with your own where condition and paste the results into the users variable.
- Update your drupal path and site name into the drush command
- Run the script with
I'm sure there's a better way to do this, but this is my hacked solution that works well.