Last active
December 12, 2015 10:38
-
-
Save aaronott/4760022 to your computer and use it in GitHub Desktop.
Disable all Drupal users except Admin via Drush
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env drush | |
<?php | |
# | |
# This script removes all drupal users with uid > 1 (e.g., skips | |
# admin user) and reassigns their content to anonymous. | |
# | |
// check if we can bootstrap | |
$self = drush_sitealias_get_record('@self'); | |
if (empty($self)) { | |
drush_die("I can't bootstrap from the current location.", 0); | |
} | |
// we don't want to say yes each time. | |
drush_set_context('DRUSH_AFFIRMATIVE', TRUE); | |
$result = db_query("SELECT name from {users} WHERE uid > 1"); | |
foreach ($result as $user) { | |
drush_invoke('user-block', array($user->name)); | |
} |
glopes, sorry for the delay. by now you've no doubt found your solution, but if not you can take a look at one of the other scripts I wrote here: https://gist.github.com/aaronott/6040509 and perhaps that may help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi aaronott,
i was thinking how i could make something similar, when i found this. :)
thx for that.
i tried to delete all users except uid 0 and uid 1 (uid > 1) with user-cancel. but that wasn´t working for me. using drush_invoke('user-cancel', array($user->name)); deletes the user with uid 0 and for now on drush throws this error message: "Could not login with user ID #0 ..."
any idea whats runnig wrong?