2

I'm trying to block all users except ones with a specific role, and would love to use something like: drush user:block !roadie.

2

1 Answer 1

3

I suggest use drush block

drush ublk $(drush sqlq 'SELECT GROUP_CONCAT(ufd.name) FROM users u join user__roles ur on  u.uid = ur.entity_id  join users_field_data ufd on ufd.uid = u.uid where ur.roles_target_id ="YOUR_ROLE_MACHINENAME" and ufd.name like "%PATTERN%"')

before that make sure the query is correct and it respond what you want by

drush sqlq 'SELECT GROUP_CONCAT(ufd.name) FROM users u join user__roles ur on  u.uid = ur.entity_id  join users_field_data ufd on ufd.uid = u.uid where ur.roles_target_id ="YOUR_ROLE_MACHINENAME" and ufd.name like "%PATTERN%"

and finally, make sure they are blocked by checking "User status" column of the result of the following command

drush uinf $(drush sqlq 'SELECT GROUP_CONCAT(ufd.name) FROM users u join user__roles ur on  u.uid = ur.entity_id  join users_field_data ufd on ufd.uid = u.uid where ur.roles_target_id ="YOUR_ROLE_MACHINENAME" and ufd.name like "%PATTERN%"')

PS:

  • YOUR_ROLE_MACHINENAME: change it with your desired role.
  • PATTERN: you can use MySQL LIKE statement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.